Home Linux Networking Configuring Network Bonding In Linux For High Availability

Configuring Network Bonding In Linux For High Availability

A Step-by-Step Guide to Setting Up Network Bonding in Linux Using Netplan and nmcli.

By sk
13.4K views

Network bonding in Linux is a technique that allows you to combine multiple network interfaces (NICs) into a single logical interface for improved redundancy and performance. In this comprehensive guide, we'll explore the concept of network bonding, its benefits, different bonding modes, and network bonding configuration in Linux.

What is Network Bonding?

Network bonding, also known as NIC bonding or teaming, is a method of combining two or more network interfaces into a single logical interface called a bond.

The two important benefits of configuring network bonding in Linux:

  • Redundancy: Bonding provides failover capabilities, ensuring network connectivity even if one interface fails.
  • Load Balancing: It can distribute network traffic across bonded interfaces, improving overall network performance.

Bonding Modes

Linux supports several bonding modes, each designed to address specific use cases. Here are two of the most commonly used modes:

  1. Mode 0 (Round Robin): Sends packets in a round-robin fashion to each bonded interface.
  2. Mode 1 (Active-Backup): One interface is active, and the others are in standby mode. If the active interface fails, another takes over.

Let's take a quick look at these two modes.

1. Mode 0: Round Robin

In this mode, packets are transmitted in a round-robin fashion across the bonded interfaces. While it provides a basic form of load balancing, it doesn't take into account the actual load or status of each interface.

This mode is useful when you want to distribute traffic evenly across interfaces.

2. Mode 1: Active-Backup

Active-Backup mode designates one interface as the active link, while the others remain in standby mode. If the active interface fails, one of the standby interfaces takes over.

This mode is ideal for redundancy, ensuring that your network remains operational even if one NIC goes down.

Hope you got the basic understanding of Network bonding in Linux. Now let us see how to create a network bond interface using Netplan and nmcli command in Linux.

First, we will see the Netplan method.

Method 1 - Setting Up Network Bonding in Linux using Netplan

Creating network bonding using Netplan in Linux is a straightforward process. Netplan is a YAML-based network configuration utility used in modern Linux distributions like Ubuntu. To set up network bonding, follow these steps:

1. Check Network Interface Names

Before creating a Netplan configuration for network bonding, it's essential to identify the names of the network interfaces you want to bond.

You can use the ip link show or ifconfig commands to list the available network interfaces. Typically, these interfaces have names like enp0sX or, ensX or, ethX.

$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens18: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 6e:26:0b:8e:33:8c brd ff:ff:ff:ff:ff:ff
    altname enp0s18
3: ens19: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 96:d2:11:4a:6d:ad brd ff:ff:ff:ff:ff:ff
    altname enp0s19
4: ens20: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether ea:3a:8b:6c:38:e1 brd ff:ff:ff:ff:ff:ff
    altname enp0s20

As you can see, my system have three network interfaces namely ens18, ens19, and ens20.

2. Create a Netplan Configuration File

Create or edit a Netplan configuration file. Netplan configuration files are typically stored in the /etc/netplan/ directory and have a .yaml extension. You can use any text editor to create or edit the configuration file, such as nano or vim.

For example, create a file named 01-bond.yaml:

$ sudo nano /etc/netplan/01-bond.yaml

3. Configure the Bond Interface

In the Netplan configuration file, define the bond interface and its parameters. Here's a sample configuration for creating a bond with three interfaces (ens18, ens19 and ens34) in active-backup mode:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens18:
      dhcp4: no
    ens19:
      dhcp4: no
    ens20:
      dhcp4: no
  bonds:
    bond0:
      interfaces: [ens18, ens19, ens20]
      addresses: [192.168.1.10/24]
      routes:
        - to: 0.0.0.0/0
          via: 192.168.1.101
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
      parameters:
        mode: active-backup
        primary: ens18

Replace the interface names, IP address, subnet, gateway, and other parameters with your specific network configuration. You can use different bonding modes by changing the mode parameter (e.g., balance-rr for round-robin or 802.3ad for LACP).

4. Apply the Configuration

After creating or editing the Netplan configuration file, apply the changes using the netplan apply command:

$ sudo netplan apply

5. Verify the Configuration

Check the status of your bonded interface using the ip link or ifconfig commands. For example:

$ ip link show bond0

You should see the bonded interface (bond0) and its status.

