NIC bonding on Ubuntu server 14.04

NIC bonding or port trunking or link aggregation is the process where two or more network ports or NICs are combined, in order to perform as a single port [1]. The process can be applied to servers as well as to switches. The steps described below are an adaptation of a very helpful article found in "ubuntu help" [2], and was the outcome of a lots of searching in the web and experimentation. The process applies to Ubuntu server 14.04. The working modes of NIC bonding ensure fault tolerance, load balance or increase in network speed since the two or more interfaces are working in parallel and double or triple the speed. This last feature is very useful on servers that need high throughput. More details about the bonding modes can be found in [3] and [4].

NIC bonding configuration

First, we assume that we know the IP address of the bonded interface (for this article's purpose it will be 192.168.0.15) and the domain name of the server (here mydomain.com).  The process described in this article creates a bonded interface that works in the active-backup mode (mode 1), which ensures fault tolerance. All the commands described here should be entered at the Linux console, so a basic understanding of the console and command line is necessary.  The commands will be coloured green and all the points that will need editing are marked red. Use the editor of your choice like nano or vim. My own preference is vim.

First update the system:

sudo apt-get update && sudo apt-get upgrade -y

Install the ifenslave package which ensures that two or more NICs can be bonded together.

sudo apt-get install ifenslave-2.6 -y

Edit your /etc/modules configuration file. This file describe which kernel modules are initialized at start-up. Ensure that the bonding module is loaded:

sudo vim /etc/modules

After editing the file should look like this:

# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.

loop
lp
rtc
bonding

The configuration of the bonding module is described in a separate file. Edit /etc/modprobe.d/bonding.conf file

sudo vim /etc/modprobe.d/bonding.conf

The contents of the file should be:

alias bond0 bonding
options bonding mode=1 miimon=100

Now  load the bonding kernel module:

sudo modprobe bonding

Backup the existing interfaces file, in case you will need to undo bonding.

sudo cp -f /etc/network/interfaces /etc/network/interfaces.nobond

NIC bonding is simple once you understand the limitations of each mode. if you're working in an environment where switches support 802.3ad and you have no special needs, use that mode. Conversely, if you have no switch support and just want to increase throughput and enable fail-over, use balance-alb. Finally, if you just need a data replication link between two servers, balance-rr is the way to go.

Edit your interfaces configuration:

sudo vim /etc/network/interfaces

For example, to combine eth0 and eth1 as slaves to the bonding interface bond0 using a simple active-backup setup, with eth0 being the primary interface:

# 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

#eth0 - the first network interface
auto eth0
iface eth0 inet manual
bond-master bond0
bond-primary eth0

#eth1 - the second network interface
auto eth1
iface eth1 inet manual
bond-master bond0

# The primary network interface
auto bond0
iface bond0 inet static
    address 192.168.0.15 #EDIT HERE THE ACTUAL IP ADDRESS
    netmask 255.255.255.0
    network 192.168.0.0 # EDIT THE NETWORK ADDRESS
    broadcast 192.168.0.255 #EDIT HERE THE ACTUAL BROADCAST ADDRESS
    gateway 192.168.0.250 #EDIT HERE THE ACTUAL GATEWAY ADDRESS
    bond-mode active-backup #This NIC bonding mode provides fault tolerance
    bond-miimon 100
    bond-slaves none
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 192.168.0.100 #EDIT HERE THE ACTUAL ADDRESS OF THE DNS SERVER
    dns-search mydomain.com

Backup the interfaces file to interfaces.bonding file :

sudo cp -f /etc/network/interfaces /etc/network/interfaces.bonding

Some times the bonded interface does not start, so it should be started manually. In order to automate this process, the commands should be given at start-up. rc.local is a good spot for this. Edit /etc/rc.local file

sudo vim /etc/rc.local

ifdown eth0
ifdown eth1
ifup eth0
ifup eth1
#edit here the actual address of bond0
ifconfig bond0 192.168.0.15 up

This last command might alter the /etc/resolv.conf file and result in loosing the nameserver information. This can be avoided by editing the /etc/resolvconf/resolv.conf.d/base file

sudo vim /etc/resolvconf/resolv.conf.d/base

and assuming that your name-server's address is 192.168.0.100 the contents should be:

nameserver 192.168.0.100
search mydomain.com

Now restart the network service:

sudo service networking restart

If this last step does not work and produces error messages you should reboot the system.

sudo reboot

Happy NIC bonding!

References

[1] Wikipedia - Link Aggregation

[2] Ubuntu Bonding

[3] Understanding NIC bonding with Linux

[4] Linux Ethernet bonding driver HOWTO

This entry was posted in Programming and tagged , , , , . Bookmark the permalink.