I have a server instance with two interfaces, and I have created a rule to ensure traffic that comes in ens160 goes out ens160 despite matching the default route for ens192.

The routes and rules work as desired when created by hand using ip, when applied by netplan netplan apply, but not when systemd-networkd is restarted with the netplan-generated config files. Specifically, the rule is not applied.

netplan.yaml:

network:
    ethernets:
        ens160:
            addresses:
            - 192.168.1.238/26
            - 192.168.1.240/26
            - 192.168.1.241/26
            dhcp4: false
            gateway4: 192.168.1.193
            routes:
            - to: 0.0.0.0/0
              via: 192.168.1.193
              table: 200
            routing-policy:
            - from: 192.168.1.192/26
              table: 200
        ens192:
            addresses:
            - 10.125.210.38/23
            dhcp4: false
    version: 2

/run/systemd/network/10-netplan-ens160.network:

[Match]
Name=ens160

[Network]
Address=192.168.1.238/26
Address=192.168.1.240/26
Address=192.168.1.241/26
Gateway=192.168.1.193

[Route]
Destination=0.0.0.0/0
Gateway=192.168.1.193
Table=200

[RoutingPolicyRule]
From=192.168.1.192/26
Table=200

ip route list:

default via 192.168.1.193 dev ens160 proto static
10.125.210.0/23 dev ens192 proto kernel scope link src 10.125.210.38
192.168.1.192/26 dev ens160 proto kernel scope link src 192.168.1.238

ip route list table 200:

default via 192.168.1.193 dev ens160 proto static

After netplan apply, ip rule list (this config works):

0:  from all lookup local
0:  from 192.168.1.192/26 lookup 200
32766:  from all lookup main
32767:  from all lookup default

However, after systemctl restart systemd-networkd

0:  from all lookup local
32766:  from all lookup main
32767:  from all lookup default

systemd log after restarting systemd-networkd:

Nov 20 17:30:28 lb1 systemd[1]: Stopping Network Service...
Nov 20 17:30:28 lb1 systemd[1]: Starting Network Service...
Nov 20 17:30:28 lb1 systemd-networkd[1810]: ens192: Gained IPv6LL
Nov 20 17:30:28 lb1 systemd-networkd[1810]: ens160: Gained IPv6LL
Nov 20 17:30:28 lb1 systemd-networkd[1810]: Enumeration completed
Nov 20 17:30:28 lb1 systemd[1]: Started Network Service.
Nov 20 17:30:28 lb1 systemd-networkd[1810]: ens160: Link is not managed by us
Nov 20 17:30:28 lb1 systemd-networkd[1810]: lo: Link is not managed by us
Nov 20 17:30:28 lb1 systemd-networkd[1810]: lo: Link is not managed by us
Nov 20 17:30:28 lb1 systemd-networkd[1810]: ens192: Configured
Nov 20 17:30:28 lb1 systemd-networkd[1810]: ens160: Configured

Update 1: Issuing two systemctl restart systemd-networkd applies the rule after the second invocation. One more and it goes away. Wut. Logs show it being applied, not explicitly though, each time:

Nov 20 18:57:52 lb1 systemd-networkd[1461]: ens160: Setting routing policy rules
Nov 20 18:57:52 lb1 systemd-networkd[1461]: ens160: Setting routes
Nov 20 18:57:52 lb1 systemd-networkd[1461]: ens160: Routing policy rule configured
Nov 20 18:57:52 lb1 systemd-networkd[1461]: ens160: Routes set
Nov 20 18:57:52 lb1 systemd-networkd[1461]: ens160: Configured

Update 2: successive netplan apply also toggle the rule in and out.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.