4

I installed the Ubuntu 18.04 and wanted to have a bridge interface instead of using the main interface directly for KVM virtualization:

Here is the Netplan default configuration after installation, which worked well:

----
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp4s0:
      addresses: [ 176.9.199.230/27 ]
      gateway4: 176.9.199.225
      nameservers:
          addresses:
              - "8.8.8.8"

After reading the documentation for Netplan, I tried this setting for bridge mode:

---

network:
  version: 2
  renderer: networkd
  ethernets:
    enp4s0:
      dhcp4: no
      dhcp6: no
  bridges:
    vmbr0:
      dhcp4: no
      dhcp6: no
      interfaces: [ enp4s0 ]
      addresses: [ 176.9.199.230/27 ]
      gateway4: 176.9.199.225
      nameservers:
        addresses:
          - "127.0.0.1"
      parameters:
        stp: false
        forward-delay: 1
        hello-time: 2
        max-age: 12

As you can tell from the IP address, the server is hosted on Hetzner.

On Ubuntu 16.04, bridges worked well with ifupdown, but now that Ubuntu 18.04 has Netplan instead of ifupdown, I need to know how configure a bridge in Netplan.

Deltik
  • 19,971

1 Answers1

9

The MAC address is randomized if you do not explicitly set it in your bridge configuration in Netplan.

If I recall correctly, Hetzner restricts the IP address you are allocated to your server's MAC address, so you may need to set the bridge's MAC address to the physical interface's.

To get the physical interface's MAC address, run this command:

cat /sys/class/net/enp4s0/address

(Replace enp4s0 with the appropriate interface name, if needed.)

In your Netplan configuration file, add the MAC address under the bridge interface name like so:

macaddress: xx:xx:xx:xx:xx:xx

For you, your Netplan configuration should look like this:

---
network:
  version: 2
  renderer: networkd
  ethernets:
    enp4s0:
      dhcp4: no
      dhcp6: no
  bridges:
    vmbr0:
      macaddress: xx:xx:xx:xx:xx:xx
      dhcp4: no
      dhcp6: no
      interfaces: [ enp4s0 ]
      addresses: [ 176.9.199.230/27 ]
      gateway4: 176.9.199.225
      nameservers:
        addresses:
          - "127.0.0.1"
      parameters:
        stp: false
        forward-delay: 1
        hello-time: 2
        max-age: 12

Apply the configuration by deleting the affected interface (necessary for Netplan to recreate it with the new MAC address) and running Netplan:

sudo ip link delete br0
sudo netplan apply

Now you should have a bridge with functioning host connectivity.

Deltik
  • 19,971