Linux Interface Bonding
I have found a number of articles on the internet that detail the bonding process, but none of them seem to have all the information I need, or too much unimportant information. I thought I would bring them together and slather in my own experience where appropriate.
Interesting point:
“NIC Bonding” : Mostly used the in Linux world
“NIC Teaming”: Mostly used in the Windows world
“Port Trunking”: Mostly used in the networking world
Remember kids!
This article will cover how to bond interfaces in Ubuntu Linux. Which means it should work well with most Debian-based distros. I make no claim as to the usefulness it will provide in bonding on RedHat, Gentoo, Suse, etc.
Lets begin shall we?
Install requisite packages:
sudo apt-get install ifenslave
Now we need to make some changes to get the proper modules loaded into the kernel. Create the following file to make this happen.
sudo pico /etc/modprobe.d/bonding
In that file enter:
alias bond0 bonding options bonding mode=0 miimon=100
If you have multiple bonds you are going to enter them in this file, with any options you would like to adjust, just replicate what you did above:
alias bond0 bonding options bonding mode=0 miimon=100 alias bond1 bonding options bonding mode=1 miimon=100
Its important to point out the difference modes of bonds here, but really..you are probably only going to use 0, 1 or 2. I have only ever used mode 0. There are more, but if you use them you probably don’t have any business reading my article. Here is a basic run-down of the most commonly used modes:
mode=0 (balance-rr)
Round-robin policy: Stripes traffic across multiple interfaces. This mode provides load balancing and fault tolerance. the striping generally results in peer systems receiving packets out of order, causing TCP/IP’s congestion control system to kick in, often by retransmitting segments.
mode=1 (active-backup)
Active-backup policy: Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. The bond’s MAC address is externally visible on only one port (network adapter) to avoid confusing the switch. This mode provides fault tolerance. The primary option affects the behavior of this mode.
mode=2 (balance-xor)
XOR policy: Transmit based on [(source MAC address XOR'd with destination MAC address) modulo slave count]. This selects the same slave for each destination MAC address. This mode provides load balancing and fault tolerance.
mode=3 (broadcast)
Broadcast policy: transmits everything on all slave interfaces. This mode provides fault tolerance.
Now you will need to open up /etc/network/interfaces in everyones favorite editor, pico! Comment out (put a # sign before) any lines that have to do with eth0 or set your interfaces to DHCP. Add the following:
auto bond0
iface bond0 inet static
address 192.168.1.10
gateway 192.168.1.1
netmask 255.255.255.0
slaves eth0 eth1
bond-mode 0
bond-miimon 100That’s it! No seriously, it was really that easy. You just need to restart your networking (I like to reboot so I know the module is loaded all proper and such, but it isn’t necessary)
Update for Ubuntu 10.04 LTS!
——————————————-
With Ubuntu 10.04 LTS (I think it started in 9.04 actually, but I only using bonding on LTS releases) the method of bonding has changed slightly. Network handing has been migrated to upstart, this means all network devices are not handled in a hotplug manor. You will need to modify your /etc/network/interfaces file as such (continuing from the example above):
auto bond0
iface bond0 inet static
address 192.168.1.10
gateway 192.168.1.1
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
bond-slaves none
bond-mode 1
bond-miimon 100
auto eth2
iface eth2 inet manual
bond-master bond0
bond-primary eth2 eth3
auto eth3
iface eth3 inet manual
bond-master bond0
bond-primary eth2 eth3Not totally different, but a difference none-the-less.
——————————————-
sudo /etc/init.d/networking restart
A couple of important things to note!
- If you ever want to un-bond your devices or make a change to the bond, you are going to need to restore the MAC address to the device you are removing. Just issue the following to do this (if you were unbonding your first interface from your first bond):
- The bonding driver uses the MAC address from the first bonding device
ifenslave -d bond0 eth0
References:


