NIC Bonding / Port Trunking with CentOS/RHEL

Hello,

with NIC Bonding or Port Trunking you can provide higher throughput and redundency to your network cards. Basically it bonds two, let's say 1Gb network cards, to one 2Gb card. Bonding can be achieved with more than 2 cards in a system.

There are several modes:

Mode 0 (round-robin – load balancing/fault tolerence):
This is the default mode and sends packets from the first to the last slave. 1st packet -> 1st NIC, 2nd packet -> 2nd NIC, 3rd packet -> 1st NIC etc…

Mode 1 (active backup – fault tolerence):
In this mode only 1 card/slave is active at the moment. Another takes over as soon as the other goes down. Only the MAC address of the bond is visible on the outside.

Mode 2 (balance-xor – load balancing/fault tolerence – Static Link Aggregation):
In this mode every destination gets the packets from the same source address based on MAC addresses.

Mode 3 (broadcast – fault tolerence):
In this mode all packets go out on every interface. Incoming traffic is not affected.

Mode 4 (802.3ad – Dynamic Link Aggregation, LACP):
In this mode there is a group created wth the same speed an duplex possibilities according to IEEE 802.3ad. There are some prerequisites fot this: Ethtool support in drivers to get speed and duplex of each slave and a switch which supports 802.3ad.

Mode 5 (balance-tlb – load balancing):
In this mode the outgoing packets are distributed over all slaves, but only the active slaves receives packets. If this goes down another slave takes over.

Mode 6 (balance-alb – load balancing):
In this mode all outgoing and incoming traffic in distributed over all salves.

Now after shortly explaining all modes here how to create such a bond:

  • add these lines to /etc/modprobe.conf:
    alias bond0 bonding
  • create and open the file /etc/sysconfig/network-scripts/ifcfg-bond0:
    DEVICE=bond0
    IPADDR=<ip address>
    NETMASK=<your netmask>
    NETWORK=<network>
    BROADCAST=<broadcast>
    GATEWAY=<gateway>
    ONBOOT=yes
    BOOTPROTO=none
    USERCTL=no
    BONDING_OPTS="mode=<your selected mode (0-6)> miimon=100"
  • then change your /etc/sysconfig/network-scripts/ifcfg-ethX files to:
    DEVICE=ethX
    ONBOOT=yes
    BOOTPROTO=none
    USERCTL=no
    MASTER=bond0
    SLAVE=yes

Now you should only need to restart your server. If you can't restart it please load the bond kernel module and restart your network:

# modprobe bonding
(ATTENTION: My host's connection froze here and i had to go to the physical server to restart the network)

# /etc/init.d/network restart