6. Test Network Connectivity

Ensure that your server or workstation can access the network through the bonded interface. You can ping other devices on the network to verify connectivity.

We also have various methods to test if your bond interface section. Navigate to the "Testing Your Linux Network Bond Interface" section and use any one of the method to verify if the bond interface is working as expected.

That's it! You've successfully created a network bonding configuration using Netplan. Remember to adapt the configuration to your specific requirements, such as bonding mode, IP address, and gateway settings, to suit your network environment.

Method 2 - Configure Network Bonding in Linux using nmcli

To create network bonding using the nmcli command in Linux, you can follow these steps. nmcli is a command-line utility for managing NetworkManager, a network configuration tool commonly used in many Linux distributions.

1. Check Network Interface Names

Before creating a bonded interface using nmcli, you should identify the names of the network interfaces you want to bond.

You can use the ip link show or ifconfig commands to list the available network interfaces. The interfaces typically have names like ensX or enp0sX or ethX.

$ ip link show

Sample Output:

Check Network Interface Names
Check Network Interface Names

As you see in the above output, I have three network interfaces namely ens18, ens19 and ens20.

2. Check NetworkManager Status

Ensure that NetworkManager is installed and running on your system. You can check its status with the following command:

$ sudo systemctl status NetworkManager

If it's not running, you can start it using:

$ sudo systemctl start NetworkManager
$ sudo systemctl enable NetworkManager

3. Create a New Bond Connection

You can create a new bond connection using the nmcli command. Here's the basic syntax:

$ sudo nmcli connection add type bond ifname bond0 mode MODE_NAME

Replace bond0 with the name you want to give to your bonded interface, and replace MODE_NAME with the bonding mode you want to use, such as active-backup, balance-rr, or 802.3ad.

For example, to create a bond called bond0 in active-backup mode:

$ sudo nmcli connection add type bond ifname bond0 mode active-backup

This command will create new network connection named 'bond-bond0'.

Connection 'bond-bond0' (e68041f8-d836-4b83-a743-1bcadec9d19e) successfully added.

4. Add Member Interfaces

Now, you need to add the network interfaces that you want to include in the bond as member interfaces.

For example, I am going to add ens19 and ens20 as the members of the bond0 interface using nmcli command.

Replace ens19 and ens20 with the names of your actual network interfaces:

$ sudo nmcli connection add type ethernet ifname ens19 master bond0
$ sudo nmcli connection add type ethernet ifname ens20 master bond0

This will add ens18, ens19, and ens20 as member interfaces to the bond0 bond connection.

You can verify the newly created network connections using command:

$ nmcli connection show

Sample Output:

NAME                UUID                                  TYPE      DEVICE 
bond-bond0          e68041f8-d836-4b83-a743-1bcadec9d19e  bond      bond0  
Wired connection 1  60e8eaf3-89f9-3e9f-9919-1944e7abee20  ethernet  ens18  
bond-slave-ens19    578bb27f-f3ff-4059-bd94-5291b98ce2fb  ethernet  ens19  
bond-slave-ens20    e338b080-6dc6-41b2-bb08-53d0470dccbd  ethernet  ens20       
Wired connection 2  5527636c-50a9-35a4-b92b-adcc4f106cba  ethernet  --     
Wired connection 3  878666ef-2160-338b-aadf-e24e9a52509a  ethernet  --     

5. Configure Bonding Options

You may need to configure additional options depending on your bonding mode and network setup. For example, if you're using active-backup mode, you can specify the primary interface:

$ sudo nmcli connection modify bond-bond0 primary ens19

The step of specifying the primary interface is required in some bonding modes, such as active-backup, to determine which interface should be the primary one that actively carries network traffic under normal conditions.

This setting is crucial for ensuring that the bonding mode functions as expected and that traffic is properly distributed or fails over in case of a network failure.

In active-backup mode, for instance, designating the primary interface ensures that network traffic primarily goes through that interface, and if it becomes unavailable, the backup interface takes over.

Without specifying the primary interface, the bond may not know which interface to use as the default choice for sending and receiving traffic.

6. Configure IP Address and DNS Settings

You can set the IP address, subnet mask, gateway, and DNS settings for the bond0 connection using the nmcli command. For example:

