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”.
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
You should be able to find the Netplan yaml configuration file in this folder "/etc/netplan/". Yes, there are two physical interfaces required for creating a bond.
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.
We are using a wilcard:
>name: enp*
The ports are defined here:
>interfaces: [eports]
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.
Is the bonding module loaded after a reboot?
Hi Ahmet,
Thanks for your update.
How can I check/load the bonding module?
You can check it with those commands:
sudo lsmod | grep 8021q
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
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/ ?
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.
There is a typo in eports – should be exports.
Thanks for the blog article 🙂
Do you mean the eports in the netplan configuration?
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?
Rebooting the server is not necessary but in our article, we do this. Just to be sure that everything is working after a reboot.
HOW TO ADD BONDING COMMAND IN KERNEL MODULE
Did you follow step 2 & 3, that should be enough to load the kernel modules.
Hi,
Why partner/actor churn stats showed churned any one can tell me ? due to that port-channel at switch showing down.
Make sure the switch is configured correctly and that the cabling is correct.