As you know network channel bonding is grouping physical network interfaces in to one single virtual interface to provide redundancy and increased throughput. In linux we have seven (7) bonding modes (mode 0 - mode 6) to support the network channel bonding. you can check the all available bonding method here and you can select the best method to use in your environment, but form my experience, most of the times we can go with mode 1, mode 4 and mode 6.
Assume if you need only the fault tolerance, then you can use mode 1 as your bonding mode or you need load balancing + fault tolerance, then you can go with mode 4 or 6 that depend on your underling physical network switch. if it support and configured to use IEEE 802.3ad Dynamic link aggregation, surely you can use mode 4 and if not simply go with mode 6. And also most of our physical boxes we have more than one network interfaces and I’m pretty sure most of us only using one interface to connect to the network. In other hand it can lead to single point of failure, so if you are doing any production deployment make sure to avoid single point of failures as much as possible and we can use NIC channel bonding to avoid network port failures, network cable failure or NIC failure (if you have two physical network cards) in our linux server.
Okay cool! how to configure that?
If you are using Fedora/RHEL or based distributions like CentOS or Oracle Linux NIC channel bonding process is quite simple but you have to edit few files here. First to enable bonding kernel module for your virtual network interface bond0, create a new file called “bonding.conf” in “/etc/modprobe.d/ directory and edit as follows or you need to create more than one bonding interfaces, need to add separate alias for them as “alias bondX bonding”.
# cat /etc/modprobe.d/bonding.conf alias bond0 bonding
And then you have to create a new network interface configuration file for “bond0” virtual interface as “ifcfg-eth0” in “/etc/sysconfig/network-scripts” directory and all network related stuffs are need to defined.
# cat /etc/sysconfig/network-scripts/ifcfg-bond0 DEVICE=bond0 NM_CONTROLLED=no USERCTL=no ONBOOT=yes BOOTPROTO=static IPADDR=192.168.0.11 NETMASK=255.255.255.0 GATEWAY=192.168.0.1 DNS1=192.168.0.2 DNS2=192.168.0.3 DOMAIN=hasitha.org BONDING_OPTS="mode=1 miimon=100"
Okay! now we create the bond0 interface and we need to configure eth0 and eth1 network interfaces as slave interfaces for the bond0 virtual interfaces. for that we need to edit “ifcfg-eth0” and “ifcfg-eth1” files located in the same directory “/etc/sysconfig/network-scripts”.
# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 HWADDR=XX:XX:XX:XX:XX:XX NM_CONTROLLED=no USERCTL=no ONBOOT=yes BOOTPROTO=none SLAVE=yes MASTER=bond0</pre>
# cat /etc/sysconfig/network-scripts/ifcfg-eth1 DEVICE=eth1 HWADDR=XX:XX:XX:XX:XX:XX NM_CONTROLLED=no USERCTL=no ONBOOT=yes BOOTPROTO=none SLAVE=yes MASTER=bond0
HAHA! now you are almost done! time to restart the network service or if it’s possible restart the server. after that, you can see the newly configured bond0 virtual interface is up and running.
# ifconfig bond0 Link encap:Ethernet HWaddr 00:10:E0:22:50:70 inet addr:192.168.0.11 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::210:e0ff:fe22:5070/64 Scope:Link UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 RX packets:6001623 errors:0 dropped:928245 overruns:0 frame:0 TX packets:2547959 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:853632915 (814.0 MiB) TX bytes:551819829 (526.2 MiB) eth0 Link encap:Ethernet HWaddr 00:10:E0:22:50:70 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:5073378 errors:0 dropped:0 overruns:0 frame:0 TX packets:2547964 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:768161611 (732.5 MiB) TX bytes:551820999 (526.2 MiB) eth1 Link encap:Ethernet HWaddr 00:10:E0:22:50:70 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:928245 errors:0 dropped:928245 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:85471304 (81.5 MiB) TX bytes:0 (0.0 b) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:24102239 errors:0 dropped:0 overruns:0 frame:0 TX packets:24102239 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:5913772444 (5.5 GiB) TX bytes:5913772444 (5.5 GiB)</pre>
If your using Debian/Ubuntu or based distribution, process is also simple but quite different than the Fedora/RHEL based distributions, In here you need to install additional package called “ifenslave - Attach and detach slave network devices to a bonding device” to support the network bonding.
# apt-get install ifenslave
Now we have to enable the bonding kernel module for the Debian/Ubuntu based system, for that we have to append the “bonding” keywords to the “/etc/modules” file.
# echo "bonding" >> /etc/modules
And now you can edit the network interface configuration file to configure the virtual bonding interface (bond0) and slave “eth0” and “eth1” interfaces. please note that in Fedora/RHEL based systems each network interface have their own configuration file and in Debian/Ubuntu based system we have only “/etc/network/interfaces” file to edit all network interfaces configuration.
# cat /etc/network/interfaces auto lo iface lo inet loopback auto eth0 iface eth0 inet manual bond-master bond0 auto eth1 iface eth1 inet manual bond-master bond0 auto bond0 iface bond0 inet static address 192.168.0.12 netmask 255.255.255.0 gateway 192.168.0.1 dns-nameservers 192.168.0.2 dns-nameservers 192.168.0.3 dns-search hasitha.org bond-mode 1 bond-miimon 100
Finally restart the network and you’r almost done. you can simply cable unplug or “ifdown” one network interface and check your network connectivity. feel free to comment if you have anything to clarify!