1

Why is systemd-network giving a statically configured network the metric 0?

If I configure an interface with DHCP I get the metric 1024:

[Match]
Name=eth0

[Network]
DHCP=ipv4

The output of ip route:

default via 10.245.111.1 dev eth0 proto dhcp src 10.245.111.96 metric 1024

However If I configure the network with a static gateway the metric is 0:

[Match]
Name=eth0

[Network]
Address=10.245.111.96/24
Gateway=10.245.111.1
DNS=10.245.111.1

The output of ip route (no metric meaning 0):

default via 10.245.111.1 dev eth0 proto static
1

You can delete the Gateway= directive from the [Network] section, and specify it in a separate [Route] section, then you can bundle it with a Metric= directive.

From the official documentation: https://www.freedesktop.org/software/systemd/man/systemd.network.html#Gateway=

This is a short-hand for a [Route] section only containing a Gateway key.

A working example for your configuration:

[Match]
Name=eth0

[Network]
Address=10.245.111.96/24
DNS=10.245.111.1

[Route]
Gateway=10.245.111.1
Metric=1024
| improve this answer | |

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.