In /lib/systemd/network/10-eth0.network
on my client, I am failing to configure anything that can translate my manual command:
sudo ip route add default via 192.168.7.1 dev eth0
where 192.168.7.1
is the static IPv4 address of my host.
My last 10-eth0.network
configuration attempt:
[Match]
Name=eth0
[Link]
RequiredForOnline=no
[Route]
Address=192.168.7.2/24
Destination=192.168.7.1/32
Gateway=192.168.7.1
Refreshed with sudo systemctl restart systemd-networkd
and validated with ip route
(it doesn't show up).
See also:
[Route]
Section Options- Answers that aren't working: systemd-networkd and direct routes
You didn't specify anywhere that it's supposed to be the default route; instead you have
Destination=192.168.7.1/32
– which is the complete opposite of adefault
route... as well as being a cyclical (self-referencing) route. According to your configuration, it probably shows up as a192.168.7.1/32 dev eth0
in your route output (that would be the effective interpretation assuming the kernel doesn't reject it).The default route is always
0.0.0.0/0
, i.e. a lowest-precedence catch-all route, and that's what you need to define as theDestination=
. (Alternatively you can omit Destination= entirely.)A route via
Gateway=192.168.7.1
can only be defined if you are in the same subnet. For that, make sure that theAddress=192.168.7.2
parameter is either in an[Address]
section or in the[Network]
section – it makes no sense in the [Route] section.