Network: Creating Bonding
Introduction
Channel bonding, also known as Port Trucking, allows applying a series of predefined policies on a group of network links combined into one. This group of network interfaces gives you the ability to perform load balancing and especially fault tolerance. Seven operation modes are available to combine necessity and flexibility. In this article, we will explore the possibilities offered and their implementation.
Installation
Prerequisites
Two prerequisites appear at the network switch level, where the interfaces are connected:
- Support and configuration of “port trunking” mode on the used ports
- Support for IEEE 802.3ad standard
For your Linux system, you need: Network cards (preferably compatible with ethtools and miitools).
Bonding module for the kernel.
- Kernel 2.4.x
|
|
- Kernel 2.6.x
|
|
|
|
ethtools and miitools
The bonding driver can only use one interface if a cable is disconnected. Since hardware failures are the most common on a server, this provides high availability. Note that there are two small tools for querying the ETHTOOL and MII registers of network cards. The tools are mii-tool (from the net-tools package) and ethtool. Not all interfaces support these registers; in this case, we cannot detect disconnection (there is a solution using ARP requests, but that’s beyond the scope of this article). To use this bonding function, you need to use modes such as active-backup; for more info, read the documentation :).
MII
|
|
|
|
Ethtool
With the Intel Pro dual card:
|
|
With the 3Com card, it doesn’t work:
|
|
The Different Modes
In this chapter, we’ll see the different modes offered by the bonding module:
Name | Mode | Description |
---|---|---|
balance-rr: load balancing | 0 | With load balancing, packets travel on one active network card, then on another, sequentially. The bandwidth is increased. If one of the network cards fails, the load balance skips this card and continues to rotate cyclically. |
active-backup: active backup | 1 | This mode is simple redundancy with failover. Only one interface is active. As soon as its failure is detected, another interface is activated and takes over. Your bandwidth does not change. |
balance-xor: Xor balance | 2 | An interface is assigned to send to the same MAC address. Thus transfers are parallelized and the choice of the interface follows the rule: (Source MAC address XOR Destination MAC address) modulo number of interfaces. |
broadcast: broadcast | 3 | No particularity in this case, all data is transmitted on all active interfaces. No other rule. |
802.3ad: 802.3ad standard | 4 | The 802.3ad standard allows link aggregation, dynamically expanding bandwidth. Groups are created dynamically based on common parameters. |
balance-tlb: TLB balance | 5 | “TLB” for Traffic Load Balancing. Outgoing traffic is distributed according to the current load (calculated relative to the speed) of each interface. Incoming traffic is received by the current interface. If the receiving interface becomes inactive, another interface takes the MAC address of the inactive interface. |
balance-alb: ALB balance | 6 | “ALB” for Adaptive load balancing. This is an extended mode of tlb balance, which includes receiving load balancing. Receive load balancing is performed at the ARP response level. The module intercepts ARP responses and changes the MAC address to that of one of the interfaces. |
Implementation
Presentation with a Script
WARNING: I use mode0! This is only possible if each interface is on a different switch, otherwise beware of packet duplication.
Let’s see a minimal script:
|
|
Let’s look closer:
- Module loading:
Two options were included here: mode (load balancing round-robin) and miimon (Interface monitoring frequency) It’s possible to put in the /etc/modules.conf file the loading of the bonding module or in /etc/modprobe.d/arch/i386:
|
|
This first example shows the case of a single bonding. It is indeed possible to have multiple bondings with different modes. For this, let’s modify the /etc/modules.conf accordingly:
|
|
- primary=eth1: forces eth1 interface to be primary
- max_bonds=2: allows having 2 bonds (so 4 interfaces but 2 bonds). Just increase this number if you want several bonds.
- -o bond0: this is essential if you want to use multiple bonds! You will then need to specify bond0, bond1, bond2…
Adding Interfaces to bond0
The ifenslave command allows us to add ethernet interfaces to bond0 (then called slave interfaces). When adding the first network interface to bond0, the latter takes the MAC address of that interface. The other interfaces then lose their MAC addresses, covered by that of the bond0 interface.
To remove an interface, simply run the command:
|
|
The bonding module then gives ethX back its real MAC address. If we remove the first MAC address (the one used by bond0), then bond0 retrieves that of eth1.
To verify our bonding:
|
|
Automatic Configuration Files
Bonding Module Options
Here is a series of the most commonly used options for the bonding module that allow fine-tuning the operation of your bonding:
Parameter | Description |
---|---|
Primary | Only for active-backup. Prioritizes a slave interface. It will become active again as soon as it can, even if another interface is active. |
updelay | (0 by default) Latency time between discovering the reconnection of an interface and its re-use. |
downdelay | (0 by default) Latency time between discovering the disconnection of an interface and its deactivation from bond0. |
miimon | (0 by default) Frequency of monitoring interfaces by Mii or ethtool. The recommended value is 100. |
use_carrier | (1 by default) Specifies the use of interface monitoring by miitool or by the network card itself (requires integrated instructions). |
arp_interval (in ms) | ARP monitoring system, avoiding the use of miitool and ethtool. If no frame arrives during the arp_interval, up to 16 ARP requests are sent through this interface to 16 IP addresses. If no response is obtained, the interface is deactivated. |
arp_ip_target | List of IP addresses, separated by a comma, used by ARP monitoring. If none is specified, ARP monitoring is inactive. |
If you want the complete list of options, you can get it this way:
|
|
Some Examples
A simple redundancy with priority on eth1:
|
|
Load balancing with ARP request verification:
|
|
Summary Table of Modes
Here are the different modes offered by the bonding module with load balancing support:
Mode | Load-Balancing |
---|---|
0 | incoming |
1 | none |
2 | incoming |
3 | none |
4 | none |
5 | incoming |
6 | incoming and outgoing |
Conclusion
Network card redundancy is often perceived as useless and expensive despite a simple installation. With these 7 modes of operation, you have the ability to obtain a high availability network interface, even responding to specific needs for load balancing. So why not take advantage of it?
Other Documentation
Bonding documentation on Ubuntu
http://www.linux-foundation.org/en/Net:Bonding
NIC Bonding On Debian Lenny
http://bisscuitt.blogspot.fr/2007/10/redhat-linux-rhel-4-nic-bonding.html
Last updated 18 Apr 2012, 18:44 CEST.