删除eth0上面的ip地址,将br0上面添加上固定ip地址
[root@master ~]# ip addr del dev eth0 192.168.3.176/24 //删除eth0上的IP地址
[root@master ~]# ifconfig br0 192.168.3.176/24 up //配置br0的IP地址并启动设备
[root@master ~]# route add default gw 192.168.3.1 //重新加入默认网关
查看配置是否生效
[root@master ~]# route //查看默认网关
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.3.0 * 255.255.255.0 U 0 0 0 br0
default 192.168.3.1 0.0.0.0 UG 0 0 0 br0
[root@master ~]# ip addr show //查看eth0跟br0的IP信息
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:a7:b7:56 brd ff:ff:ff:ff:ff:ff
inet6 fe80::5054:ff:fea7:b756/64 scope link
valid_lft forever preferred_lft forever
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/ether 52:54:00:a7:b7:56 brd ff:ff:ff:ff:ff:ff
inet 192.168.3.176/24 brd 192.168.3.255 scope global br0
inet6 fe80::5054:ff:fea7:b756/64 scope link
valid_lft forever preferred_lft forever
[root@master ~]# ping 192.168.3.1 -w2 //测试同一网段连接是否成功,判断网卡IP是否绑定正确
PING 192.168.3.1 (192.168.3.1) 56(84) bytes of data.
64 bytes from 192.168.3.1: icmp_seq=1 ttl=255 time=3.45 ms
64 bytes from 192.168.3.1: icmp_seq=2 ttl=255 time=4.20 ms
--- 192.168.3.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 3.457/3.832/4.208/0.380 ms
[root@master ~]# ping 192.168.1.1 -w2 //测试不同网段连接是否成功,判断网关是否添加成功
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=255 time=2.38 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=255 time=7.64 ms
--- 192.168.1.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 2.381/5.011/7.642/2.631 ms
上面是通过命令进行的手动配置方法,但是大家都清楚,这些命令配置的结果在服务器重启之后就不能生效了,要想使得所有配置永久生效,我们还是需要通过配置文件进行配置,然后重启网卡设备,让系统帮我们配置,然后重启之后也是生效的。
通过上面的手动配置方法,大家可以清楚得看到一个桥接设备的配置流程,这个在你写到配置文件里面,然后让系统帮你配置的时候是看不到的 :) ,那么下面我们将所有的配置还原,通过配置文件进行相关自动化配置吧。