RHEL6: 网卡bonding

通过bonding,可以将两块或多块网卡当作一块网卡使用,可用于提高性能或是冗余。

参考文档

1. https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-networkscripts-interfaces-chan.html
2.

# yum install kernel-doc
# vim /usr/share/doc/kernel-doc-2.6.32/Documentation/networking/bonding.txt

实验环境

操作系统:RHEL 6.5
网卡: eth0, eth1, eth2

操作步骤

要将eth1和eth2两网卡bonding在一起。

写bond0的配置文件

首先需要建立一个bond0的配置文件,然后把eth1和eth2都关联到bond0上。

# vim /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.100.60
NETMASK=255.255.255.0
ONBOOT=yes
BOOTPROTO=none
NM_CONTROLLED=no
USERCTL=no
BONDING_OPTS="mode=1 miimon=100"

设置好ip地址,子网掩码和bonding_opts。

修改eth1和eth2的配置文件

修改eth1和eth2的配置文件,使它们成为bond0的slave.

# vim /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
TYPE=Ethernet
BOOTPROTO=none
HWADDR=52:54:00:6e:2c:b6
MASTER=bond0                                                                                                                                                           
SLAVE=yes
ONBOOT=yes

# vim /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
TYPE=Ethernet
BOOTPROTO=none
HWADDR=52:54:00:ad:01:e4
MASTER=bond0
SLAVE=yes
ONBOOT=yes 

modprobe配置

修改modprobe配置

# vim /etc/modprobe.d/bond0.conf 
alias bond0 bonding 

确认Bonding Kernel Module已经安装上。

# modprobe --first-time bonding

测试

重启网络

# /etc/init.d/network restart
# ifconfig

可以看到bond0已经起来了,有ip地址(eth1的ip地址),eth1和eth2是slave.
用以下命令查看bond0的详细信息

# cat /proc/net/bonding/bond0 
Ethernet Channel Bonding Driver: v3.6.0 (September 26, 2009)

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: 100 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 52:54:00:6e:2c:b6
Slave queue ID: 0

Slave Interface: eth2
MII Status: up
Speed: 100 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: 52:54:00:ad:01:e4
Slave queue ID: 0

Bonding选项

修改BONDING_OPTS可以使bonding发挥不一样的功能。
mode

Specifies one of the bonding policies. The default is
balance-rr (round robin). Possible values are:

balance-rr or 0
active-backup or 1
broadcast or 3