GekBuzz

Answers, Explainers & Everyday Guides

How to Set Up Network Bonding on Ubuntu for Beginners

How to Set Up Network Bonding on Ubuntu for Beginners

Network bonding on Ubuntu allows you to combine multiple network interfaces into a single logical interface. This setup increases bandwidth, provides redundancy, and improves network reliability by enabling failover between interfaces. It’s especially useful in environments where uptime and performance are critical, such as servers or professional workstations.

What You’ll Need

  • An Ubuntu system (desktop or server) with at least two network interfaces (NICs) available for bonding.
  • Root or sudo privileges to modify network configurations.
  • Basic familiarity with the Linux command line and file editing.
  • Access to your network’s switch or router (optional but recommended to configure switch-side bonding modes if needed).

Step-by-Step

  1. Check your network interfaces: Open a terminal and run ip link show or ifconfig -a to list all network interfaces. Identify the interfaces you want to bond (e.g., eth0 and eth1).
  2. Install ifenslave package: This utility is required to manage bonded interfaces. Run sudo apt update followed by sudo apt install ifenslave.
  3. Load bonding kernel module: Run sudo modprobe bonding to activate the bonding driver. To make it load on boot, add bonding to /etc/modules by running echo bonding | sudo tee -a /etc/modules.
  4. Backup current network config: Before making changes, backup your existing network configuration files, e.g., sudo cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak or the appropriate config file for your Ubuntu version.
  5. Edit netplan configuration: Ubuntu 18.04 and newer use Netplan for network configuration. Open your netplan YAML file with sudo nano /etc/netplan/01-netcfg.yaml (filename may differ).
    • Define a bonded interface (e.g., bond0) with your chosen mode (see bonding modes below).
    • Specify the member interfaces (e.g., eth0 and eth1).

    Example configuration:

    network:
      version: 2
      renderer: networkd
      ethernets:
        eth0: {}
        eth1: {}
      bonds:
        bond0:
          interfaces: [eth0, eth1]
          parameters:
            mode: active-backup
            primary: eth0
            mii-monitor-interval: 100
          dhcp4: yes
    

    This example uses active-backup mode with DHCP enabled.

  6. Apply the network configuration: Run sudo netplan apply. This command will activate the bonding interface and bring down individual interfaces under it.
  7. Verify bonding status: Check if the bond is up and the slave interfaces are attached with cat /proc/net/bonding/bond0. This file shows bonding mode, active slave, and link status.
  8. Configure switch (optional): If your bonding mode requires switch support (e.g., 802.3ad for LACP), ensure your network switch is configured to support link aggregation for the ports connected to your Ubuntu system.
  9. Test failover: Disconnect one network cable and verify that network connectivity continues without interruption, confirming the bond is working as expected.

Common Mistakes

  • Not backing up network config files: Changes can disrupt connectivity; always backup before editing.
  • Incorrect YAML syntax: Netplan files are sensitive to indentation and formatting errors, leading to failed applies.
  • Using incompatible bonding modes without switch support: Modes like 802.3ad require switch configuration; otherwise, the bond won’t work correctly.
  • Forgetting to load the bonding module: Without it, bonding interfaces won’t function.
  • Not specifying all slave interfaces in the bond: Leaving out an interface means it won’t be part of the bond.
  • Assuming bonding increases speed automatically: Some modes only provide failover, not aggregated bandwidth.

Tips

  • Choose the right bonding mode: For simple failover, use active-backup. For load balancing or aggregation, consider balance-rr, balance-xor, or 802.3ad with switch support.
  • Use mii-monitor-interval to monitor link health: This setting controls how often the link is checked and helps with faster failover.
  • Test changes on a non-production system first: To avoid downtime, try bonding on a test machine or during maintenance windows.
  • Use ip a and ip link commands frequently: They help diagnose interface and bonding status quickly.
  • Keep your system and packages updated: Newer kernel and netplan versions have improved bonding support and bug fixes.
  • Document your configuration changes: This helps maintain clarity if you revisit or troubleshoot later.

Troubleshooting

If your network bonding does not work as expected, try the following steps:

  • Check kernel module: Run lsmod | grep bonding to confirm the bonding module is loaded. If it’s not, run sudo modprobe bonding.
  • Validate netplan YAML syntax: Use sudo netplan try to test configuration before applying, catching syntax errors.
  • Inspect bond status: View /proc/net/bonding/bond0 for detailed info on slaves and mode.
  • Verify IP assignment: Make sure the bonded interface has a valid IP address via DHCP or static config.
  • Check physical connections: Ensure all cables and ports are connected and functioning.
  • Review switch configuration: For modes like 802.3ad, confirm the switch ports are set up for link aggregation.
  • Restart networking services: Sometimes, restarting with sudo systemctl restart systemd-networkd or rebooting helps apply changes cleanly.
  • Look at system logs: Check journalctl -xe or /var/log/syslog for network-related errors.

Frequently Asked Questions

What is network bonding, and why should I use it?

Network bonding combines multiple network interfaces into one logical interface to increase bandwidth, provide redundancy, and improve fault tolerance.

Can I bond wireless interfaces on Ubuntu?

Bonding wireless interfaces is generally not supported or recommended due to the nature of wireless connections and driver limitations.

What bonding mode should I choose for simple failover?

Use active-backup mode, which keeps one interface active and switches to another if it fails.

Does bonding always increase my network speed?

Not necessarily. Some modes provide failover only, while others can aggregate bandwidth depending on switch support and configuration.

Do I need to configure my network switch for bonding to work?

For some modes like 802.3ad (LACP), yes. Other modes like active-backup do not require switch configuration.

How can I check if my bonded interface is working correctly?

Check /proc/net/bonding/bond0 for status details and test failover by disconnecting one cable to see if the connection persists.

By following these steps and tips, even beginners can successfully set up network bonding on Ubuntu, improving their network’s reliability and performance with minimal hassle.

For extra practice, you might try creating a static IP bonded interface or experimenting with different bonding modes to see how they affect traffic and failover behavior.

Remember, network bonding is a powerful tool, but it requires careful configuration, especially when working with network switches and production environments.

Related

How to Set Up Network Bonding on Ubuntu for Beginners

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top