2

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.

1
  • 1
    I don't think I'd get too attached to netplan. From what I've seen, it's yet another of Canonical's crappy solutions to non-problems, and it's likely to go the way of the dodo (except they actually shipped it in an LTS Ubuntu, so some people are going to be stuck with it for years). Commented Apr 9, 2018 at 18:41

2 Answers 2

0

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
0

I didn't find a way to do a tap interface from netplan yaml file, I think you will have to read in deep the reference manual from web page. It is possible the tunnel interface with gretap mode should be a solution. Anyway my advice is use the ip command in a boot script in systemd for example, if you wanna to configure it fast.

/usr/bin/tap.sh

#!/bin/bash

ip link add name br0 type bridge;
for i in `seq 0 5`; do
    ip tuntap add name tap$i mode tap;
    ip link set up dev tap$i;
    ip link set tap$i master br0;
done;

/lib/systemd/system/tap.service

[Unit]
Description=TAP Interfaces
After=network.target

[Service]
Type=oneshot
User=root
ExecStart=/usr/bin/tap.sh

[Install]
WantedBy=multi-user.target

$ sudo systemctl enable tap.service
Created symlink /etc/systemd/system/multi-user.target.wants/tap.service → /lib/systemd/system/tap.service.

Netplan docs: https://netplan.io/reference/#properties-for-device-type-tunnels%3A

4
  • Shouldn't this go into /etc/systemd rather than /lib/systemd? The latter may be overwritten.
    – slhck
    Commented Mar 12, 2021 at 12:58
  • Hi! No. Use /lib/systemd/system with filename and extension .service the standard way to work with unit files in systemd. Commented Mar 15, 2021 at 13:26
  • That's not correct, actually, see: wiki.archlinux.org/index.php/systemd/lib is reserved for system-installed packages. You should use /etc and override if necessary.
    – slhck
    Commented Mar 15, 2021 at 13:56
  • link is rotten. actual link to netplan docs: netplan.readthedocs.io/en/stable/netplan-yaml
    – shomeax
    Commented Apr 28, 2023 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .