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.

cynexit
  • 31
  • 1
  • 3

2 Answers2

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.

Blaok
  • 116
  • 1
  • 2
  • 4
  • On Debian Stretch this only leads to an error: `Unknown section 'RoutingPolicyRule'. Ignoring.` – Sprinterfreak Jan 24 '18 at 05:49
  • 2
    @Sprinterfreak Like I said this only works **if you have `systemd` 235 or higher**. [Debian Stretch is still at `systemd` 232](https://packages.debian.org/stretch/systemd). – Blaok Jan 25 '18 at 06:32
  • `/32` (4) or `/128` (6) can be omitted. – iBug Feb 01 '20 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
weinrea
  • 21
  • 2