Header Shadow Image


Configuring Linux Bonding: bond0 using eth0 eth1 and wlan0

This is a simple howto tutorial for creating and bonding three interfaces, a wireless one (wlan0), one RealTek based GIGe cabled NIC (eth0) and another alternate Intel based GIGe NIC (eth1).  This is partially a conceptual howto since a home HTPC / Backup center probably doesn't need three separate NIC's for redundancy.  However, with recent ventures into the world of GIGe ethernet and associated issues, it does add some merit to this initiative.  The wireless NIC card (wlan0) is thrown here just to add another level of redundancy: a wireless one.

Here are the steps to configuring bonding on RHEL / SL Linux:

Step Step Name Command / Results
1 Plug in your network cards that will be participating in the bonding.

The results should look similar to this from the OS side:

# (lspci && lsusb)|grep -Ei "Gigabit|Comm"
04:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 03)
05:06.0 Ethernet controller: Intel Corporation 82541PI Gigabit Ethernet Controller (rev 05)
Bus 008 Device 002: ID 0cf3:1002 Atheros Communications, Inc. TP-Link TL-WN821N v2 [Atheros AR9001U-(2)NG]
#

 

2 Once plugged in, find the MAC address of each card. To get the MAC address, provided you have not yet configured bonding, by simply issuing ifconfig -a or netstat -ie.  Please see here for alternate ways of finding the MAC.
3 Define your interfaces.

To do so, we'll need to create a number of files under /etc/sysconfig/network-scripts:

# cat ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
NM_CONTROLLED=no
HWADDR=1C:6F:65:3F:FC:14

MASTER=bond0
SLAVE=yes

DNS1=192.168.0.1

# cat ifcfg-eth1
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
NM_CONTROLLED=no
HWADDR=90:e2:ba:1a:08:28

MASTER=bond0
SLAVE=yes

DNS1=192.168.0.1

# cat ifcfg-wlan0
DEVICE=wlan0
ONBOOT=yes
BOOTPROTO=none
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
NM_CONTROLLED=no
HWADDR=00:25:86:F1:65:D0

MASTER=bond0
SLAVE=yes

DNS1=192.168.0.1

# cat ifcfg-bond0
DEVICE=bond0
IPADDR=192.168.0.14
NETMASK=255.255.254.0
GATEWAY=192.168.0.1

ONBOOT=yes
BOOTPROTO=none
USERCTL=no
NM_CONTROLLED=no
DNS1=192.168.0.1
# pwd
/etc/sysconfig/network-scripts

The items in blue, green and bolded black being key here.  Notice, we only specify an IP for the bond0 interface, not the slaves.

4 Ensure the bonding module will load on startup.

Ensure the following line exists in the /etc/rc.local file:

# cat /etc/rc.local|grep bonding
/sbin/modprobe bonding;
echo 100 > /sys/class/net/bond0/bonding/miimon;
#

In addition, ensure the /etc/modprobe.d/modprobe.conf file is defined to load the bonding module including any customizations:

# cat /etc/modprobe.d/modprobe.conf
alias bond0 bonding
options bond0 -o bond0 mode=2 miimon=100 max_bonds=1
#

The bonding mode selected is 2 for active-backup configuration since we only want to use wlan0 for backup. (In case all connection with the server fails through eth0 and eth1)

 

(Optional)
Another means of implementing bonding is via these lines:

install bond0 /sbin/modprobe –ignore-install -o bonding0 bonding miimon=100 
remove bond0 /sbin/modprobe -r –ignore-remove bonding0 
install bond1 /sbin/modprobe –ignore-install -o bonding1 bonding miimon=100 
remove bond1 /sbin/modprobe -r –ignore-remove bonding1 

5

(Optional) It is recommended
to create some UDEV
rules to ensure the interface
cards always come back named the same way on subsequent reboots.

To do this, it is recommended to define some UDEV rules

# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x10ec:0x8168 (r8169)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="1c:6f:65:3f:fc:14", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# USB device 0x0cf3:0x1002 (usb) (custom name provided by external tool)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:25:86:f1:65:d0", ATTR{type}=="1", KERNEL=="wlan*", NAME="wlan0"

# PCI device 0x8086:0x107c (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="90:e2:ba:1a:08:28", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

#

This will ensure that the network card names per each ethernet adapter (as listed in lspci above) will always retain the same name.

6 Load the bonding module.

Check first that it isn't loaded, if it is, skip to the next step:

# lsmod|grep bonding
bonding               127806  0
8021q                  25941  1 bonding
ipv6                  322541  84 bonding,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6
#

If it isn't loaded, load it using:

# modprobe bonding

 

7 Restart the network.

Issue the following to restart your network:

# service network restart

to make the changes take effect.

And this completes our bonding tutorial.  Feel free to leave a reply on your bonding success story.  We'd love to hear from you.

Cheers,
TK

One Response to “Configuring Linux Bonding: bond0 using eth0 eth1 and wlan0”

  1. […] Linux Bonding […]

Leave a Reply

You must be logged in to post a comment.


     
  Copyright © 2003 - 2013 Tom Kacperski (microdevsys.com). All rights reserved.

Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License