3

Basically the title says it all, what would be the equivalent to

ip rule add from 10.10.0.10/32 table 2
ip rule add to 10.10.0.10/32 table 2

in systemd-networkd?

I tried to setup something like

[Route]
Destination 10.10.0.10/32
Table=2

but this is not doing the trick and the manpages do not mention anything in this regards.

2 Answers 2

8

If you have systemd 235 or higher, you can use the following:

[RoutingPolicyRule]
From=10.10.0.10/32
Table=2

[RoutingPolicyRule]
To=10.10.0.10/32
Table=2

Full documentation can be found here.

3
  • On Debian Stretch this only leads to an error: Unknown section 'RoutingPolicyRule'. Ignoring. Jan 24, 2018 at 5:49
  • 2
    @Sprinterfreak Like I said this only works if you have systemd 235 or higher. Debian Stretch is still at systemd 232.
    – Blaok
    Jan 25, 2018 at 6:32
  • /32 (4) or /128 (6) can be omitted.
    – iBug
    Feb 1, 2020 at 17:02
2

As you may have already realized, there is currently no way to to this with systemd-networkd alone.

You can create a oneshot service unit like this:

[Unit]
Description=Configure routes
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/sbin/ip rule add from 10.10.0.10/32 table 2
ExecStart=/sbin/ip rule add to 10.10.0.10/32 table 2
ExecStop=/bin/true

[Install]
WantedBy=network.target

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.