Blog

How to Setup Network Bonding with Debian 6

In order to setup either load balancing or redundant NICS on your Debian server, you will need at least two NICS connected to either different switches (failover and possible load balancing) or the same switch (load balancing only).
First off, you need to install the bonding module by:

#sudo apt-get install ifenslave-2.6
#sudo modprobe bonding && echo bonding >> /etc/modules

This will install the module as well as load the module at boot.
Now we need to edit the /etc/network/interfaces file as follows:

#sudo cp /etc/network/interfaces /etc/network/interfaces.org
#sudo vi /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto bond0
iface bond0 inet static
address 192.168.2.8
netmask 255.255.255.0
network 192.168.2.0
broadcast 192.168.2.255
gateway 192.168.2.1
bond-mode balance-rr
bond-miimon 100
bond-downdelay 200
bond_updelay 200
slaves eth0 eth1

Reboot and test by checking that bond0 is UP and that eth0 and eth1 (in this case) are UP and running as SLAVE.

A Note About Various Bonding Policies

In the above example bounding policy (mode) is set to 0 or balance-rr. Other possible values are as follows:

The Linux bonding driver aggregating policies
Bonding policies (mode) Description
balance-rr or 0 Round-robin policy to transmit packets in sequential order from the first available slave through the last. This mode provides load balancing and fault tolerance.
active-backup or 1 Active-backup policy. Only one slave in the bond is active. A different slave becomes active if, and only if, the active slave fails. This mode provides fault tolerance.
balance-xor or 2 Transmit based on the selected transmit hash policy. The default policy is a simple [(source MAC address XOR’d with destination MAC address) modulo slave count]. This mode provides load balancing and fault tolerance.
broadcast or 3 Transmits everything on all slave interfaces. This mode provides fault tolerance.
802.3ad or 4 Creates aggregation groups that share the same speed and duplex settings. Utilizes all slaves in the active aggregator according to the 802.3ad specification. Most network switches will require some type of configuration to enable 802.3ad mode.
balance-tlb or 5 Adaptive transmit load balancing: channel bonding that does not require any special switch support. The outgoing traffic is distributed according to the current load (computed relative to the speed) on each slave. Incoming traffic is received by the current slave. If the receiving slave fails, another slave takes over the MAC address of the failed receiving slave.
balance-alb or 6 Adaptive load balancing: includes balance-tlb plus receive load balancing (rlb) for IPV4 traffic, and does not require any special switch support. The receive load balancing is achieved by ARP negotiation.
[ Source: See Documentation/networking/bonding.txt for more information. ]

Force CentOS 6 to Detect New Network Devices

This is handy to know specially if you work with virtual machines. CentOS 6.x now uses udev to deal with all hardware devices. Udev managages hardware, including network interfaces, via .rules files which contain various attributes of a given piece of hardware that are used to match the device against a single device node each time it is connected to the system. When you move a virtual machine from one host to another, that copy has the original .rules files contained in it which will no longer match the new host (in terms of network connections, different MAC Address, UID, etc.). In the case of CentOS 6.x, the 70-persistent-net.rules file controls the network devices in the system and for what ever reason, CentOS 6.x does not update this file upon boot.

To force CentOS 6.x to detect the new settings, all you need to do is:

vi /etc/sysconfig/network-scripts/ifcfg-eth0

And remove the existing HWADDR line so that it won’t conflict with the new value written to the 70-persistent-net.rules file when you reboot the system. If there also exists a UID line, remove that as well.

Once you have saved the changes, all you need to do is to remove the existing 70-persistent-net.rules file by:

rm -f /etc/udev/rules.d/70-persistent-net.rules

Restart the computer or virtual machine and check that you now have network connectivity.