Simple way to achieve network redundancy in Linux

Martynas Sklizmantas,

2008 May 05,

Linux, Technology

2

Just today a collegue has asked about network bonding, which is sometimes called port trunking in Linux operating system, specifically:

  • What it is?
  • How does it work?
  • How to enable it?

I will try to explain it in simple way and in the end you will be able to configure your Linux machine to have network redundancy and higher bandwidth.

What it is?

Network bonding is simple way to have redundant network connection if one of network cards fail, by combining several cards into one. Also it can help to have more bandwidth if one network card is not able to cope with high volume of traffic. In short: it provides you some level of protection of network gear failure (network card or switch to which network card is connected) and more traffic without huge efforts.

How it works?

There are several modes in with network bonding can operate: round robin, active backup, transmit based on destination address, broadcast, dynamic link aggregation, adaptive transmit load balancing, adaptive load balancing. For some of these modes you need to have a switch (or other networking device) which supports such features and for other don’t. For the purpuse of demonstration we will look only into first mode - round robin, which sends packets via each network card (called slave in bonding terminology). This mode provides fault taulerance and load balancing and does not require specific switch configuration.

How to enable it?

First you need to configure ports of the switch to have the same configuration and put as many network cards to the server as you want. For the purpose of demonstration we will put two cards, which usually are enough for general needs. If you require to bond more network cards (and to have multiple bonded interfaces) - leave a comment and I will get back to you with details on how to achieve it.

Step by step instructions on how to enable bonding on Linux Red Hat machine, which has two network cards (interfaces) and the purpose is to have one virtual interface. Let’s assume that we have two network interfaces in our machine - eth0, eth1 and here we go:

  1. Make sure that system will load bonding modules on startup. For this you need to add this line into /etc/modules.conf: alias bond0 bonding options bonding miimon=100 mode=0.
  2. Configure network interfaces to operate in slave mode: edit or create /etc/sysconfig/network-scripts/ifcfg-eth0 and /etc/sysconfig/network-scripts/ifcfg-eth1 files to contain such lines:
    DEVICE=ethX
    USERCTL=no
    ONBOOT=yes
    MASTER=bond0
    SLAVE=yes
    BOOTPROTO=none
    Be sure to replace ethX with correct number! (either 0 or 1, depending on the interface).
  3. Edit or create /etc/sysconfig/network-scripts/ifcfg-bond0 to contain following information: DEVICE=bond0
    USERCTL=no
    ONBOOT=yes
    BROADCAST=192.168.0.255
    NETWORK=192.168.0.0
    NETMASK=255.255.255.0
    GATEWAY=192.168.0.254
    IPADDR=192.168.0.1
    Replace ip addresses and other network information as needed.
  4. Reboot the system to bring bonded network interface up (It can be done without reboot, but it is always recommended to do so, to be sure, that everything will be working fine after unexpected shutdown).
  5. Check if you have network connection and bond0 interface is up: ifconfig bond0. Also you can check status information by looking at /proc/net/bonding/bond0.

Enjoy fault taulerance and load balancing on your Linux machine.

Share, bookmark this article

Digg Del.icio.us Reddit Blinklist Ma.Gnolia StumbleUpon Furl Simpy Google Yahoo Spurl Blinkbits Technorati Newsvine Netvouz Slashdot Netscape

Comments

HI, I have a question. This only works when a NIC goes down only? or is there a way to make it works also when one of the ISP lost link?

hello,

this only works when a NIC (or switch if used two separate switches for separate NICs) goes down. In theory it might be possible to make it work when ISP loses link, but it requires that multiple ISPs would agree togother and implement such network configurtion on their side, so I am not sure if anyone is doing it.

before going further I would like to ask a question:

do you want to achieve redundancy for incomming traffic or outgoing? (ie - you have webserver, which has to be served or office lan, where you would like to use multiple ISPs just in case)

regards,

m

Have any comments?

© 2007-2008 XorBin