When hosting successful & busy websites or operating a critical server, high availability & redundancy are major factors to consider. To achieve high availability & redundancy, backup of the server & server clusters are prepared. One other thing that is used for HA/redundancy is Network Bonding.
Network Bonding refers to combining more than one NIC into a single NIC for the purpose of HA/redundancy or load balancing. When network bonding is achieved and one of the NICs fails, the load will be transferred to the next NIC in the bonding or we can even also configure it for load balancing.
Recommended Read: How to use IP Command for Beginners
Also Read: IP Route command: Create static routes or Change the default Gateway in Linux
In this tutorial, we are going to create network bonding for two interfaces on RHEL/CentOS 7 servers.
Install Module for Network Bonding
To create a network bond between NICs, we will require a bonding module. To load the bonding module into the system, run
$ modprobe bonding |
Once the module has been loaded, we will create a file for bonding interface ‘ifcfg-bind0’ in ‘/etc/sysconfig/network-scripts’ directory.
Configuring Bond interface
Goto ‘/etc/sysconfig/network-scripts’ & create bond file with following content,
$ cd /etc/sysconfig/network-scripts $ vi ifcfg-bond0DEVICE=bond0 TYPE=Bond NAME=bond0 BONDING_MASTER=yes BOOTPROTO=none ONBOOT=yes IPADDR=192.168.0.100 NETMASK=255.255.255.0 GATEWAY=192.168.0.1 BONDING_OPTS="mode=5 miimon=100" |
Here, mode=5 means network bond will provide fault tolerance & load balancing as well. Details of all available modes for network bonding are mentioned below,
mode=0 (Balance Round Robin)— round-robin mode for fault tolerance and load balancing.
mode=1 (Active backup)— Sets the active-backup mode for fault tolerance.
mode=2 (Balance XOR)— Sets an XOR (exclusive-or) mode for fault tolerance and load balancing.
mode=3 (Broadcast)— Sets a broadcast mode for fault tolerance. All transmissions are sent on all slave interfaces.
mode=4 (802.3ad)— Sets an IEEE 802.3ad dynamic link aggregation mode. Creates aggregation groups that share the same speed & duplex settings.
mode=5 (Balance TLB)— Sets a Transmit Load Balancing (TLB) mode for fault tolerance & load balancing.
mode=6 (Balance ALB)— Sets an Active Load Balancing (ALB) mode for fault tolerance & load balancing.
The next step is to configure network interfaces i.e. ifcfg-en0s3 & en0s5, for the bonding.
Configuring network interfaces
Make changes to both interfaces file & add parameters “MASTER” & “SLAVE” to it, so that it looks like,
TYPE=Ethernet BOOTPROTO=none DEVICE=enp0s3 ONBOOT=yes HWADDR="23:03:56:bh:56:9g" MASTER=bond0 SLAVE=yes |
Save both files & restart the networking services on the system,
$ systemctl restart network |
We can now run the ‘ifconfig’ command to verify our newly created bonding interface or we can also check the bonding by running the following,
$ cat /proc/net/bonding/bond0 |
This will provide complete information about the bonding interface.
Testing fault tolerance
To test if the network bonding is working or not, bring one of the network interfaces down. To do so, run
$ ifdown en0s3 |
& verify by making an HTTP or ssh request to the server via the bonding interface IP address, the network should be working just fine. Further, we can also check which interface is working & which is down by running the above command i.e
$ cat /proc/net/bonding/bond0 |
Note:- For persistent loading of the module at the system boot, run the following command,
$ echo modprobe bonding >> /etc/rc.modules
$ chmod +x /etc/rc.modules
This concludes our tutorial on network bonding. Please mention your queries/comments in the comment box below.
Thanks for posting this! I actually have to do this for a new CentOS 7 server that we just finished racking, so your timing is very fortunate for us. 🙂
I notice that you loaded the bonding module via modprobe early in the process, but didn’t see you mention any way of having that module be loaded on boot. Is the module automatically loaded at boot based off of the new ifcfg-bond0 file that was created as part of this tutorial?
The rc.modules is recommended to use, not rc.local because rc.modules gets executed earlier in the boot process…
Great post.Ne’er knew this, regards for letting me know.
very helpful post
Thank you.