Configuring active/backup bonded interfaces on CentOS Linux hosts


I have been doing quite a bit of experimentation with the Linux network stack in the past few weeks. One thing I have always liked about Linux networking is the bonding implementation, which allows you to aggregate one or more interfaces together for high availability purposes. To create a bonded interface on a CentOS Linux host, you will first need to locate two or more NICs to use. Once you locate a couple of NICs, you will need to create an ifcfg-eth[0-9] interface file similar to the following for each interface:

$ cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

$ cat /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

The difference between these files and the typical interface definition files is the removal of the network information, and the inclusion of the MASTER and SLAVE directives. The MASTER directive indicates which bond to enslave (using ifenslave) the interface to, and the SLAVE directive indicates that this interface will be a slave interface. To configure an actual bond, you will need to create a file named ifcfg-bond[0-9] that contains something similar to the following:

$ cat /etc/sysconfig/network-scripts/ifcfg-bond0

DEVICE=bond0
IPADDR=192.168.1.60
NETMASK=255.255.255.0
NETWORK=192.168.1.0
BROADCAST=192.168.1.255
ONBOOT=yes
BOOTPROTO=static
USERCTL=no
BONDING_OPTS="mode=active-backup fail_over_mac=1 arp_interval=500 arp_ip_target=192.168.1.1 num_grat_arp=3"

The bond interface definition file contains the name to assign to the bonded interface as well as the network configuration. You can optionally set one or more bonding options with the BONDING_OPTS directive. Now you may be asking yourself, what bonding options are available? You can view a full list on kernel.org, or by perusing the bonding.txt file that comes with the kernel source.

In the example above, I configured the mode to be active-backup (you can also adjust the mode to enable 802.3ad or a more sophisticated bonding mode to better distribute traffic over the available interfaces). I also set fail_over_mac to instruct the bond to assign the MAC address of the active interface to the bond (this is required if you are testing with VMWare server, and is not rquired if you are using physical NICs), arp_interval to control how often ARP requests are sent to test for availability, arp_ip_target to control where ARP requests are sent, and num_grat_arp to control the number of gratuitous ARPs that are issued when a network failover occurs. I have a follow up post that describes how to configure the Linux bonding implementation to work with 802.3ad, so stay tuned.

This article was posted by Matty on 2009-04-11 14:30:00 -0400 -0400