Search:  
Gentoo Wiki

HOWTO_Setup_Bonded_ethernet_adapters


This article is part of the HOWTO series.
Installation Kernel & Hardware Networks Portage Software System X Server Gaming Non-x86 Emulators Misc

Contents

Introduction

This HowTo will show you how to bond multiple ethernet adaptors in one box so that if one card or connection fails or is disconnected you still have network connectivity.

Alternatively, you can create a bridged interface, which would allow you to plug one Ethernet connection into one switch and the other Ethernet connection into a separate switch. See Bridging for more details.

Kernel Configuration

First enable the bonding driver as a module in the kernel.

$ cd /usr/src/linux
$ make menuconfig
  Device Driver => Network device support => <M> Bonding driver support
$ make && make modules_install

Module Insertion

Note: See Documentation/networking/bonding.txt for other modes/options.

More configuration options here Possible values for mode are: 0 (round robin policy, default) and 1 (active backup policy), and 2 (XOR). Increase max_bonds if you'd like to create more than one bond interface. There are many others, so it's best to familiarize yourself before proceeding.

Base Layout 1

Add the following line to the modules.autoload.d file to load the drivers on boot

File: /etc/modules.autoload.d/kernel-2.6
 
  bonding miimon=100 mode=1
  

Base Layout 2

Add the following lines to modules to load the drivers on boot

File: /etc/conf.d/modules
 
  modules_2_6="${modules_2_6} bonding"
  module_bonding_args_2_6="miimon=100 mode=1"
  

Network Configuration

Network Configuration (Older)

Note: This is only necessary if you are using an older version of Gentoo. The latest net scripts support bonding and will call ifenslave for you. See next section.

