Saturday, September 10, 2011

Linux network interface bonding

Step 1.  To keep backup of MAC Address

# ifconfig | grep eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:7D:12:D0
# ifconfig | grep eth1
eth1      Link encap:Ethernet  HWaddr 00:0C:29:7D:12:DA

Step 2.  To create a virtual network interface configuration

# cd /etc/sysconfig/network-scripts/
# vi ifcfg-bond0
DEVICE=bond0
IPADDR=10.0.0.101
NETMASK=255.255.255.0
ONBOOT=yes

Note:    You can also specify “GATEWAY=10.0.0.1” in the /etc/sysconfig/network configuration file.

Step 3.  To keep backup of old interface configurations

#mv ifcfg-eth0 OLD.ifcfg-eth0
#mv ifcfg-eth1 OLD.ifcfg-eth1

Step 4.  To create the interface configurations

# vi ifcfg-eth0
DEVICE=eth0
MASTER=bond0
SLAVE=yes
ONBOOT=yes

# vi ifcfg-eth1
DEVICE=eth1
MASTER=bond0
SLAVE=yes
ONBOOT=yes

Step 5.  To add the bonding configuration in /etc/modprobe.conf file

# vi /etc/modprobe.conf
alias bond0 bonding
options bond0 miimon=100 mode=1

Note:    1.     mode=1 is for HA failover.
2.       mode=0 is for load balancing (teaming)
3.       miimon=100 means the link is going to be checked every 100 milliseconds

Step 6.  To restart the network

# service network restart
Shutting down interface eth0:  /etc/sysconfig/network-scripts/ifdown-eth: line 91: /sys/class/net/bond0/bonding/slaves: No such file or directory                                 [  OK  ]
Shutting down interface eth1:  /etc/sysconfig/network-scripts/ifdown-eth: line 91: /sys/class/net/bond0/bonding/slaves: No such file or directory                                 [  OK  ]
Shutting down loopback interface:                                                                                                          [  OK  ]
Bringing up loopback interface:                                                                                                 [  OK  ]
Bringing up interface bond0:                                                                                                       [  OK  ]

Note:  bonding module is loaded automatically, just like any other network interface module

Step 7.  To check loaded module

# lsmod | grep bond
bonding               126649  0

Step 8.  To check other network parameters

# modinfo bonding
filename:       /lib/modules/2.6.18-164.el5/kernel/drivers/net/bonding/bonding.ko
:
parm:           max_bonds:Max number of bonded devices (int)
:

Step 9.  To check logs

# tail -F /var/log/messages
Aug 17 11:36:25 airafr1 kernel: ADDRCONF(NETDEV_CHANGE): bond0: link becomes ready
Aug 17 11:36:25 airafr1 kernel: bonding: bond0: Adding slave eth1.
Aug 17 11:36:25 airafr1 kernel: e1000: eth1: e1000_watchdog_task: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
Aug 17 11:36:25 airafr1 kernel: bonding: bond0: enslaving eth1 as a backup interface with an up link.
Aug 17 11:36:27 airafr1 avahi-daemon[3120]: New relevant interface bond0.IPv6 for mDNS.
Aug 17 11:36:27 airafr1 avahi-daemon[3120]: Joining mDNS multicast group on interface bond0.IPv6 with address fe80::20c:29ff:fe7d:12d0.
Aug 17 11:36:27 airafr1 avahi-daemon[3120]: Registering new address record for fe80::20c:29ff:fe7d:12d0 on bond0.
Aug 17 11:36:29 airafr1 avahi-daemon[3120]: New relevant interface bond0.IPv4 for mDNS.
Aug 17 11:36:29 airafr1 avahi-daemon[3120]: Joining mDNS multicast group on interface bond0.IPv4 with address 10.0.0.101.
Aug 17 11:36:29 airafr1 avahi-daemon[3120]: Registering new address record for 10.0.0.101 on bond0.

Step 10.                To check bond status

# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:7d:12:d0

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:7d:12:da

Step 11.                To check bond status after eth0 become down

# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)

Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth1
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: down
Link Failure Count: 1
Permanent HW addr: 00:0c:29:7d:12:d0

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:0c:29:7d:12:da

No comments:

Post a Comment