NIC Bonding On Slackware 12.1

Want to support HowtoForge? Become a subscriber!
 
Submitted by mstjohn1974 (Contact Author) (Forums) on Tue, 2008-11-18 14:45. :: Linux | Other

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.


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by joeytrungale (registered user) on Sat, 2008-12-20 02:13.
copy and paste to bond_setup.sh, sh ./bond_setup.sh

<code>

#!/bin/bash

# Quick and dirty script to setup bonding on Slackware-12.2
# 12/20/2008 Joey Trungale <joey@trungale.net>

MODULE=e1000e
NIC0=eth1
NIC1=eth2

set -e

echo
echo "Compiling ifenslave..."
cd /usr/src/linux/Documentation/networking
gcc -Wall -O -I/usr/src/linux/include ifenslave.c -o ifenslave
strip ifenslave

echo "Installing ifenslave..."
cp ifenslave /sbin/ifenslave

echo "Creating rc.bond script..."
cd /etc/rc.d
touch rc.bond
chmod 755 rc.bond

cat <<EOF> rc.bond
#!/bin/sh

case "\$1" in
  'start')
    echo "start bond0"
    #modprobe bonding mode=balance-alb miimon=100
    modprobe bonding mode=balance-rr miimon=100
    modprobe $MODULE
    ifconfig bond0 up
    ifenslave bond0 $NIC0
    ifenslave bond0 $NIC1
    #TODO need to be changed
    #ifconfig bond0 hw ether 00:16:3e:aa:aa:aa
  ;;
  'stop')
    ifconfig bond0 down
    rmmod bonding
    rmmod $MODULE
  ;;
  *)
    echo "Usage: \$0 {start|stop}"
  ;;
esac
EOF

echo "Patching rc.M to start rc.bond on startup..."
patch -s -p0 rc.M <<EOF
--- rc.M    2008-12-20 08:37:48.000000000 -0600
+++ rc.M.new    2008-12-20 08:38:47.000000000 -0600
@@ -82,6 +82,11 @@
   fi
 fi
 
+# If script rc.bond is executable then start it
+if [ -x /etc/rc.d/rc.bond ]; then
+  . /etc/rc.d/rc.bond start
+fi
+
 # Initialize the networking hardware.
 if [ -x /etc/rc.d/rc.inet1 ]; then
   . /etc/rc.d/rc.inet1
EOF

cat <<EOF

Dont forget to add the following to /etc/rc.d/rc.inet1.conf:

IFNAME[4]="bond0"
IPADDR[4]="XXX.XX.XX.XX"
NETMASK[4]="255.255.255.0"
USE_DHCP[4]=""
DHCP_HOSTNAME[4]=""

Also, you may wish to choose a different method of bonding,
modify the 'mode=' option in rc.bond to one of the settings
from /usr/src/linux/Documentation/networking/bonding.txt.

Enjoy!
EOF
</code>

Submitted by Anonymous (not registered) on Wed, 2008-11-26 13:11.

     Ethernet bonding requires switch side configuration also in order to work as expected.

 

Submitted by HN (not registered) on Mon, 2008-12-01 02:46.

Not entirely true.

You can provide the "mode=<n>" parameter to the bonding module.

For most of the modes, you do not need any switch config, however if you select LACP mode (from memory, i think LACP is supported by the bond module), the switch connected to the NIC's obviously needs to support LACP.

HN

Submitted by Anonymous (not registered) on Thu, 2009-01-08 19:10.
 In order to make a "logical" interface to work properly, you need both sides (server,switch) to be configured accordingly. I dont say that there will be connectivity issues , but you WONT get twice the bw without "merging" the switch ports. 
Submitted by SoftBear (not registered) on Mon, 2010-03-01 23:49.

Interesting point, assuming bandwidth was the goal, this would be true, and would require a switch that supports bonding. 

 However, the stated purpose of THIS thread was painless redundancy. 

 I believe that goal is achieved without concern for what happens beyond the bounds of the target system. 

Submitted by AntiCMOS (not registered) on Fri, 2014-02-28 00:30.
Personally I think setting up anything other than LACP is foolish. If your going to bond a ether channel you might as well get the extra bandwidth with your redundancy.