Introduction
Network interfaces (NICs) are crucial to any server machine. If you can't talk to the network, you can't do much of anything. In any high-availability system, you want to remove as many single-points-of-failure as possible, and NICs are no exception. The linux kernel provides several ways to aggregate (bond) many physical NICs into a single virtual interface. This interface looks like a single thing to any applications which use it.
There are 2 primary use cases for using bonding:
- Load balancing for higher throughput : If you have more network traffic than can flow through a single interface, you can build a single bonded interface which uses all the bandwidth of its physical interfaces. Keep in mind that this doesn't necessarily provide high-availability. (If you NEED 2 Gb/sec of throughput, losing 1 of your 2 1 Gb/sec interfaces will kill you.)
- Failover for high availability : Sets of physical interfaces can be configured in primary/secondary arrangements. Traffic flows through only 1 interface at a time, but if that interface fails for some reason, the bonding driver instantly starts routing traffic through the secondary instead.
There are many bonding modes supported by the linux kernel. Some provide load balancing, some provide high-availability, some may provide both. Some require cooperation/configuration on the switch, and some don't. Modes are described in detail : http://www.linuxfoundation.org/collaborate/workgroups/networking/bonding
Configure Network Interfaces
First we create a configuration script for the virtual interface. This is the thing which can have IP addresses configured on it.
/etc/sysconfig/network-scripts/ifcfg-bond0
IPADDR=192.168.0.1
NETMASK=255.255.255.0
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
BONDING_OPTS="mode=0 miimon=100 primary=eth2"
Selecting a different bonding mode is simply a matter of changing the mode=0 option listed above.
Now we need to create configuration scripts for the physical interfaces which will be part of bond0. Since they are configured as components of bond0 instead of independent interfaces in their own right, they cannot have IP addresses attached to them.
/etc/sysconfig/network-scripts/ifcfg-eth2
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
/etc/sysconfig/network-scripts/ifcfg-eth3
USERCTL=no
BOOTPROTO=none
ONBOOT=yes
MASTER=bond0
SLAVE=yes
Configure modprobe
Add the following to /etc/modprobe.conf
options bond0 mode=balance-rr miimon=100
The options specified here get overridden by those in ifcfg-bond0, but it may be helpful in some circumstances to know that you can set options here as well.
Then load the module
Start It Up
Now restart the nework to bring up the bonded device.
You can get information on the bonding configuration and status:
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)
Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth2
MII Status: up
Link Failure Count: 1
Permanent HW addr: 00:26:55:32:26:2c
Slave Interface: eth3
MII Status: up
Link Failure Count: 1
Permanent HW addr: 00:26:55:32:26:2e
Tests
- Try pinging over the bonded interface, and make sure you aren't dropping packets.
- Use
tcpdumpon both interfaces to see which one is being used. In round-robin mode, both should be generating traffic. In failover mode, only 1 should be. More info in the last paragraph of this post: http://lists.linbit.com/pipermail/drbd-user/2007-September/007440.html
