Mikko Kortelainen

NIC bonding with Red Hat/CentOS

Here are simple instructions on how to configure network interface bonding on Red Hat based distros. The thing I always forget. There's also a little script which will create a bonding interface bond0 between eth0 and eth1 and migrate existing IP settings from eth0. You can find it in the bottom of this post.

But first here's how to do it by hand.

Configure bonding module and interface alias:

/etc/modprobe.conf:

alias bond0 bonding
options bond0 miimon=100 mode=1

Insert bonding module:

# modprobe bonding

Configure network interfaces, two physical and one bonding interface:

/etc/sysconfig/network-scripts/ifcfg-eth0:

DEVICE=eth0
BOOTPROTO=static
HWADDR=00:11:22:33:44:55
ONBOOT=yes
TYPE=Ethernet
SLAVE=yes
MASTER=bond0

/etc/sysconfig/network-scripts/ifcfg-eth1:

DEVICE=eth1
BOOTPROTO=static
HWADDR=00:11:22:33:44:56
ONBOOT=yes
TYPE=Ethernet
SLAVE=yes
MASTER=bond0

/etc/sysconfig-network-scripts/ifcfg-bond0:

DEVICE=bond0
BOOTPROTO=none
IPADDR=192.168.0.2
NETMASK=255.255.255.0
GATEWAY=192.168.0.1
ONBOOT=yes

Restart networking (your network connections will drop at this point):

# /etc/init.d/network restart

That's it!

Automatic Script

Here's the script I promised. It takes your existing IP settings from eth0 and migrates them to a newly created bond0 which is created between eth0 and eth1:

cat >>/etc/modprobe.conf <<EOF
alias bond0 bonding
options bond0 miimon=100 mode=1
EOF

cat >>/etc/sysconfig/network-scripts/ifcfg-bond0 <<EOF
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
EOF

cat /etc/sysconfig/network-scripts/ifcfg-eth0 | \
  egrep 'IPADDR|NETMASK|GATEWAY' >>/etc/sysconfig/network-scripts/ifcfg-bond0

HWADDR_ETH0="$(cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep HWADDR)"
HWADDR_ETH1="$(cat /etc/sysconfig/network-scripts/ifcfg-eth1 | grep HWADDR)"

cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
SLAVE=yes
MASTER=bond0
$HWADDR_ETH0
EOF

cat > /etc/sysconfig/network-scripts/ifcfg-eth1 <<EOF
DEVICE=eth1
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
SLAVE=yes
MASTER=bond0
$HWADDR_ETH1
EOF

More information can be found in the bonding.txt of the kernel source documentation.

http://www.netmite.com/android/mydroid/kernel/Documentation/networking/bonding.txt