Monday, December 24, 2007

Centos 5 - Linux Bonding - mode5

Linux bonding is a tool use to combine 2 or more Ethernet cards together to make more bandwidth available.

For example, your server have 1 pcs of 100Mbits NIC, it is only can perform 100Mbits transmit/receive. Say, your server is ftp server for internal usage, there is more than a thousand of internal users use it everyday and 100Mbits is always not enough to serve them. There is 2 solutions, 1st, purchase an 1Gbits NIC card ( with gigabit switch) but that will be costly. 2nd, add-on another 100Mbit NIC and bond the 1st and 2nd NIC together, so that you will have 200Mbit bandwidth available for internal users

Assume you have 2 NIC in your centos5 now, which is eth0 and eth1
#vi /etc/modprobe.conf
remove the line of eth0 and eth1
and then add the line to /etc/modprobe.conf
alias bond0 bonding
options bond0 miimon=100 mode=5

Here i choose the mode=5 cause i just need load balancing on transmitting but not receiving. There is few modes available, read carefully before you implement.

go to /etc/sysconfig/network-script
create ifcfg-bond0 and input the follow content
#touch ifcfg-bond0
DEVICE=bond0
IPADDR=
NETMASK=
NETWORK=
BOARDCAST=
GATEWAY=
ONBOOT=yes
BOOTPROTO=dhcp
USERCTL=no

i use dhcp because i got dhcp server with the address bond to the mac address automatically. So not much configuration at here. If u use static IP address, just modify the IPADDR, NETMASK, BOARDCAST and etc.

modify the eth0 and eth1
#vi /etc/sysconfig/network-script/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
USERCTL=no
MASTER=bond0
SLAVE=yes

do the above config on ifcfg-eth1 but device must be eth1. If your current config have mac address, just leave it here. It will not effect the system.

restart the network service
#/etc/init.d/network restart

you will see the messages like this Determining IP information for bond0 with OK status.
mean that everything work fine.

do ifconfig and see,
#ifconfig -a
you will see the bond0, eth0 and eth1 have same mac address, actually they all bonded with mac address from eth0.

check your log and see you will see the bonding messages
#tail -n 30 /var/log/messsages
....................................
bonding:bond0: Adding slave eth0
eth0: link up
..................................
bonding:bond0: Adding slave eth1
eth1: link up
..................................
you will see the message some sort like above, mean that both ethernet card has been bonded with the bond0 interface.