6

I recently set up a server with its network managed directly by systemd-networkd (nuked netplan.io and Network Manager) and gave it static IPs like this:

/etc/systemd/network/10-ethernet.network

[Match] Name=eno1 [Network] Address=192.168.1.2/24 Gateway=192.168.1.1 DNS=192.168.1.1 

After restarting systemd-networkd.service, default routes look like this:

default via 192.168.1.1 dev eno1 proto static default via 172.16.0.1 dev eno2 proto static default via 172.31.255.1 dev eno3 proto static ^^^ 

Because there are multiple NICs and I want to make eno1 the preferred one, I want the routes laid out like this:

default via 192.168.1.1 dev eno1 proto static metric 100 default via 172.16.0.1 dev eno2 proto static metric 300 default via 172.31.255.1 dev eno3 proto static metric 500 ^^^^^^^^^^ 

Without the metric value, it default to 0, meaning all routes have the same priority (highest), which I want to avoid.

I've tried this setting:

[Route] Gateway=192.168.1.1 Metric=100 

But it only generates an extra route with the desired metric while the original ones (missing metric) still remaining.

I'm running on Systemd 240. How should I achieve this?

1
  • Wait, I've started a bounty, but maybe I misunderstand the question. What happens if you only specify one of the two Gateways, on either [Route] or [Network]? Commented Dec 22, 2019 at 6:25

1 Answer 1

8
+50

In this thread you can see the developers talking about how things work vs. how things should work: https://github.com/systemd/systemd/issues/928

They give a couple examples:

Under the Route tag

[Route] Destination=192.168.0.0/24 Metric=2048 

Under the DHCP tag

[DHCP] RouteMetric=1024 

It is explained that:

subnet routes are configured with no metric via address_configure in networkd-address.c when obtaining an IP and dhcp-provided routes with metric are processed later via link_set_dhcp_routes in networkd-dhcp4.c

Further there is a caveat:

the RouteMetric works for routed packets, but not for those that remain on the local subnet

It's possible that the exact functionality you want doesn't exist yet as the ticket I cited is currently open. Feel free to give feedback directly to the developers and join the discussion if you think you have an idea about how this should be working.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.