Tap interface using netplan

linux-networkingubuntu-18.04

How does one set up tun and tap interfaces on systems that use netplan?

Normally you'd use pre-up in /etc/network/interfaces to call ip tuntap for creating the interface, but I haven't found anything in the netplan docs to do this.

Best Answer

I ran into this problem when upgrading to 18.04 broke my tap based OpenVPN server. It is quite annoying when a headless server just stops working because Ubuntu dropped support for defining bridges in /etc/network/interfaces. There are a few examples already but pretty much you need to create a .yaml file in /etc/netplan that looks something like one of the configs below. Note that you will need the bridge-utils package installed.

Replace eth0 with the name of your ethernet device. You can find this using ifconfig -a.

Additionally you can set the MAC address of the bridge using the macaddress: xx:xx:xx:xx:xx:xx option where xx:xx:xx:xx:xx:xx is replaced with the address you want to use.

/etc/netplan/00-bridge.yaml

For DHCP:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
     dhcp4: no
     dhcp6: no
  bridges:
    br0:
      interfaces: [eth0]
      dhcp4: true 
      dhcp6: no

For a static IP:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      dhcp6: no
  bridges:
    br0:
      interfaces: [eth0]
      dhcp4: no
      addresses: [10.0.0.5/24]
      gateway4: 10.0.0.1
      nameservers:
        addresses: [8.8.8.8]
      dhcp6: no
Related Topic