linux系统做双网卡绑定,经过实验得出以下步骤
系统版本:CentOSrelease 6.8 (Final)
系统内核版本:2.6.32-642.el6.x86_64
cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=dhcp
cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=dhcp
cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.137.10
NETMASK=255.255.255.0
DNS1=202.96.128.166
alias bond0 bonding
options bond0 miimon=100 mode=1 #若想使用负载均衡模式,修改mode=0,其他配置不动即可
说明:
miimon是毫秒数,每100毫秒触发检测线路稳定性的事件
mode 是ifenslave的工作状态
miimon=100表示系统每100ms监控一次链路连接状态,如果有一条线路不通就转入另一条线(此监控是监控服务器到交换机之间的线路,交换机以上的线路断开了,此监控线路也显示没有故障问题)
mode=1表示active-backup,提供冗余功能,工作方式是主备,默认情况下只有一块网卡工作,另一块做备份网卡
mode=0表示round-robin,负载均衡,此状态并没有增加带宽,只是在两块网卡轮询工作,两块网卡的带宽速率是平均的,同时也支持容错能力(此状态需要交换机做聚合端口)
ifenslave bond0 eth0 eth1 #启动将eth0、eth1绑定成bond0
route add default gw 192.168.137.1 bond0 #启动添加默认网关
ifconfig
bond0 Linkencap:Ethernet HWaddr 00:0C:29:A6:77:FA
inetaddr:192.168.137.10 Bcast:192.168.137.255 Mask:255.255.255.0
inet6 addr:fe80::20c:29ff:fea6:77fa/64 Scope:Link
UP BROADCAST RUNNINGMASTER MULTICAST MTU:1500 Metric:1
RX packets:1737errors:0 dropped:0 overruns:0 frame:0
TX packets:930errors:0 dropped:0 overruns:0 carrier:0
collisions:0txqueuelen:0
RX bytes:138239(134.9 KiB) TX bytes:105449 (102.9 KiB)
eth0 Linkencap:Ethernet HWaddr 00:0C:29:A6:77:FA
inet6 addr:fe80::20c:29ff:fea6:77fa/64 Scope:Link
UP BROADCAST RUNNINGSLAVE MULTICAST MTU:1500 Metric:1
RX packets:1521errors:0 dropped:0 overruns:0 frame:0
TX packets:746errors:0 dropped:0 overruns:0 carrier:0
collisions:0txqueuelen:1000
RX bytes:124324(121.4 KiB) TX bytes:94507 (92.2 KiB)
eth1 Link encap:Ethernet HWaddr 00:0C:29:A6:77:FA
UP BROADCAST RUNNINGSLAVE MULTICAST MTU:1500 Metric:1
RX packets:221errors:0 dropped:0 overruns:0 frame:0
TX packets:199errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RXbytes:15061 (14.7 KiB) TX bytes:12592(12.2 KiB)
说明:
bond0、eth0、eth1的MAC地址都是一样的
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): 100
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:a6:77:fa
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:a6:77:04
Slave queue ID: 0
说明:
实际eth0和eth1的MAC地址是不一样的
ping192.168.137.10 –t
物理断开eth0:
查看bond0信息:eth0断开,系统使用eth1网卡
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: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
MII Status: down
Speed: Unknown
Duplex: Unknown
Link Failure Count: 1
Permanent HW addr: 00:0c:29:a6:77:fa
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:a6:77:04
Slave queue ID: 0
本文出自 “斌少的技术博客” 博客,请务必保留此出处http://yinjianbin.blog.51cto.com/4529118/1879886
原文地址:http://yinjianbin.blog.51cto.com/4529118/1879886