For some of my Ubuntu 18.04 servers, I need to run KVM virtual machines which require a bridge to the network so the machines get public LAN IP addresses and aren’t hidden behind NAT. With the server configuration for both my co-location and servers at work the network interfaces are all bonded for fail-over. This means I need a bond to have a bridge ontop of it for the virtual machines to get public IP addresses, while still allowing for failover of the network connection in the event of a network failure.
Research
There are some good examples of setting up netplan here: https://netplan.io/examples
They have a bridge example:
network: version: 2 renderer: networkd bridges: br0: dhcp4: yes interfaces: - enp3s0
And a bond example:
network: version: 2 renderer: networkd bonds: bond0: dhcp4: yes interfaces: - enp3s0 - enp4s0 parameters: mode: active-backup primary: enp3s0
But there’s not a clear indication of how to amalgamate the two.
A bond and a bridge
Here’s what I’ve ended up with in ‘/etc/netplan/50-cloud-init.yaml’:
network: bridges: br0: addresses: - 192.168.10.30 dhcp4: false gateway4: 192.168.10.1 nameservers: addresses: - 192.168.10.1 - 192.168.10.2 search: [] interfaces: - bond0 bonds: bond0: interfaces: - eno1 - eno2 parameters: mode: active-backup ethernets: eno1: addresses: [] dhcp4: false dhcp6: false eno2: addresses: [] dhcp4: false dhcp6: false
Note that I’ve obviously defined static IP addresses, but this isn’t a requirement. Just set ‘dhcp4: true’ and remove the ‘address’, ‘gateway’ and ‘nameserver’ sections if you’re using DHCP.
Once the file’s got that setup in it, it’s possible to run:
sudo netplan apply
and you should be able to run ‘networkctl list’ to check the bridge and bond are setup.
Benjamin Hugo says
Thanks for a great article
I’m documenting a fix for people who rely on DHCP to assign a static IP based on mac-address. Before installing the bridge (to connect KVM VMs) we had the mac-address set on the bond interface. It seems the bridge DHCP4 settings somehow superceeds the bond DHCP4 settings. The solution is to transfer the mac-address of the bond onto the bridge in a setting that looks something like the following:
01-netplan.yaml
03-bridges.yaml
Running networkctl status -a you should get something like the following after applying and (probably) rebooting
“`
● 1: lo
Link File: /lib/systemd/network/99-default.link
Network File: n/a
Type: loopback
State: carrier (unmanaged)
Address: 127.0.0.1
::1
● 2: eno1
Link File: /lib/systemd/network/99-default.link
Network File: /run/systemd/network/10-netplan-eno1.network
Type: ether
State: carrier (configured)
Path: pci-0000:01:00.0
Driver: bnx2x
Vendor: Broadcom Limited
Model: NetXtreme II BCM57800 1/10 Gigabit Ethernet (BCM57800 10-Gigabit Ethernet)
HW Address: xx:xx:xx:xx:xx:xx
Connected To: strubendca7.switch.ru.ac.za on port Te1/0/7 (elwood)
● 3: eno2
Link File: /lib/systemd/network/99-default.link
Network File: /run/systemd/network/10-netplan-eno2.network
Type: ether
State: carrier (configured)
Path: pci-0000:01:00.1
Driver: bnx2x
Vendor: Broadcom Limited
Model: NetXtreme II BCM57800 1/10 Gigabit Ethernet (BCM57800 10-Gigabit Ethernet)
HW Address: xx:xx:xx:xx:xx:xx
Connected To: strubendca7.switch.ru.ac.za on port Te1/0/8 (elwood)
● 4: eno3
Link File: /lib/systemd/network/99-default.link
Network File: /run/systemd/network/10-netplan-eno3.network
Type: ether
State: routable (configured)
Path: pci-0000:01:00.2
Driver: bnx2x
Vendor: Broadcom Limited
Model: NetXtreme II BCM57800 1/10 Gigabit Ethernet (BCM57800 1-Gigabit Ethernet)
HW Address: xx:xx:xx:xx:xx:xx (Dell Inc.)
Address: 146.231.135.142
2001:4200:1010:1548:baca:3aff:feec:7855
fe80::baca:3aff:feec:7855
Gateway: 146.231.135.129
DNS: 146.231.129.97
146.231.129.102
Search Domains: ru.ac.za
NTP: 146.231.129.81
146.231.129.86
Connected To: strubendca7-mgmt.switch.ru.ac.za on port 1/0/15
● 5: eno4
Link File: /lib/systemd/network/99-default.link
Network File: n/a
Type: ether
State: off (unmanaged)
Path: pci-0000:01:00.3
Driver: bnx2x
Vendor: Broadcom Limited
Model: NetXtreme II BCM57800 1/10 Gigabit Ethernet (BCM57800 1-Gigabit Ethernet)
HW Address: xx:xx:xx:xx:xx:xx (Dell Inc.)
● 6: brvm
Link File: /lib/systemd/network/99-default.link
Network File: /run/systemd/network/10-netplan-brvm.network
Type: ether
State: routable (configured)
Driver: bridge
HW Address: xx:xx:xx:xx:xx:xx (Dell Inc.)
Address: 146.231.135.133
2001:4200:1010:1548:baca:3aff:feec:7851
fe80::baca:3aff:feec:7851
Gateway: 146.231.135.129
DNS: 146.231.129.97
146.231.129.102
Search Domains: ru.ac.za
NTP: 146.231.129.81
146.231.129.86
● 7: bond0
Link File: /lib/systemd/network/99-default.link
Network File: /run/systemd/network/10-netplan-bond0.network
Type: ether
State: carrier (configured)
Driver: bonding
HW Address: xx:xx:xx:xx:xx:xx
Wynand says
Got an error but after changing from
bridges:
br0:
addresses:
– 192.168.10.30
to
bridges:
br0:
addresses:
– 192.168.10.30/24
It worked
Thanks for this post really helped