1

I have a host which is on 192.168.0.0/24 with an IP of 192.168.0.13. Its DHCP-provided gateway is 192.168.0.254.

The configuration is done via systemd-networkd and the issue below is present at least until version 240 (the version I use today - see my answer regarding further versions).

I need this host to reach 10.0.0.0/8 networks which are available through a 192.168.0.10 gateway - this can be done by adding a static route:

# ip r add 10.0.0.0/8 via 192.168.0.10

It works fine (the traffic goes through).

I now wanted to add this entry to my systemd-networkd configuration, by adding a [Route] to my curent definition

[Match]
Name=eth0

[Network]
DHCP=yes

# the entry below is added to ensure a static route

[Route]
Gateway=192.168.0.10
Destination=10.0.0.0/8

It does not work:

  • no static route is added
  • there is an error message in the log mentioning an unreachable network
Jan 17 11:29:32 rpi-dmz systemd[1]: Stopping Network Service...
Jan 17 11:29:32 rpi-dmz systemd[1]: Stopped Network Service.
Jan 17 11:29:32 rpi-dmz systemd[1]: Starting Network Service...
Jan 17 11:29:33 rpi-dmz systemd-networkd[14584]: wlan0: Gained IPv6LL
Jan 17 11:29:33 rpi-dmz systemd-networkd[14584]: eth0: Gained IPv6LL
Jan 17 11:29:33 rpi-dmz systemd-networkd[14584]: Enumeration completed
Jan 17 11:29:33 rpi-dmz systemd[1]: Started Network Service.
Jan 17 11:29:33 rpi-dmz systemd-networkd[14584]: eth0: Could not set route: Network is unreachable
Jan 17 11:29:33 rpi-dmz systemd-networkd[14584]: eth0: DHCPv4 address 192.168.0.13/24 via 192.168.0.254

How to correctly add that route via systemd-networkd?

3

This is a bug in systemd, still present on version 240.

Per the thread above, a workaround (or solution, I am not sure about the status since the bug is still open) is to add GatewayOnlink=yes in the [Route] section:

[Match]
Name=eth0

[Network]
DHCP=yes

[Route]
Gateway=192.168.0.10
Destination=10.0.0.0/8
GatewayOnlink=yes

This parameter is available from systemd version ~237.

  • FWIW I would agree this is an open bug in systemd. The equivalent settings in NetworkManager work without hitting this problem; I think it is very reasonable for people to expect that the very similar-looking options in systemd-networkd will also work. It is undesirable for them to have to discover this does not work by experiment and have to look in the log - and then even when you look at the log messages, it is not very helpful. – sourcejedi Jan 17 at 13:24
  • I don't know what the best behaviour would be though. I see "Note that DHCPv6 will by default be triggered by [receiving a packet of type] Router Advertisement, if that is enabled..." – sourcejedi Jan 17 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.