Home Linux How to Enable and Configure Network Bonding in Linux: A Step-by-Step Guide.

How to Enable and Configure Network Bonding in Linux: A Step-by-Step Guide.

by Ashila Antony
Linux logo with code

Network bonding is a method used to combine multiple network interfaces into a single virtual interface, often to provide redundancy, improve network throughput, or load balance traffic across multiple interfaces. This technology is particularly useful in high-availability systems or environments that require higher network performance. In Linux, network bonding is implemented through the bonding kernel module, which allows multiple physical network interfaces to appear as a single logical interface.

This guide explains how to enable and configure network bonding on a Linux system. The steps include loading the bonding module, creating a bonded interface, and configuring bonding options based on the network requirements.

1. Prerequisites

Before configuring network bonding, you need to ensure that:

  • The Linux system has multiple network interfaces (e.g., eth0, eth1).
  • You have administrative (root) privileges to configure network settings.
  • The bonding kernel module is available on the system.

2. Understanding Bonding Modes

Linux supports several bonding modes, each providing different behaviors for redundancy, load balancing, or fault tolerance. The following are the most common modes:

  1. Mode 0 (Round-robin):
    • Provides load balancing by transmitting packets in a round-robin manner across all interfaces.
    • It requires support from the switch for load balancing.
  2. Mode 1 (Active-backup):
    • One interface is active at a time, while others are in backup mode.
    • Provides fault tolerance (if the active interface fails, a backup interface is activated).
  3. Mode 2 (XOR):
    • Load balancing based on the XOR of the MAC address, ensuring that the traffic is balanced across the interfaces.
  4. Mode 3 (Broadcast):
    • Sends all packets to both interfaces, ensuring redundancy.
    • Primarily used for high availability.
  5. Mode 4 (IEEE 802.3ad – Dynamic Link Aggregation):
    • Implements Link Aggregation Control Protocol (LACP) to dynamically create aggregated links.
    • Requires switch support for LACP.
  6. Mode 5 (Adaptive Load Balancing):
    • Provides load balancing and fault tolerance, using ARP monitoring to dynamically assign traffic to the most optimal interface.
  7. Mode 6 (Balance-alb):
    • Adaptive load balancing that dynamically assigns packets to different interfaces based on current traffic patterns.
    • No switch support is needed, unlike LACP.

3. Installing the Bonding Module

In most modern Linux distributions, the bonding module is pre-installed in the kernel. However, you might need to load it manually if it is not loaded by default.

To load the bonding module, run the following command:

sudo modprobe bonding

To ensure the bonding module is loaded after a reboot, you can add it to the /etc/modules file:

echo “bonding” | sudo tee -a /etc/modules

4. Creating a Bonded Interface

a) Identifying Network Interfaces

Before creating a bonded interface, you need to identify the physical network interfaces you want to bond. Use the ip or ifconfig command to list all available network interfaces.

ip link show

For example, suppose you have two interfaces, eth0 and eth1, which you want to bond.

b) Configuring the Bonding Interface

You need to configure the bond interface (e.g., bond0) by creating a configuration file or using network management tools.

Using Network Configuration Files (Traditional Method)

For distributions like CentOS, RHEL, or Fedora, network interfaces are often configured in /etc/sysconfig/network-scripts/ for older versions. In newer systems using NetworkManager or netplan, the configuration will differ.

Create Bonded Interface Configuration:

First, create a bonding configuration file for the new bonded interface, e.g., /etc/sysconfig/network-scripts/ifcfg-bond0.

Example configuration file for bond0 (mode 1, active-backup):

DEVICE=bond0

NAME=bond0

BONDING_MASTER=yes

BOOTPROTO=static

IPADDR=192.168.1.100

NETMASK=255.255.255.0

GATEWAY=192.168.1.1

ONBOOT=yes

BONDING_OPTS=”mode=1 miimon=100 primary=eth0″

  • DEVICE: Name of the bond interface (bond0).
  • BONDING_OPTS: Options for bonding. Here, mode=1 is active-backup, miimon=100 specifies a monitoring interval of 100 ms, and primary=eth0 designates eth0 as the primary interface.

Configure the Physical Interfaces:

Next, configure the physical interfaces (eth0 and eth1) by creating files such as /etc/sysconfig/network-scripts/ifcfg-eth0 and /etc/sysconfig/network-scripts/ifcfg-eth1. These files should contain the following configurations:

Example for eth0:

DEVICE=eth0

NAME=eth0

MASTER=bond0

SLAVE=yes

ONBOOT=yes

 Similarly, configure eth1 in the same manner.

Restart Network Service:

After configuring the bonded interface and the physical interfaces, restart the network service to apply the changes:

sudo systemctl restart network

Using netplan (Modern Systems)

On systems using netplan (Ubuntu 18.04 and later), you will configure the bonding in the /etc/netplan/ directory.

Create the Bonded Interface:

Open or create a .yaml configuration file in /etc/netplan/, such as /etc/netplan/01-bonding.yaml.

Example configuration for bond0:

network:

  version: 2

  renderer: networkd

  ethernets:

    eth0: {}

    eth1: {}

  bonds:

    bond0:

      interfaces: [eth0, eth1]

      parameters:

        mode: active-backup

        primary: eth0

        mii-monitor-interval: 100

      dhcp4: false

      addresses:

        – 192.168.1.100/24

      gateway4: 192.168.1.1

Apply the Configuration:

Apply the netplan configuration by running:

sudo netplan apply

5. Testing the Bonding Configuration

After configuring network bonding, it’s crucial to verify that the bonded interface is working as expected. Use the following commands to check:

Check the bond interface status:

cat /proc/net/bonding/bond0

  •  This will provide detailed information about the bonding status, including active interfaces, the bonding mode, and link status.
  • Test failover by disconnecting one of the physical interfaces and checking if the network continues to function without interruption.
  • Run ping or other network diagnostic tools to ensure the network is reachable.

Conclusion

Network bonding in Linux provides several options for improving network performance and redundancy. By combining multiple network interfaces into a single logical interface, bonding can ensure higher availability and better throughput. The configuration process can be done through traditional network-scripts or modern methods like netplan, depending on the Linux distribution.

By understanding bonding modes and choosing the appropriate configuration for your network’s needs, you can improve the reliability and efficiency of your system’s network connectivity.

Leave a Comment