Learn to bridge and bond network interfaces using Netplan on Ubuntu, optimizing connectivity for network administrators.
In this lesson, you will learn how to bridge and bond network interfaces using Netplan on Ubuntu. We’ll start by exploring example YAML configuration files, then modify them to suit your network configuration. This guide is perfect for network administrators looking to optimize connectivity using bridges and bonded devices.
This configuration defines a single Ethernet interface (enp3s0) with DHCP disabled, and a bridge (br0) that obtains an IP address via DHCP. This file serves as our starting template.
Before making any modifications, verify that the network interfaces referenced in the configuration match your system’s hardware.
Determine the network interface names in your system with:
Copy
Ask AI
jeremy@kodekloud:~$ ip -c link1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 100 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:002: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:03:bc:00 brd ff:ff:ff:ff:ff:ff3: enp0s8: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 08:00:27:d2:01:dd brd ff:ff:ff:ff:ff:ff4: enp0s9: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 08:00:27:ea:bb:00 brd ff:ff:ff:ff:ff:ff
Note that enp0s3 is used for primary connectivity (e.g., SSH access) and should not be modified to avoid disconnection. In this lesson, we will use enp0s8 and enp0s9 for the bridge.
Update the Netplan configuration to create a bridge that combines enp0s8 and enp0s9. Disable DHCP on the individual Ethernet interfaces and enable it solely on the bridge:
Save the file and apply the configuration. Verify the network interface statuses with:
Copy
Ask AI
jeremy@kodekloud:~$ ip -c link1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 100 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:002: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:03:bc:2f brd ff:ff:ff:ff:ff:ff3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:f4:ce:41 brd ff:ff:ff:ff:ff:ff4: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:19:88:7f brd ff:ff:ff:ff:ff:ff5: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000 link/ether 8a:93:4f:ea:fb:f2 brd ff:ff:ff:ff:ff:ff
This output shows that enp0s8 and enp0s9 are now slaves to the bridge br0, which is assigned an IP address via DHCP.
Next, let’s configure network bonding to provide redundancy and load balancing. Begin by copying the bonding example file and setting secure permissions:
Edit the bonding configuration file (/etc/netplan/99-bond.yaml) using your favorite text editor. The corrected configuration below ensures that the Ethernet interfaces are properly defined:
The Ethernet interfaces enp0s8 and enp0s9 have DHCP disabled.
A bond named bond0 is configured with DHCP enabled.
The bonding mode is set to active-backup (Mode 1) with enp0s8 designated as the primary interface.
The MII monitor checks link status every 100 milliseconds.
For additional bonding modes (such as balance-rr, balance-xor, broadcast, 802.3ad, balance-tlb, or balance-alb), review the bonding documentation and adjust the parameters accordingly.
For a deeper understanding of the bonding options and Netplan configuration, consult the manual by running:sudo man netplanThen search for “bonding” within the manual.
Apply the new Netplan configuration:
Copy
Ask AI
sudo netplan apply
After applying the changes, confirm the bonding setup with:
Copy
Ask AI
jeremy@kodekloud:~$ ip -c link1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 100 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:002: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:0a:bc:7c brd ff:ff:ff:ff:ff:ff3: enp0s8: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000 link/ether 2a:df:84:09:1a:e1 brd ff:ff:ff:ff:ff:ff4: enp0s9: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP mode DEFAULT group default qlen 1000 link/ether 2a:df:84:09:1a:e1 brd ff:ff:ff:ff:ff:ff5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000 link/ether 2a:df:84:09:1a:e1 brd ff:ff:ff:ff:ff:ff
This output indicates that both enp0s8 and enp0s9 are slaves of bond0, which is receiving its IP configuration via DHCP.