Centos 7 雙網卡綁定,主備工作狀態

介紹:

系統版本:
[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)

網卡eth0初始配置:
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.14.211
PREFIX=24
GATEWAY=192.168.14.254
DNS1=10.1.2.30
DNS2=114.114.114.114

網卡eth1初始配置:
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=static
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=192.168.14.215
PREFIX=24
GATEWAY=192.168.14.254
DNS1=10.1.2.30
DNS2=114.114.114.114

一、配置雙網卡主備

1、關閉 NetworkManager服務

[root@localhost ~]# systemctl stop  NetworkManager
[root@localhost ~]# systemctl disable  NetworkManager

2、添加bond0

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-bond0 
TYPE=Bond
DEVICE=bond0
IPADDR=192.168.14.220
PREFIX=24
BONDING_OPTS=mode=active-backup
NAME=bond0
ONBOOT=yes

3、修改eth0

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.14.211
PREFIX=24
GATEWAY=192.168.14.254
DNS1=10.1.2.30
DNS2=114.114.114.114
MASTER=bond0                #新增
SLAVE=yes                   #新增

4、修改eth1

[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=static
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=192.168.14.215
PREFIX=24
GATEWAY=192.168.14.254
DNS1=10.1.2.30
DNS2=114.114.114.114
MASTER=bond0                #新增
SLAVE=yes                   #新增

5、重啓網卡

[root@localhost ~]# systemctl restart network

6、查看狀態

[root@localhost ~]# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 0
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:08:01:5d
Slave queue ID: 0

Slave Interface: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:08:01:67
Slave queue ID: 0

7、添加臨時默認路由(永久路由自行添加配置文件)

[root@localhost ~]# route add -net 0.0.0.0/0 gw 192.168.14.254 dev bond0

二、模擬生產環境網卡故障

1、關閉eth0主網卡模擬故障,eth1從備轉爲主

[root@localhost ~]# ifdown eth0

2、故障網卡eth0恢復之後並不會搶佔eth1,從而避免網絡波動

[root@localhost ~]# ifup eth0

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章