Create NIC Channel Bonding in RedHat/CentOS/Fedora
Channel Bonding enables two or more network interfaces to act as one, simultaneously increasing the bandwidth and providing redundancy. This is a great way of achieving redundancy to a server. If one physical NIC is down or unplugged, it will automatically move resource to other NIC card. Channel bonding will work with the help of bonding driver in kernel. This post guides you through how to create NIC / Channel Bonding in RedHat, CentOS and Fedora Linux.
Step 1: Creating Bonding Channel
As a root, create a new file name bonding.conf in the /etc/modprobe.d/ directory. Name can be anything you like as long as it ends with a .conf extension. Insert the following line in this new file.
alias bond0 bonding
For each configured channel bonding interface, there must be a corresponding entry in your new /etc/modprobe.d/bonding.conf file.
Step 2: Creating Channle Bonding Interface
To create a channel bonding interface, create a file in the /etc/sysconfig/network-scripts/ directory called ifcfg-bond0. The following is a sample channel bonding configuration file. (Note : IP Address may differ in your environment.)
# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0 IPADDR=192.168.1.8 NETMASK=255.255.255.0 ONBOOT=yes BOOTPROTO=none USERCTL=no
Step 3: Configuring Channel Bonding Interface
After the channel bonding interface is created, the network interfaces to be bound together must be configured by adding the MASTER and SLAVE directives to their configuration files. The configuration files for each of the channel-bonded interfaces can be nearly identical. For example, if two Ethernet interfaces are being channel bonded, both eth0 and eth1 may look like the following example. Edit physical interface card details as under.
For eth0
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 USERCTL=no ONBOOT=yes MASTER=bond0 SLAVE=yes BOOTPROTO=none
For eth1
# vi /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1 USERCTL=no ONBOOT=yes MASTER=bond0 SLAVE=yes BOOTPROTO=none
The above directives are self explanatory for many system admin, however, let me explain to newbie.
- DEVICE: Indicates what is the device name
- USERCTL: Indicates that can user control this device(here its no)
- ONBOOT: Indicates that at the boot time do this device should be up?
- MASTER: Is this device has master? Then what it is(here its bond0)
- SLAVE: Is this device acting as slave?
- BOOTPROTO: What about getting IP Address from DHCP? It’s set to none which indicate it’s a static IP)
Step 4: Restarting Network Service
Restart the network service and see the output of ifconfig.
# service network restart
[[email protected] network-scripts]# ifconfig bond0 Link encap:Ethernet HWaddr 00:0C:21:60:30:C4 inet addr:192.168.1.8 Bcast:172.16.1.255 Mask:255.255.255.0 inet6 addr: fe80::20c:29ff:fe69:31c4/64 Scope:Link UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1 RX packets:19676 errors:0 dropped:0 overruns:0 frame:0 TX packets:342 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1623240 (1.5 MiB) TX bytes:42250 (41.2 KiB) eth0 Link encap:Ethernet HWaddr 00:0C:21:60:30:C4 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:10057 errors:0 dropped:0 overruns:0 frame:0 TX packets:171 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:832257 (812.7 KiB) TX bytes:22751 (22.2 KiB) Interrupt:19 Base address:0x2000 eth1 Link encap:Ethernet HWaddr 00:0C:21:60:30:C4 UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1 RX packets:9620 errors:0 dropped:0 overruns:0 frame:0 TX packets:173 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:791043 (772.5 KiB) TX bytes:20207 (19.7 KiB) Interrupt:19 Base address:0x2080 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:2 errors:0 dropped:0 overruns:0 frame:0 TX packets:2 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:104 (104.0 b) TX bytes:104 (104.0 b)
Network Manager in my experience needs to be off.
Flag is NM_CONTROLLED=”no” on each interface
Another useful flag in Bonding is selecting which interface is going to be the primary. This is useful if you have two switches and you want to have preference which switch the traffic goes over.
BONDING_OPTS=”mode=1 miimon=100 primary=em1″
primary=em1 means that it will always have em1 interface (Sorry Dell Server, EM1 is also considered eth0) if you lose this link which I have tested by pulling the cable. You lose two pings and em2 or eth1 whichever you are using takes over the load. When you plug the cable back in it will drop 2 pings and switch back to EM1 or eth0
networkmanager is running, and I create my bond at boot in /etc/rc.local
If the secondary slave is marked for DHCP, it will spontaneously leave your bond0 interface. Check the mac addresses of your slaves with ifconfig, if they don’t match, there’s a problem.
Killing networkmanager may also work. Seriously RedHat, straighten out your networking stack.
Hi,
That’s Excellent.
But for above NIC bonding could you please put the details of eth0 and eth1 before bonding.
Novice to the Linux world and ether channel bonding!!
Thanks
Hi All,
Can anyone tell me how to manually test the failover without bringing down the master interfaces
ifenslave -c bond0 eth1
this will change the active slave to eth1 without bringing down the master. if eth1 is of couse configured as the second slave.
or to manually failover
sudo ifconfig eth0 down
the bond will failover to eth1
sudo ifconfig eth0 up
sudo ifconfig eth1 down
the bond will fail back over to eth0
sudo ifconfig eth1 up
Sorry but shouldnt the entry for eth1 read “/etc/sysconfig/network-scripts/ifcfg-eth1”? (above it reads “eth0”). Could confuse some people. ;)
Please also mention mode of bonding.
I had the hwaddr commented out for each interface in the bond. Once I removed the comment and updated the driver it worked. Lesson learned.
I am running Oracle Linux 5.7 (Red Hat based) and have configured bonding. I can activate the bond manually once the host is up but the bonded interfaces do not exist on reboot and the bond fails. Any ideas?
add commands in /etc/rc.local file to load at boot time.
@joe: pl. share your bond interface as well as physical interface details
I’ve set up channel bonding following these steps on CentOS 6.3 bonding eth1 and eth2. The device seems to bond okay, but once bonded, the network traffic just stops. No ping, no nothing. Any clues?
These are both ports on a Syba dual port gigabit adapter (Realtek chipset).
Estou com o mesmo problema.
Look up policy based routing
I’ve been agonizing with this also for a while.
NetworkManager service is mucking it up. stop it and I bet all your pings become consistent.
to stop it:
#service NetworkManager stop
to kill it on boot up:
#chkconfig –level 2345 NetworkManager off
Excellent how to. However, the ifcfg-bond0 needs the line defining the default gateway.
as in:
GATEWAY=192.168.1.1
Otherwise you will not be able to get off that subnet.