$ sudo nmcli connection modify bond-bond0 ipv4.method manual
$ sudo nmcli connection modify bond-bond0 ipv4.addresses "192.168.1.10/24" 
$ sudo nmcli connection modify bond-bond0 ipv4.gateway "192.168.1.101"
$ sudo nmcli connection modify bond-bond0 ipv4.dns "8.8.8.8, 8.8.4.4"

You can also mention all network details in a single command like below:

$ sudo nmcli connection modify bond-bond0 ipv4.method manual ipv4.addresses "192.168.1.10/24" ipv4.gateway "192.168.1.101" ipv4.dns "8.8.8.8,8.8.4.4"

Adjust the IP address, subnet mask, gateway, and DNS servers according to your network configuration.

7. Activate the Bond Connection

Finally, activate the bond connection using the nmcli command:

$ sudo nmcli connection up bond-bond0

This will bring up the bonded interface and make it available for network communication.

Configure Network Bonding in Linux using nmcli
Configure Network Bonding in Linux using nmcli

8. Verify the Configuration

Verify that the bonded interface bond0 is up and running using the nmcli command:

$ sudo nmcli connection show

That's it! You have successfully created a network bonding configuration using the nmcli command. Your bonded interface is now configured for redundancy and load balancing, depending on the bonding mode you selected.

You can use any one of the following methods to test if your network bond interface is working or not.

Testing Your Linux Network Bond Interface

To check if the bond interface is working correctly, you can perform various tests and checks to ensure that it provides the expected redundancy and load balancing.

Here are some steps to help you verify the functionality of a bond interface in Linux:

1. Check Bond Status

Use the following command to check the status of your bond interface (replace bond0 with the actual name of your bond interface):

$ sudo cat /proc/net/bonding/bond0

This command will display detailed information about the bond interface, including its mode, the status of the slave interfaces, and any errors or failures.

View Network Bond Interface Details
View Network Bond Interface Details

2. Test Failover

To verify that failover is working as expected, you can physically disconnect one of the slave interfaces (e.g., unplug the network cable) and monitor the bond's behavior.

The bond should automatically switch traffic to the remaining active slave interface. You can check this by observing the bond's status with the command mentioned in step 1.

3. Test Load Balancing

If your bond is configured for load balancing (e.g., using the "balance-rr" mode), you can use tools like iperf to generate network traffic and check if it is distributed evenly across the bonded interfaces.

Install iperf if it's not already installed and run tests between your server and other network devices.

Example:

  • On the server (bonded interface): iperf -s
  • On a client: iperf -c <server_ip>

Verify that traffic is flowing through all bonded interfaces and that you are getting increased throughput compared to a single interface.

If the network bond interface is working correctly, you should see an output similar to the one below on the system where you configured the bond interface.

$ iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size:  128 KByte (default)
------------------------------------------------------------
[  1] local 192.168.1.10 port 5001 connected with 192.168.1.101 port 39808
[ ID] Interval       Transfer     Bandwidth
[  1] 0.0000-10.0011 sec  38.7 GBytes  33.3 Gbits/sec
[...]

4. Check Interface Status

Use standard network diagnostic tools like ifconfig, ip, or nmcli to check the status of individual network interfaces (both slave and bond). Ensure that all interfaces are up and have the expected IP addresses and configuration.

Example:

$ ip addr show
Check Network Bond Interface Status
Check Network Bond Interface Status

5. Review System Logs

Check system logs (e.g., /var/log/syslog, /var/log/messages) for any error messages or notifications related to the bond interface. Look for any messages indicating interface failures or issues.

6. Monitor Network Traffic

You can use network monitoring tools like tcpdump or wireshark to capture and analyze network traffic on the bond interface. This can help you confirm that traffic is being balanced or failover is working as expected.

7. Ping and Test Connectivity

Perform ping tests and test network connectivity between your bonded server and other devices on the network. Verify that you can reach various destinations, and there are no connectivity issues.

8. Load Testing

In addition to iperf, you can perform more comprehensive load testing using tools like netperf or ttcp to evaluate the bond's performance under heavy network loads.

By conducting these tests and checks, you can ensure that your bond interface is functioning correctly, providing both redundancy and load balancing as configured.

This comprehensive approach will help you identify any issues and verify that your network bonding setup meets your expectations and requirements.

Change IP Address of Bond Interface

To change the IP address of a bond interface in Linux later, you can follow these steps:

Modify Bond Interface IP Address using Netplan

1. Edit the Netplan Configuration (for systems using Netplan):

