Pages

Sunday, April 23, 2017

What is Bonding and how to do it

What is Bonding

Linux network bonding is creation of a single bonded  interface by combining 2 or more Ethernet interfaces. This is done for multiple purposes like HA, load distributing etc.... Below are the some of modes of bonding. Based on the mode configured the respective device will act.

Modes of Bonding

Mode 0 – Round robin
Mode 1 – Active Backup
Mode 2 – Balance XOR
Mode 3 – Broadcast
Mode 4  - 802.3as
Mode 5 – Balance TLB
Mode 6 – Balance TLB

List of Confiuration files used -  /etc/modprobe.conf, /etc/sysconfig/network-scritps/ifcfg-bond0,   /proc/net/bonding/bond0

How to do Bonding


(i) Create a  file named <anything>.conf (as long as it ends with a .conf extension) in the /etc/modprobe.d/ directory or add below entry in /etc/modprobe.conf file.

alias bond0 bonding

Above line  creates a interface named bond0 for bonding. Now we need to configure IP address and other details for the interface which will be done by creating a new file file in network-scripts folder.

To be added in configuration file


Other options :  Options bond0 mode=1 miimon=100

(ii) Load the bond driver module from command prompt : modprobe bonding

(iii) Now the IP address and other details need to be added for bond0 device and other interface details need to be changed as slave.

** An Sample entry of  bond interface configuration files **

# Cat /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.1.1
NETMASK=255.255.255.0
ONBOOT=yes
BOOTPROTO=none
USERCTL=no

** An Sample entry of other interface configuration files **

# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
USERCTL=no
ONBOOT=yes
MASTER=bond0
SLAVE=yes
BOOTPROTO=none

Note: No IP address should be mentioned in slave files

After configuring above details restart the network service and check the status of bonding.

cat  /proc/net/bonding/bond0

To verify whether bonding works, do an ifdown eth0 and check /proc/net/bonding/bond0 and check the current active slave. Meanwhile do a continuous ping to the bond0 IP from different machine and do a ifdown to active interface. Ping should not work.

How to  change slave device in bonding

There may be a situation where we need to change the active device of bond0 from eth0 to eth1. In that case we need to use ifenslave command to do the same.

# Ifenslave –c bond0 eth1   ; Changes the active to eth1
# Ifenslave –d  bond0 eth0  ; Removes eth0 from bonding
# Ifenslave  bond0 eth2

-a, - all-interfaces  show information about all interfaces.
-c, - Change active slave.
-d, - Removes slave interfaces from the bonding device.
-f,  - Force actions to the specified interfaces appears not to belong to an Ethernet device.
-u, - usage. Show usage information and exit.
-v, - verbose. Print warning and debug messages.
-V, - version. Show version information and exit.

It means that if one card fails-second starts to work. mode=1 in your file means the same. 

miimon:
Specifies the MII link monitoring frequency in milliseconds. This determines how often the link state of each slave is inspected for link failures. A value of zero disables MII link monitoring. A value of 100 is a good starting point. Somewhere I read that, it is deprecated. Not very sure. I think now bond driver uses netif_carrier_ok to find the link status of its slaves.

No comments:

Post a Comment