建站服务器
Linux双网卡绑定
系统环境说明
操作系统:linux 6.5
Em1 网卡接口连接的是主交换机。
Em2网卡接口连接的是备交换机。
修改配置文件:
Vi /etc/modprobe.d/dist.conf
添加以下两行
alias bond0 bonding
options bonding mode=1 miimon=100
常规可使用方式,在生产环境,我还是偏向使用了主备模式,保守一些。
mode=1,代表的是主备模式。
mode=0,平衡循环模式。
mode=6,负载均衡模式。
配置网卡文件
[root@testdb network-scripts]# cat ifcfg-em1
DEVICE=em1
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
MASTER=bond0
SLAVE=yes
[root@testdb network-scripts]# cat ifcfg-em2
DEVICE=em2
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
MASTER=bond0
SLAVE=yes
[root@testdb network-scripts]# cat ifcfg-bond0
DEVICE=bond0
BOOTPROTO=static
IPADDR=192.168.88.101
NETMASK=255.255.255.0
GATEWAY=192.168.88.1
ONBOOT=yes
TYPE=Ethernet
NM_CONTROLLED=no —-此参数决定mac地址,最好保持两个网卡一致。否则路由器识别识别失败。
停止NetworkManager服务:
chkconfig NetworkManager off
service NetworkManager stop
modprobe bonding
service network restart
最好重启一下系统。
校验是否成功
Ifconfig -a
bond0 Link encap:Ethernet HWaddr 44:A8:42:06:E1:C1
inet addr:192.168.88.101 Bcast:15.21.72.255 Mask:255.255.255.0
inet6 addr: fe80::46a8:42ff:fe06:e1c1/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:185 errors:0 dropped:0 overruns:0 frame:0
TX packets:162 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:19774 (19.3 KiB) TX bytes:48110 (46.9 KiB)
em1 Link encap:Ethernet HWaddr 44:A8:42:06:E1:C1
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:156 errors:0 dropped:0 overruns:0 frame:0
TX packets:162 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:16596 (16.2 KiB) TX bytes:48110 (46.9 KiB)
Interrupt:35
em2 Link encap:Ethernet HWaddr 44:A8:42:06:E1:C1
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:29 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3178 (3.1 KiB) TX bytes:0 (0.0 b)
Interrupt:38
这里三个mac地址是一致的。
[root@testdb ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: em1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: em1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 44:a8:42:06:e1:c1
Slave queue ID: 0
Slave Interface: em2
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 44:a8:42:06:e1:c2
Slave queue ID: 0
测试是否可行
拔掉第一个接口,看是否能自动切换,然后再插回去,拔掉第二条线,看是否能来回切换成功。