How to set up LACP bonding on Ubuntu 18.04 with Netplan

Estimated reading time: 1 min

Introduction

In this article, we’ll look at how to set up LACP bonding on a server running Ubuntu. LACP bonding uses the Link Aggregation Control Protocol to combine two network interfaces into one logical interface. Today, we’ll use it to combine two ethernet interfaces. This is useful to increase the throughput from each ethernet device and to provide for a way to failover if there’s an error with one of the devices.

Prerequisites

  • The network switch your server is connected to must be set up accordingly in for a successful procedure
  • You need to have the SSH login details of your server ready

Step 1 – Login using SSH

You must be logged in via SSH as sudo or root user. Please see this article for instructions if you don’t know how to connect.

Step 2 – Install the ifenslave dependency

sudo apt-get install ifenslave

Step 3: Load bonding kernel module

Before you can configure the network cards you need to ensure that the kernel module called bonding is present and loaded.

sudo lsmod | grep bonding

If the module is not loaded. Use the following command to load it

sudo modprobe bonding

To ensure that the bonding module is loaded during boot time change file the following file

sudo nano /etc/modules

Add the following line

bonding

Step 4 – find the active network interface

clear && echo $(ip -o -4 route get 8.8.8.8 | sed -nr 's/.*dev ([^\ ]+).*/\1/p')

Step 5 – Configure the network interface

The output of step 4 is the network interface which is active at the moment. You should use that name for the bond. In our case this is enp2s0 and the second interface enp3s0.

# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
  version: 2
  ethernets:
    eports:
      match:
        name: enp*
      optional: true
  bonds:
    bond0:
      interfaces: [eports]
      addresses: [78.41.207.45/24]
      gateway4: 78.41.207.1
      nameservers:
        addresses: [89.207.128.252, 89.207.130.252]
      parameters:
        mode: 802.3ad
        lacp-rate: fast
        mii-monitor-interval: 100

Apply the changes

sudo netplan apply

Step 6 – Reboot

reboot

Step 7 – Check bonding interface status

If everything went well, you should have a working bonding interface. You can check this by executing the following command

cat /proc/net/bonding/bond0

Conclusion

Congratulations, you have configured LACP network interface according to IEEE 802.3ad on a Ubuntu server 18.04 with Netplan. If you are interested in other modes which are available check this URL section “Descriptions of bonding modes”.

Was this article helpful?
Dislike 16
Views: 94279

Reader Interactions

Comments

  1. goudeuk says

    Hello

    Could you please let me know which file do I need to edit in Step 5?
    Also where in the file (step5) are the two physical interfaces defined?

    Many thanks

      • Michael Cooper says

        Very nice article I understand the over all concept now just need one thing addressed.

        Where are the nics defined in the netplan config file?

        You have the following:
        ################
        network:
        version: 2
        ethernets:
        eports:
        match:
        name: enp*
        optional: true
        bonds:
        bond0:
        interfaces: [eports]
        addresses: [78.41.207.45/24]
        gateway4: 78.41.207.1
        nameservers:
        addresses: [89.207.128.252, 89.207.130.252]
        parameters:
        mode: 802.3ad
        lacp-rate: fast
        mii-monitor-interval: 100
        ############################

        I am assuming enp2s0 goes under network -> ethernets->eports->name does it actually use a wildcard character?

        Where does enp3s0 get defined in this config?
        I see you have eports defined and referenced but where des the second nic get defined?

        Not trying to be a jerk just need a little clarification, Thanks for all your hard work.

  2. Madan says

    I tried the above steps however it is not working for me.

    When I see the bonding status it is working fine for me(cat /proc/net/bonding/bond0)

    However, after reboot it is not working for me and I am unable to connect to the server.

  3. Madan says

    Hi Ahmed,

    Thanks for your response.

    Yes, I have loaded the bonding modules after the reboot. However, When I manually unplug the primary ethernet connection(eX:enp0s3) I am unable to connect/ping the server. If I unplug another ethernet connection manually it is working fine for me. Kindly once see the below file and let me know if it requires any modifications.

    # interfaces(5) file used by ifup(8) and ifdown(8)
    auto lo
    iface lo inet loopback

    # eth0 is manually configured, and slave to the "bond0" bonded NIC
    auto enp0s3
    iface enp0s3 inet manual
    bond-master bond0
    bond-primary enp0s3

    # eth1 ditto, thus creating a 2-link bond.
    auto enp0s8
    iface enp0s8 inet manual
    bond-master bond0

    # bond0 is the bonding NIC and can be used like any other normal NIC.
    # bond0 is configured using static network information.
    auto bond0
    iface bond0 inet static
    address 192.168.0.7
    gateway 192.168.0.1
    netmask 255.255.255.0
    bond-mode 1
    bond-miimon 100
    bond-slaves none
    # bond-lacp-rate 1
    # bond-slaves enp0s3 enp0s8

    • Ahmet Bas says

      Is this a configuration with netplay does not seems like a yaml configuration. Did you check our Ubuntu 16.04 knowledge base article https://www.snel.com/support/how-to-setup-lacp-bonding-on-ubuntu-16-04/ ?

  4. Madan says

    Hi Ahmad,

    Above configuration, I did in the oracle virtual VM.

    kindly let me know, If I restart the server multiple times with bonding changes, will it be an effect on the bonding?

    Please correct me if I am wrong, I think due to the network cache I am getting the different results of bonding after every immediate restart.

  5. darkfader says

    why does one need to reboot?
    what is the point of this daemon if we need to reboot to activate or test something that could be configured on the fly more than a decade before the daemon was designed?

Leave a Reply

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