I'm using Ubuntu 20.04, with systemd-networkd and Netplan. I have two physical interfaces (ens3
and ens4
) which are configured by DHCP (with reservations, so I always get the same addresses).
Additionally, I have two tunnel devices. These are outside Netplan/networkd control (they're created by Strongswan, but for all intents and purposes they're created manually by running something like ip tunnel add...
). These tunnel devices have an ip route
added to send traffic to them. When initially created, these work fine, but systemd-networkd will eventually remove the routes.
To counter this, I have successfully configured the tunnel devices in systemd-networkd but the route fails to be created because it is attempted before ens3
/ens4
are configured (I see tunnel1: Could not set route: Invalid prefsrc address. Invalid argument
in syslog). I have confirmed the ordering by switching on debug logging.
I can add the route manually:
ip route add 10.0.32.0/20 dev tunnel1 scope link src 10.0.16.170 metric 100
...which works fine, but will be removed at some later time by systemd-networkd.
The documentation says "All configuration files are collectively sorted and processed in lexical order, regardless of the directories in which they live.", so I had a look for other config files, and found these in /run/systemd/network
:
10-netplan-ens3.link
10-netplan-ens3.network
10-netplan-ens4.link
10-netplan-ens4.network
I've tried naming my netdev
and network
files as 99-tunnel1.netdev
or zzzz-tunnel1.netdev
etc, and even tried with 00-
etc too. No matter what I do, it always seems that ens3
and ens4
are configured after the tunnel interfaces, and so the route always fails to add.
I have also tried configuring my devices in Netplan. It makes some things tricky, but ultimately has the same problem. Even though it creates files like 10-netplan-tunnel1.network
(which are lexically after the ens3/ens4 files), they're still applied in the wrong order by networkd.
I'm sure I'm missing something here, but I can't see what. Any ideas?
My tunnel1.netdev
looks like this:
[NetDev]
Name=tunnel1
Kind=vti
MTUBytes=1419
[Tunnel]
Remote=1.2.3.4
Local=2.3.4.5
Key=100
...and the .network
looks like this:
[Match]
Name=tunnel1
[Link]
RequiredForOnline=no
MTUBytes=1419
[Address]
Address=169.254.102.162/30
Peer=169.254.102.161/30
[Route]
Destination=10.0.32.0/20
PreferredSource=10.0.16.170
Metric=100
Scope=link