If you're using Netplan for network configuration (common in modern Linux distributions), you'll need to edit the Netplan configuration file. For example, if your bond interface is configured in a file named 01-bond.yaml, you can edit it with a text editor:

$ sudo nano /etc/netplan/01-bond.yaml

2. Modify the IP Address:

In the Netplan configuration file, locate the addresses section under your bond interface configuration. It will look something like this:

addresses: [192.168.1.10/24]

Modify the IP address and subnet mask to your desired values. For example:

addresses: [192.168.1.20/24]

3. Apply the Configuration:

After making the changes, save the configuration file and apply the changes using the netplan apply command:

$ sudo netplan apply

This will apply the new IP address to the bond interface.

If you are not using Netplan and instead using other network configuration methods like NetworkManager or ifupdown, the steps may vary slightly.

In such cases, you will need to modify the configuration files for the bond interface and then restart or reload the network service to apply the changes.

Modify Bond Interface IP Address using nmcli

For instance to change the IP address of a bond interface using nmcli command, follow the steps below.

1. Check Existing Bond Configuration:

Before making changes, check the existing configuration of your bond interface using the nmcli command:

$ nmcli connection show bond0

Replace bond0 with the name of your bond interface.

2. Modify the IP Address:

Use the nmcli command to modify the IP address of the bond interface. Replace bond0 with your bond interface name and new_ip_address with the new IP address you want to assign:

$ sudo nmcli connection modify bond0 ipv4.addresses new_ip_address/24

For example, to change the IP address to "192.168.1.20/24":

$ sudo nmcli connection modify bond0 ipv4.addresses 192.168.1.20/24

3. Apply the Changes:

After modifying the IP address, you can apply the changes to the bond interface using the following command:

$ sudo nmcli connection up bond0

This command activates the bond interface with the new IP address.

4. Verify the Changes:

Verify that the changes have taken effect by checking the bond interface's status and IP address:

$ nmcli connection show bond0

You should see the updated IP address in the output.

By following these steps, you can successfully change the IP address of a bond interface using nmcli. Make sure to replace bond0 and new_ip_address with your specific bond interface name and the desired IP address you want to assign.

The specific configuration files and commands can vary depending on your Linux distribution and network management tools in use.

Frequently Asked Questions (FAQ)

Here are some common FAQ for network bonding in Linux.

Q: What is network bonding in Linux?

A: Network bonding, also known as NIC bonding or teaming, is a technique in Linux that combines multiple network interfaces into a single logical interface. It enhances redundancy and performance for servers or workstations.

Q: Why should I use network bonding?

A: Network bonding offers improved network reliability by providing failover capabilities. It also enhances network performance through load balancing across multiple network interfaces.

Q: What bonding modes are available in Linux?

A: Linux supports various bonding modes, including "active-backup" (failover), "balance-rr" (round-robin), "802.3ad" (LACP), and more. Each mode serves different purposes and suits specific network configurations.

Q: How can I test if my bond interface is working correctly?

A: You can test your bond interface by monitoring its status, simulating network failures to check failover behavior, and using tools like iperf to verify load balancing.

Q: What should I do if I need to change the IP address of a bond interface?

A: To change the IP address of a bond interface, modify the relevant configuration file (e.g., Netplan, ifupdown, NetworkManager), update the IP address, and apply the changes using the appropriate command or tool (e.g., netplan apply, nmcli connection up).

Q: Is it possible to mix different bonding modes on the same system?

A: Yes, it's possible to have multiple bond interfaces with different bonding modes on the same system. Each bond interface operates independently.

Q: Can I add or remove slave interfaces from a bond interface without disrupting network connectivity?

A: Yes, you can dynamically add or remove slave interfaces from a bond interface without disrupting network connectivity. The bond interface will adapt to the changes, provided it is configured correctly.

Conclusion

Network bonding is a valuable method for enhancing network availability, redundancy, and load balancing in Linux systems. By combining multiple physical network interfaces into a single logical interface, network bonding can provide increased bandwidth, fault tolerance, and traffic distribution.

Netplan and nmcli are two powerful tools that can be used to configure network bonding in Linux. Netplan offers a declarative YAML-based approach for defining network configurations, while nmcli provides a command-line interface for managing network connections.

Through a combination of netplan and nmcli, network bonding can be effectively implemented on Linux systems, ensuring reliable and high-performance network connectivity.


Related Read:


You May Also Like

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More