Could someone provide a link for these new scripts as a fresh 2006.0 install with everything up to date still has the old init scripts :-(

Now we have to edit the /etc/conf.d/net file to initialize the bonded interface

Be sure you replace the <vars> below with your address information.

File: /etc/conf.d/net
 
   #(Do not add entries for eth0 or eth1)
   iface_bond0="<ip_address> netmask <ip_netmask> broadcast <ip_broadcast>"
  

Create an init.d link to an existing net script for the new bond interface

$ ln -sf /etc/init.d/net.eth0 /etc/init.d/net.bond0

Add the following line to /etc/conf.d/local.start, to bond the interfaces


File: /etc/conf.d/local.start
  
   ifenslave bond0 eth0 eth1
  

Remove the existing interfaces from rc-update

$ rc-update del net.eth0; rc-update del net.eth1

Add the bond interface to rc-update

$ rc-update add net.bond0 default

Network Configuration (Newer)

You need the followiing package

emerge net-misc/ifenslave

Editing the Network Configuration File

Base Layout 1

Now we have to edit the /etc/conf.d/net file to initialize the bonded interface - worked for me with baselayout-1.12.9 -

Be sure you replace the <vars> below with your address information.

File: /etc/conf.d/net
 
   #(Do not add entries for eth0 or eth1)   

   #Following the above advice lets the Network cards scan for an dhcp server when booting (baselayout-1.12.9), i had to add: 
   config_eth0=( "null" )
   config_eth1=( "null" )

   slaves_bond0="eth0 eth1"

   config_bond0=( "<ip_address> netmask <ip_netmask> brd <ip_broadcast>" )

   #Configure Default Gateway (optional)
   routes_bond0=( "default gw <gw_ip_address>" )
  
Base Layout 2

Be sure you replace the <vars> below with your address information. Note the lack of parenthesis as baselayout-2 discards the use of bash like array expressions.

File: /etc/conf.d/net
 
   config_bond0="<ip_address> netmask <ip_netmask>"
   slaves_bond0="eth0 eth1"
   
   #Configure Default Gateway (optional)
   routes_bond0="default gw <gw_ip_address>"
  

For multiple bonds, simply duplicate the above configuration using bond1, bond2, etc and define the slave interfaces for each bond. Be sure to increase "max_bonds" in /etc/conf.d/modules to the number of bonds you create.

Adding RC Scripts

Create an init.d link to an existing net script for the new bond interface, again, repeat for multiple bond interfaces.

$ ln -sf /etc/init.d/net.lo /etc/init.d/net.bond0

Remove the existing interfaces from rc-update

Note: After a reboot my Wireless Interface (configured in /etc/conf.d/wireless) came up but didn't authenticate, i had to keep it.

$ rc-update del net.eth0; rc-update del net.eth1


Add the bond interface to rc-update

$ rc-update add net.bond0 default

Network Configuration (Newer) without modules enabled in kernel

If you prefer monolithic kernel, you have to edit the /etc/conf.d/net file to initialize the bonded interface as above, but you have to insert a preup() function, which runs before the bond0 is up and gives some informative output:

Note: Please test this! It works for me pretty well, however most docs state that bonding works only if you load it as a module.


File: /etc/conf.d/net
 
  preup() {
        # Adjusting the bonding mode / MII monitor
        # Possible modes are : 0, 1, 2, 3, 4, 5, 6,
        #     OR
        #   balance-rr, active-backup, balance-xor, broadcast,
        #   802.3ad, balance-tlb, balance-alb

        # MII monitor time interval typically: 100 milliseconds

        if [[ ${IFACE} == "bond0" ]] ; then
                BOND_MODE="balance-alb"
                BOND_MIIMON="100"
                echo ${BOND_MODE} >/sys/class/net/bond0/bonding/mode
                echo ${BOND_MIIMON}  >/sys/class/net/bond0/bonding/miimon
                einfo "Bonding mode is set to ${BOND_MODE} on ${IFACE}"
                einfo "MII monitor interval is set to ${BOND_MIIMON} ms on ${IFACE}"
        else
                einfo "Doing nothing on ${IFACE}"
        fi
        return 0
   }
   #(Do not add entries for eth0 or eth1)
   slaves_bond0="eth0 eth1"

   config_bond0=( "<ip_address> netmask <ip_netmask> brd <ip_broadcast>" )

   #Configure Default Gateway (optional)
   routes_bond0=( "default gw <gw_ip_address>" )
  

Compile the ifenslave executable

# emerge ifenslave

Preliminary Testing

Load the bonding module and start up the interface

$ modprobe bonding; 

Stop the existing interfaces

$ /etc/init.d/net.eth0 stop
$ /etc/init.d/net.eth1 stop

Start the bonded interface

$/etc/init.d/net.bond0 start 
$/etc/init.d/local restart


Checking that the interface is up

$ ifconfig

(output should look something like this:)

Code: ifconfig output
 
 bond0  Link encap:Ethernet  HWaddr 00:00:00:00:00:00
        inet addr:<ip_address>  Bcast:<ip_broadcast>  Mask:<ip_netmask>
        UP BROADCAST RUNNING MASTER MULTICAST  MTU:1500  Metric:1
        RX packets:11573 errors:0 dropped:0 overruns:0 frame:0
        TX packets:5082 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:0
        RX bytes:962442 (939.8 Kb)  TX bytes:516064 (503.9 Kb)
 
 eth0	Link encap:Ethernet  HWaddr 00:00:00:00:00:00
        UP BROADCAST RUNNING NOARP SLAVE MULTICAST  MTU:1500  Metric:1
        RX packets:2706 errors:0 dropped:0 overruns:0 frame:0
        TX packets:32 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:1000
        RX bytes:175590 (171.4 Kb)  TX bytes:3150 (3.0 Kb)
        Interrupt:28
 
 eth1	Link encap:Ethernet  HWaddr 00:00:00:00:00:00
        UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
        RX packets:8867 errors:0 dropped:0 overruns:0 frame:0
        TX packets:5050 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:1000
        RX bytes:786852 (768.4 Kb)  TX bytes:512914 (500.8 Kb)
        Interrupt:29
 
 Lo	Link encap:Local Loopback
        inet addr:127.0.0.1  Mask:255.0.0.0
        UP LOOPBACK RUNNING  MTU:16436  Metric:1
        RX packets:0 errors:0 dropped:0 overruns:0 frame:0
        TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:0
        RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
  

Documentation/README

For some further detailed information on bonding with an explainantion of the different modes/module options see:

Retrieved from "http://www.gentoo-wiki.info/HOWTO_Setup_Bonded_ethernet_adapters"

Last modified: Sat, 30 Aug 2008 08:21:00 +0000 Hits: 29,826