linux 网卡 绑定 bond 主备
一、做linux双网卡bond
1.    编辑文件:
#vi /etc/modprobe.conf
添加:
alias bond0 bonding
options bond0 miimon=100 mode=1
(mode=0 表示load blance 简称AA模式;mode=1 表示热备,简称AB模式)注:millmon是用来进行链路监测的,millmon=100,表示每100ms监测一次链路连接状态,
如果有一条不通,就转入另一条,这个值建议为100, 设成其它值可能导致不稳定)
2.    创建bond0起动配置文件:
cd /etc/sysconfig/network-scripts/
cp ifcfg-eth0 ifcfg-bond0
vi ifcfg-bond0
内容如下:
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.12
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
USERCTL=no
3.    编辑ifcfg-eth0 , ifcfg-eth1两个网卡配置文件,内容如下:
#vi ifcfg-eth0
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0  //这两行主要是用于系统service network restart
SLAVE=yes     //后自动启用
BOOTPROTO=none
HWADDR=XXXXXXXXXXXXXX (本网卡的MAC,可加可不加)
         
#cp ifcfg-eth0 ifcfg-eth1
#vi ifcfg-eth1
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0     //这两行主要是用于系统service network restart
SLAVE=yes       //后自动启用
BOOTPROTO=none
HWADDR=XXXXXXXXXXXXXX  (本网卡的MAC,可加可不加)
 
至此,linux服务器端配置完毕,重启(命令:reboot)或重启网络服务(命令:service network restart)看到bong0激活成功。
你可以一直ping这个IP,然后分别插拔服务器的两根网线看是否丢包即可确认你的bond0是否为主备模式。
或者 cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.1.2 (January 20, 2007)
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
Link Failure Count: 0
Permanent HW addr: 00:14:5e:fc:16:78
Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:14:5e:fc:16:7a
二、做单bond多IP
修改文件:/etc/sysconfig/network-scripts/ifcfg-bond0 为以下内容(相对于上面等于是屏蔽了几行)
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=static
新增文件:/etc/sysconfig/network-scripts/ifcfg-bond0:0
DEVICE=bond0:0
ONBOOT=yes
BOOTPROTO=static
NETWORK=172.16.174.0
NETMASK=255.255.255.0
IPADDR=172.16.174.11
GATEWAY=172.16.174.254
USERCTL=no
TYPE=Ethernet
新增文件:/etc/sysconfig/network-scripts/ifcfg-bond0:1
DEVICE=bond0:1
ONBOOT=yes
BOOTPROTO=static
NETWORK=172.16.175.0
NETMASK=255.255.255.0
IPADDR=172.16.175.11
GATEWAY=172.16.175.254
USERCTL=no
TYPE=Ethernet
 
三、做多网卡多bond方式(如我要把1-2网卡做一个bond,3-4网卡做一个bond.
[root@addrdb02 ~]# cat /etc/modprobe.conf  (如下:)
alias scsi_hostadapter usb-storage
alias eth0 bnx2
alias eth1 bnx2
alias eth2 e1000
alias eth3 e1000e
alias scsi_hostadapter1 qla2xxx_conf
alias scsi_hostadapter2 qla2xxx
alias scsi_hostadapter2 cciss
alias scsi_hostadapter3 ata_piix
alias usb-controller uhci-hcd
alias usb-controller1 ehci-hcd
alias bond0 bonding
options bonding mode=1 miimon=100 updelay=100 max_bonds=2 (做两个bond时此处设为2)
alias bond1 bonding

[root@addrdb02 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
NETWORK=172.16.174.0
NETMASK=255.255.255.0
IPADDR=172.16.174.11
GATEWAY=172.16.174.254
USERCTL=no
TYPE=Ethernet
[root@addrdb02 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond1
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
NETWORK=172.16.175.0
NETMASK=255.255.255.0
IPADDR=172.16.175.11
USERCTL=no
TYPE=Ethernet
[root@addrdb02 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no
HWADDR=XXXXXXXXXXXXXX  (本网卡的MAC,可加可不加)
TYPE=Ethernet
[root@addrdb02 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
MASTER=bond0
SLAVE=yes
USERCTL=no
HWADDR=XXXXXXXXXXXXXX  (本网卡的MAC,可加可不加)
TYPE=Ethernet
[root@addrdb02 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
ONBOOT=yes
BOOTPROTO=none
MASTER=bond1
SLAVE=yes
USERCTL=no
HWADDR=XXXXXXXXXXXXXX  (本网卡的MAC,可加可不加)
TYPE=Ethernet
[root@addrdb02 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth3
DEVICE=eth3
ONBOOT=yes
BOOTPROTO=none
MASTER=bond1
SLAVE=yes
USERCTL=no
HWADDR=XXXXXXXXXXXXXX  (本网卡的MAC,可加可不加)
TYPE=Ethernet