Linux 6.5 雙網卡綁定
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,平衡循環模式。
-
配置網卡文件
[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
-
測試是否可行
拔掉第一個接口,看是否能自動切換,然后再插回去,拔掉第二條線,看是否能來回切換成功。