Linux双网卡绑定——理论与实践(实践篇)
Linux双网卡绑定的主要实现步骤为:
1. 配置一个虚拟的网卡bond0
2. 配置eth0,eth1为slave模式
3. 加载bonding模块
4. 重启系统
下面将详细介绍每个步骤
一. 配置虚拟网卡bond0
新建/etc/sysconfig/network-scripts/ifcfg-bond0文件,内容如下:
DEVICE=bond0
BOOTPROTO=static
IPADDR=192.168.0.100
NETMASK=255.255.255.0
BROADCAST=192.168.0.255
GATEWAY=192.168.0.1
ONBOOT=yes
TYPE=Ethernet
二. 配置eth0,eth1为slave模式
更改配置文件/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
SLAVE=yes
MASTER=bond0
USERCTL=yes
更改配置文件/etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
SLAVE=yes
MASTER=bond0
USERCTL=yes
三. 加载bonding模块
修改模块配置文件/etc/modprobe.conf,在最后加入以下内容:
options bond0 miimon=100 mode=0
四. 重启系统
重启之后,测试bonding是否正常运行,运行ifconfig命令,结果如下
bond0 Link encap:Ethernet HWaddr 00:0C:29:45:B4:D1
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe45:b4d1/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:100 errors:0 dropped:0 overruns:0 frame:0
TX packets:130 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:17527 (17.1 KiB) TX bytes:20937 (20.4 KiB) eth0 Link encap:Ethernet HWaddr 00:0C:29:45:B4:D1
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:65 errors:0 dropped:0 overruns:0 frame:0
TX packets:99 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10340 (10.0 KiB) TX bytes:15317 (14.9 KiB)
Interrupt:18 Base address:0x1080 eth1 Link encap:Ethernet HWaddr 00:0C:29:45:B4:D1
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:40 errors:0 dropped:0 overruns:0 frame:0
TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7487 (7.3 KiB) TX bytes:7022 (6.8 KiB)
Interrupt:19 Base address:0x1400
运行cat /proc/net/bonding/bond0,结果如下:
Ethernet Channel Bonding Driver: v3.3.0 (June 10, 2008)
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
Link Failure Count: 0
Permanent HW addr: 00:0c:29:45:b4:d1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:45:b4:db