You are not logged in.

#1 2025-07-09 14:13:47

andrej
Member
Registered: 2012-03-31
Posts: 23

[SOLVED] Help me understand systemd-networkd and default route

I don't even know how to phrase the question. Basically...

with this DHCP config:

[Match]
Name=en*
[Network]
DHCP=yes
[Route]
Gateway=10.0.0.1
GatewayOnLink=yes

I get these routes:

default via 10.0.0.1 dev enp7s0 proto static onlink
10.0.0.0/24 via 10.0.0.1 dev enp7s0 proto dhcp src 10.0.0.3 metric 1002 mtu 1450
10.0.0.0/24 via 10.0.0.1 dev enp7s0 proto dhcp src 10.0.0.3 metric 1024
10.0.0.1 dev enp7s0 proto dhcp scope link src 10.0.0.3 metric 1002 mtu 1450
10.0.0.1 dev enp7s0 proto dhcp scope link src 10.0.0.3 metric 1024
169.254.169.254 via 10.0.0.1 dev enp7s0 proto dhcp src 10.0.0.3 metric 1002 mtu 1450
169.254.169.254 via 10.0.0.1 dev enp7s0 proto dhcp src 10.0.0.3 metric 1024

And the internet is reachable (can ping 8.8.8.8).

But with this static IP config

[Match]
Name=en*
[Network]
Address=10.0.0.3/24
[Route]
Gateway=10.0.0.1
GatewayOnLink=yes

I don't get the default route

10.0.0.0/24 via 10.0.0.1 dev enp7s0 proto dhcp src 10.0.0.3 metric 1002 mtu 1450
10.0.0.1 dev enp7s0 proto dhcp scope link src 10.0.0.3 metric 1002 mtu 1450
169.254.169.254 via 10.0.0.1 dev enp7s0 proto dhcp src 10.0.0.3 metric 1002 mtu 1450

And the internet is not reachable.

To add more context, I have 2 VPSes on Hetzner. One has a private IP (`10.0.0.2`) and a public IP and is configured as a NAT. The other only has a private IP (`10.0.0.3`). This `10.0.0.0/24` subnet is configured with a custom route for destination `0.0.0.0/24` with gateway `10.0.0.2` (which is the NAT server). The `10.0.0.3` can't reach the internet without the default route.

I want to get rid of the `DHCP=yes` on it, because for some reason it loses the IP lease which in turn deletes the default route. I have no idea why this is happening, so I'm trying to figure out networking stuff. I have very little IP networking knowledge so please bear with me.

When I use DHCP I get daily lease loss:

from journalctl -u systemd-netword.service
...
Jul 09 09:30:37 hostname systemd-networkd[696]: enp7s0: DHCP lease lost <-- when this happens, the lease renews, but the default route is deleted, who knows why
...

Anyway, how can I make `systemd-networkd` add and keep the default route?

Last edited by andrej (2025-07-10 05:54:59)

Offline

#2 2025-07-09 14:47:25

seth
Member
Registered: 2012-09-03
Posts: 65,585

Re: [SOLVED] Help me understand systemd-networkd and default route

"DefaultRouteOnDevice=true" in the "[Network]" segment?

Online

#3 2025-07-09 15:17:09

-thc
Member
Registered: 2017-03-15
Posts: 933

Re: [SOLVED] Help me understand systemd-networkd and default route

Did you realize that in both cases (DHCP and static) you have too many routes/duplicates and an APIPA address (169.254.x.y) added by DHCP?

Check your services for another active DHCP client (systemd-networkd does DHCP internally).

find /etc/systemd -type l -exec test -f {} \; -print | awk -F'/' '{ printf ("%-40s | %s\n", $(NF-0), $(NF-1)) }' | sort -f

Last edited by -thc (2025-07-09 15:25:03)

Offline

#4 2025-07-10 05:53:55

andrej
Member
Registered: 2012-03-31
Posts: 23

Re: [SOLVED] Help me understand systemd-networkd and default route

I've found a Hetzner specific package called `hc-utils` that did something with networking. Removing that and restarting systemd-networkd seems to have fixed all routing issues. Thanks for the hints.

Offline

Board footer

Powered by FluxBB