On a Debian Stretch system with multiple interfaces, I need to define the default route via a specific interface ens3
. This interface receives its ip address 10.33.34.2
through dhcp.
I adjusted the following guide to my needs:
5.3. The modern network configuration without GUI
Thus, I created a file /etc/systemd/network/route.network
with the following content
[Match]
Name=ens3
[Network]
Gateway=10.33.34.1
However, the default route is not set correctly at startup.
I enabled debugging of systemd-networkd
according to How to debug systemd-networkd?
After restarting systemd-networkd
, I see the following in the logs:
Aug 21 13:43:13 vpn systemd-networkd[15671]: ens3: Setting routes
Aug 21 13:43:13 vpn systemd-networkd[15671]: ens3: Could not set route: Network is unreachable
Aug 21 13:43:13 vpn systemd-networkd[15671]: ens3: Routes set
Aug 21 13:43:13 vpn dhclient[15709]: Listening on LPF/ens3/52:54:00:3f:f1:d0
Aug 21 13:43:13 vpn dhclient[15709]: Sending on LPF/ens3/52:54:00:3f:f1:d0
Aug 21 13:43:13 vpn dhclient[15709]: Sending on Socket/fallback
Aug 21 13:43:13 vpn dhclient[15709]: DHCPDISCOVER on ens3 to 255.255.255.255 port 67 interval 8
Aug 21 13:43:13 vpn dhclient[15709]: DHCPREQUEST of 10.33.34.2 on ens3 to 255.255.255.255 port 67
Aug 21 13:43:13 vpn dhclient[15709]: DHCPOFFER of 10.33.34.2 from 10.33.34.1
Aug 21 13:43:13 vpn dhclient[15709]: DHCPACK of 10.33.34.2 from 10.33.34.1
Aug 21 13:43:13 vpn systemd-networkd[15671]: ens3: Adding address: 10.33.34.2/24 (valid forever)
It seems that networkd tries to set the route before the IP-address is assigned via dhcp.
How do I get the default route set to a specific interface with systemd?
== Edit ==
I was wrong in assuming that systemd-networkd brings up the interfaces. If I restart the system, I see
$ sudo service systemd-networkd status
● systemd-networkd.service - Network Service
Loaded: loaded (/lib/systemd/system/systemd-networkd.service; disabled; vendor pres
Drop-In: /etc/systemd/system/systemd-networkd.service.d
└─10-debug.conf
Active: inactive (dead)
Docs: man:systemd-networkd.service(8)
Thus, configuration in /etc/systemd/network/route.network
takes no effect when booting. Currently, I'm wondering what service is responsible to bring up all the network devices.
== Edit 2 ==
This article by Steven Iveson provides a good insight on how network devices are started by systemd-udevd
and how to modify interface configuration.
By testing and further reading, I would also restate my problem:
The multiple interfaces are brought up in random order. Each obtains a correct dhcp configuration. The first interface to be brought up will set the default route and therefore, 10.33.34.1
will not always be used as default route
systemd
, sorry. Another option would be to configure your DHCP server to distribute the correct route in the first place.