How to add a static route in systemd-networkd?

How to add a static route in systemd-networkd?

– Unix & Linux Stack Exchange How to add a static route in systemd-networkd? 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.

How to change the Order of the default gateway?

Instead of defining the default Gateway in the [Network] section you can add a default route with a lower metric to the static interface: After this you can do the same for a DHCP interface (note that you don’t have to define the Gateway because this will be provided by your DHCP server):

What should the default route metrics be in systemd-networkd?

After restarting systemd-networkd.service, default routes look like this: Because there are multiple NICs and I want to make eno1 the preferred one, I want the routes laid out like this: Without the metric value, it default to 0, meaning all routes have the same priority (highest), which I want to avoid.

Which is the default gateway for the routing table?

Now the problem is that the routing table is generated with 162.132.192.252 (from net0) as the default gateway, but I would like the gateway from eth0 to be the default gateway.

Which is the network file in systemd-networkd?

A plain ini-style text file that encodes network configuration for matching network interfaces, used by systemd-networkd (8). See systemd.syntax (7) for a general description of the syntax. The main network file must have the extension .network; other extensions are ignored.

When does systemd.network not match all interfaces?

When a network file does not contain valid settings in [Match] section, then the file will match all interfaces and systemd-networkd warns about that.

Which is the DHCP gateway for systemd networkd?

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).