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.