How To Simple Linux Bonding



  • Written in January, 2008: Simple Linux Bonding

    Bonding or channel aggregation is a means by which multiple Ethernet connections can be used as a single connection with a single IP Address. This is very handy both for performance but also for failure protection. Bonding is accomplished using the Linux Bonding Driver.

    This How To will address basic bonding on the Red Hat and SUSE platforms. This is actually very easy. Be aware, however, that if you are connected to a machine remotely over the network that making changes to your networking configuration could cause you to lose your connection. You have been warned.

    The first step is to add the Linux Bonding Driver to the modules list. Depending on the version of Linux that you are using this will either be /etc/modules.conf (Red Hat 3 or older) or /etc/modprobe.conf (Red Hat 4 or newer.) You will need to add an alias to the bonding driver. It is traditional to call the first bonded driver instance bond0 which is what we will do here. Add the following line to your /etc/modprobe.conf file:

    alias bond0 bonding 
    

    To make configurations to this driver you will need to add another line. In our example we are going to use the very simple “Mode 6” bonding method. (Learn about Linux Bonding Modes.) This type of bonding requires no support from your switch which makes it very easy to use. I prefer mode 6 because it accomplishes bidirectional load balancing without any switch configuration. This is a more general purpose type of bonding than most of the other forms. All configuration is taken care of at the server. Add the following line also to /etc/modprobe.conf:

    options bond0 miimon=100 mode=6 downdelay=200 updelay=200
    

    This is a good, general purpose set of options for bonding. It is a good place to start. Once you are comfortable with bonding you can tweak it as is appropriate for your needs. Now we need to set up the configuration for the bond0 interface. The file that we will be creating/editing is /etc/sysconfig/network-scripts/ifcfg-bond0:

    DEVICE=bond0
    IPADDR=192.168.0.2
    NETWORK=192.168.0.0
    NETMASK=255.255.255.0
    BROADCAST=192.168.0.255
    ONBOOT=yes
    BOOTPROTO=none
    USERCTL=no
    

    We will break this down for you. IPADDR is your IP address. This is a generic example. You have to put in your own IP address for this particular Linux host here. NETWORK is the network address of your network. This is not always needed but good to have. If you don’t know your network address it is most likely your IP address but ending with the final octet in zero (in cases when your subnet mask is 255.255.255.0 or /24.) Your NETMASK is your subnet mask. Commonly as shown here. BROADCAST is, again, network dependent but likely your IP address but with the final octet ending in 255 (again in /24 subnets.) ONBOOT should be “yes” unless you do not want the interface to start when the machine starts. BOOTPROTO is “none” unless you are using DHCP or BOOTP for this address which I expect that you are not as that is very uncommon for bonded interfaces. USERCTL is for “user control” and you can do what you like here. For security reasons I leave this as “no”.

    Finally some basic configurations of your regular Ethernet interfaces and you will be all set. Here is a sample of /etc/sysconfig/network-scripts/ifcfg-eth0:

    DEVICE=eth0
    BOOTPROTO=none
    ONBOOT=yes
    TYPE=Ethernet
    SLAVE=yes
    MASTER=bond0
    

    This is even simpler than the bond0 configuration file. Here we specify the DEVICE name (eth1, eth2, etc. to suit your needs), BOOTPROTO is “none”, ONBOOT should be the same as for bond0. Type as appropriate but almost always “Ethernet”. The most important bits of the file are SLAVE which must be “yes” and MASTER which must be the DEVICE name that you are enslaving to.

    At this point your bonded interface is configured. You can now restart your networking to test it out.

    /etc/init.d/network restart