NIC Bonding On Slackware 12.1
I was standing in front of a problem while I built a NFS Storage Server. It is necessary for me to have redundancy in every point of view. I solved all redundancy issues I had by using server hardware with redundant power supplies, a Raid 1+ 0 Raid array and two UPS’s one for each power supply. The only thing left in my mind was what about a network failure? Well just use the two Gig NIC’s and hook each of them up to its own switch. Great idea but how do I get them acting as one unit speak one single IP? NIC Bonding was my solution. After a couple of hours researching on the Internet stumbled upon the build in solution by using ifenslave.
Here is how I did it:
In order to get fault tolerance we are going to bond the NICs. We need to compile a little program that will help us doing the bonding. Go to /usr/src/linux/Documentation/networking.
Type in:
gcc -Wall -O -I/usr/src/linux/include ifenslave.c -o ifenslave
and copy it over to /sbin by typing in:
cp ifenslave /sbin/ifenslave
Now change to the directory /etc/rc.d and create rc.bond.
Type
touch rc.bond
This will be the startup script for the bonding and needs to be executeable.
Type
chmod 755 rc.bond
Start vi by typing
vi rc.bond
and enter the following:
#!/bin/sh # case "$1" in 'start') echo "start bond0" #modprobe bonding mode=balance-alb miimon=100 modprobe bonding mode=balance-rr miimon=100 modprobe tg3 ifconfig bond0 up ifenslave bond0 eth0 ifenslave bond0 eth1 #TODO need to be changed ifconfig bond0 hw ether 00:16:3e:aa:aa:aa ;; 'stop') ifconfig bond0 down rmmod bonding rmmod tg3 ;; *) echo "Usage: $0 {start|stop}" ;; esac
To save the file hit <ESC> and type in :wq <enter>.
Now we need to make sure that this script gets started upon boot. Type in
vi rc.M
and scroll down to “#Initialize the networking hardware” and position the cursor in the line before that and hit “a” for insert. Type in the following:
# If script rc.bond is executeable then start it if [ -x /etc/rc.d/rc.bond ]; then . /etc/rc.d/rc.bond start fi
Hit <ESC> and type :wq <enter> to save and quit.
It is time to edit the last script. Type
vi rc.inet1.conf
and make sure the NICs have no static IPs assigned or configured for DHCP. It should look like this:
IPADDR[0]="" NETMASK[0]="" USE_DHCP[0]="" DHCP_HOSTNAME[4]="" IPADDR[1]="" NETMASK[1]="" USE_DHCP[1]="" DHCP_HOSTNAME[1]=""
And add these lines to it before the default gateway gets assigned:
IFNAME[4]="bond0" IPADDR[4]="XXX.XX.XX.XX" NETMASK[4]="255.255.255.0" USE_DHCP[4]="" DHCP_HOSTNAME[4]=""
Hit <ESC> and type :wq <enter> to write and quit. Reboot your system and after it’s back up login; type in:
cat /proc/net/bonding/bond0
and you should see something similar like this:
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:e0:81:5e:9e:c4
Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:e0:81:5e:9e:c5
If the link status is up and your system is responding on pings everything should be fine. You can also monitor the Link Status with
mii-tool –w
It gives you live status of the link.