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

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