CentOS 7 bonding模式双网卡绑定

时间:2022-06-11 14:43:55

1.1    查看系统内核是否支持bonding

[root@cobbler-node1 ~]# cat /boot/config-3.10.0-693.el7.x86_64 | grep -i bonding
CONFIG_BONDING=m

1.2    备份系统自带的网卡配置文件,以及创建bond0网卡配置文件

[root@cobbler-node1 ~]# cd /etc/sysconfig/network-scripts
[root@cobbler-node1 network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@cobbler-node1 network-scripts]# cp -a ifcfg-eth0 ifcfg-eth0.bak
[root@cobbler-node1 network-scripts]# cp -a ifcfg-eth1 ifcfg-eth1.bak
[root@cobbler-node1 network-scripts]# cp -a ifcfg-eth0.bak ifcfg-bond0

1.3修改系统eth0、eth1、bond0网卡配置文件

[root@cobbler-node1 network-scripts]# vi ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=none
DEVICE=eth0
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
[root@cobbler-node1 network-scripts]# vi ifcfg-eth1
TYPE=Ethernet
BOOTPROTO=none
DEVICE=eth1
ONBOOT=yes
USERCTL=no
MASTER=bond0
SLAVE=yes
[root@cobbler-node1 network-scripts]# vi ifcfg-bond0
TYPE=Bond
BOOTPROTO=none
DEVICE=bond0
ONBOOT=yes
IPADDR=10.129.49.240
NETMASK=255.255.255.0
GATEWAY=10.129.49.1
DNS1=10.112.15.30
DNS2=10.112.15.33
USERCTL=no

1.4    将eth0、eth1网卡配置文件合并显示

[root@cobbler-node1 network-scripts]# paste ifcfg-eth0 ifcfg-eth1
TYPE=Ethernet TYPE=Ethernet
BOOTPROTO=none BOOTPROTO=none
DEVICE=eth0 DEVICE=eth1
ONBOOT=yes ONBOOT=yes
USERCTL=no USERCTL=no #控制用户是否有修改网卡的权限,必须设置为no,只有root用户才可以修改
MASTER=bond0 MASTER=bond0
SLAVE=yes SLAVE=yes

1.5    对比eth0、eth1网卡配置文件不同内容

[root@cobbler-node1 network-scripts]# diff ifcfg-eth0 ifcfg-eth1
3c3
< DEVICE=eth0
---
> DEVICE=eth1

1.6    在/etc/modprobe.d/目录下创建bonding.conf(网卡绑定模式)配置文件

[root@cobbler-node1 network-scripts]# echo -e "alias bond0 bonding\noptions bond0 mode=6 miimon=100" >> /etc/modprobe.d/bonding.conf
[root@cobbler-node1 network-scripts]# cat /etc/modprobe.d/bonding.conf
alias bond0 bonding
options bond0 mode=6 miimon=100
注意:
#mode=6代表负载均衡;两块网卡同时工作,增加网络带宽,不需要依赖物理交换机设置
#mode=1代表主备切换;只有一块网卡处于活动状态,活动网卡故障切换到备用网卡
#miimon=100代表网络链路检测频率100ms检查一次,如果出现问题则切换到备用网卡

1.7    执行modprobe bonding命令更新加载bonding模块,使其系统支持网卡bonding

[root@cobbler-node1 network-scripts]# modprobe bonding
#验证bonding模块是否加载成功,出现如下结果则证明加载成功
[root@cobbler-node1 network-scripts]# lsmod | grep bonding
bonding 145728 0

1.8    重启系统网络服务

[root@cobbler-node1 network-scripts]# systemctl restart network

1.9    查看网卡绑定的模式以及绑定的网卡状态信息

[root@cobbler-node1 network-scripts]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011) Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0 Slave Interface: eth0
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 28:6e:d4:88:ce:5d
Slave queue ID: 0 Slave Interface: eth1
MII Status: up
Speed: Unknown
Duplex: Unknown
Link Failure Count: 0
Permanent HW addr: 28:6e:d4:88:ce:5e
Slave queue ID: 0

1.10    查看系统网络信息,验证绑定成功

[root@cobbler-node1 network-scripts]# ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
inet 10.129.49.240 netmask 255.255.255.0 broadcast 10.129.49.255
inet6 fe80::2a6e:d4ff:fe88:ce5d prefixlen 64 scopeid 0x20<link>
ether 28:6e:d4:88:ce:5d txqueuelen 1000 (Ethernet)
RX packets 1675775 bytes 126050576 (120.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3432 bytes 496778 (485.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth0: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 28:6e:d4:88:ce:5d txqueuelen 1000 (Ethernet)
RX packets 837774 bytes 63015040 (60.0 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1718 bytes 237790 (232.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth1: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 28:6e:d4:88:ce:5d txqueuelen 1000 (Ethernet)
RX packets 838224 bytes 63053418 (60.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1714 bytes 258988 (252.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1 (Local Loopback)
RX packets 8 bytes 584 (584.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 584 (584.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0