网卡绑定by吴迪
1新建bond0
cp ifcfg-eth0 ifcfg-bond0
vi bond0
# Intel Corporation 82545EM GigabitEthernet Controller (Copper)
DEVICE=bond0
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.1.111
NETMASK=255.255.255.0
BCAST=192.168.1.255
TYPE=Ethernet
2、 修改eth0
# Intel Corporation 82545EM GigabitEthernet Controller (Copper)
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
3、 eth1同样配置修改DEVICE=eth1
4、 修改配置文件
vi modprobe.conf
增加两行下面语句:
alias bond0 bonding
option bond0 miimon 100 mode 1
注 :
miimon是用来进行链路监测的。比如:miimon=100,那么系统每100ms监测一次链路连接状态,如果有一条线路不通就转入另一条线路;mode的值表示工作模式,他共有0,1,2,3四种模式,常用的为0,1两种。
mode=0表示load balancing (round-robin)为负载均衡方式,两块网卡都工作。
mode=1表示fault-tolerance (active-backup)提供冗余功能,工作方式是主备的工作方式,也就是说默认情况下只有一块网卡工作,另一块做备份.
5、 修改/etc/rc.local配置文件
添加如下2行
ifenslave bond0 eth0 eth1
route add -net 192.168.1.0 netmask 255.255.255.0 bond0
6、 重启后验证/proc/net/bonding/bond0 文件并通过插拔网线判断网络状态是否启用主备模式。