Wednesday, 19 March 2014

Ethernet Channel Bonding Configuration in Linux

Hello folks,
Recently we had a discussion on Ethernet Channel Bonding on Linux. My cool buddy (my friend) asked me some queries on Ethernet bonding and how to identify which mode the Ethernet bonding is currently configured. However at that point of time I was working on a critical issue and I was not in a position to explain details to him. So thought of keeping the YUM topic (with HTTP/FTP) on hold for time being and do Ethernet channel bonding now.  Hope this will help other people to understand the NIC bonding concepts!

Anyway let me start the topic now!

Ethernet Channel Bonding enables two or more Network Interfaces Card (NIC) to a single virtual NIC card which may increase the bandwidth and provides redundancy of NIC Cards. This is a great way to achieve redundant links, fault tolerance or load balancing networks in production system. If one physical NIC is down or unplugged, it will automatically move resources to other NIC card. 
Channel/NIC bonding will work with the help of bonding driver in Kernel.
There are 6 types of NIC bonding modes are available in Linux. However I am taking only 2 which is very commonly used.

0: Load balancing (Round-Robin): Traffic is transmitted in sequential order or round-robin fashion from both NIC. This mode provides load balancing and fault tolerance.
1: Active-Backup: Only one slave NIC is active at any given point of time. Other Interface Card will be active only if the active slave NIC fails.

So I hope we are done with the explanation now let us go through the configuration part.


I am using Redhat Enterprise Linux Server 6.3



Let me start with mode 0: Load balancing (Round-Robin):
I have 2 NIC cards in my server eth0 and eth1and the new interface is called as bond0


Edit the network configuration file under /etc/sysconfig/network-scripts/ifcfg-eth0 and Mention parameter MASTER bond0 and eth0 interface as a SLAVE in config file as shown below.


Repeat the same step and entry for eth1 configuration file.


Now let us create the channel bonding interface bond0 and configure Channel bonding interface in the “/etc/sysconfig/network-scripts/” directory called ifcfg-bond0.
Entry should looks like the below:
In the below configuration I have chosen Bonding Options mode=0 i.e Round-Robin and miimon=100 (Polling intervals 100 ms).


Now restart the network service. Make sure bonding module is loaded when the channel-bonding interface (bond0) is brought up. If you have not loaded the module, when bringing up bond0 network you will meet this error:

“Bringing up interface bond0:  Device bond0 does not seem to be present, delaying initialization.
[FAILED]”


Now you need to use modprobecommand to load the bonding driver.

 Now restart the network services. You can see this will be success and your channel bonding is done now:



You need create bonding.conf file under /etc/modprobe.d and add the below lines.so that the loaded bonding driver can survive the reboot.


Now check the bond0 configuration using  ifconfig command and you can see the similar output shown in below:

 

So this is the configuration part now you want see the status of the NIC channel bonding. You have to run the following command to see the status:


Sample output is shown below:




Mode 1: Active-Backup :
Suppose if you want to change the network bonding mode to a different mode you can simply edit the /etc/sysconfig/network-scripts/ifcfg-bond0file.  Only change is the mode no. here it is mode 1 (Active-Backup)


For activating the new setting you need to either reboot the server or you can run the following command online. This will remove and re-add the bonding driver and restart the network services to effect the changes.

#modprobe -r bonding;modprobe bonding;service network restart


Use cat /proc/net/bonding/bond0 to check the status:



Here is the details of other modes in Linux. Hope now you know how to configure the different modes now.
Mode 0 (balance-rr)
This mode transmits packets in a sequential order from the first available slave through the last. If two real interfaces are slaves in the bond and two packets arrive destined out of the bonded interface the first will be transmitted on the first slave and the second frame will be transmitted on the second slave. The third packet will be sent on the first and so on. This provides load balancing and fault tolerance.
Mode 1 (active-backup)
This mode places one of the interfaces into a backup state and will only make it active if the link is lost by the active interface. Only one slave in the bond is active at an instance of time. A different slave becomes active only when the active slave fails. This mode provides fault tolerance.
Mode 2 (balance-xor)
Transmits based on XOR formula. (Source MAC address is XOR’d with destination MAC address) modula slave count. This selects the same slave for each destination MAC address and provides load balancing and fault tolerance.
Mode 3 (broadcast)
This mode transmits everything on all slave interfaces. This mode is least used (only for specific purpose) and provides only fault tolerance.
Mode 4 (802.3ad)
This mode is known as Dynamic Link Aggregation mode. It creates aggregation groups that share the same speed and duplex settings. This mode requires a switch that supports IEEE 802.3ad Dynamic link.
Mode 5 (balance-tlb)
This is called as Adaptive transmit load balancing. The outgoing traffic is distributed according to the current load and queue on each slave interface. Incoming traffic is received by the current slave.
Mode 6 (balance-alb)
this is Adaptive load balancing mode. This includes balance-tlb + receive load balancing (rlb) for IPV4 traffic. The receive load balancing is achieved by ARP negotiation. The bonding driver intercepts the ARP Replies sent by the server on their way out and overwrites the src hw address with the unique hw address of one of the slaves in the bond such that different clients use different hw addresses for the server.

Similarly you can use ifenslave command to attach and detach slave network devices to a bonding device.

The following example shows how to setup a bonding device and enslave two real Ethernet devices to it:

# modprobe bonding
# ifconfig bond0 192.168.1.1 netmask 255.255.255.0
# ifenslave bond0 eth0 eth1
refer manpage for more details.
Hope this is useful! I would love to hear the feedback from your end so that I can improve the contents here.
Thanks in advance !

4 comments:

  1. Very good Vinil .
    Simple steps and good presentation.Keep it up .Eagerly waiting for next topic

    ReplyDelete
  2. Very easy to understand your presentation ,, Thanks a lot vinil

    ReplyDelete