跳转至

linux bond配置步骤

一、网卡绑定

第一步:创建一个ifcfg-bondX

Bash
1
2
3
4
5
6
7
8
9
# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BONDING_OPTS="mode=0 miimon=100"
BOOTPROTO=none
ONBOOT=yes
IPADDR=192.168.0.180
NETMASK=255.255.255.0
NETWORK=192.168.0.0
USERCTL=no

BONDING_OPTS="mode=0 miimon=100" ,mode有多种模式实现不同的功能

第二步:修改ifcfg-ethX

Bash
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
USERCTL=no

第三步:配置/etc/modprobe.conf,添加alias bond0 bonding

Bash
# vim /etc/modprobe.conf
alias scsi_hostadapter mptbase
alias scsi_hostadapter1 mptspi
alias scsi_hostadapter2 ata_piix
alias scsi_hostadapter3 ahci
alias net-pf-10 off
alias ipv6 off
options ipv6 disable=1
alias eth0 b0                # 后面分组的名字,eth0 和 eth3 对应的是bond0
alias eth1 b1
alias eth2 e1000
alias eth3 b0
alias eth4 b1
alias bond0 bonding
alias bond1 bonding
options bond0 miimon=100 mode=1 primary=eth0
options bond1 miimon=100 mode=1 primary=eth1
options bonding max_bonds=2 miimon=200 mode=1

第四步:重启网络服务

service network restart

通过查看/proc/net/bonding/bond0,查看当前是用什么mode,如果是主备的话,当前是哪个网卡工作。

Bash
# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.4.0-1 (October 7, 2008)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: eth0 (primary_reselect always)
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:c8:7f:34

Slave Interface: eth3
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c8:7f:52

Bash
# cat /proc/net/bonding/bond1
Ethernet Channel Bonding Driver: v3.4.0-1 (October 7, 2008)

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: eth1
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c8:7f:3e

Slave Interface: eth4
MII Status: up
Speed: 1000 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 00:0c:29:c8:7f:5c