SYNOPSYS

I have 2 network interfaces and very simple routing needs.
Let’s try systemd-networkd.

SCHEMATICS

systemd-networkd must be running,
links can be configured through *.link files.
network is configured through *.network files.

PROCEDURE

First replace dhcpcd.service with systemd-networkd network configuration.
/etc/systemd/network/en.network

1
2
3
4
5
[Match]
Name=en*

[Network]
DHCP=v4

Then build a unit to mess with routing tables.
/etc/systemd/system/route.service

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
[Unit]
Description=Route tunning
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/route.conf
ExecStart=/usr/bin/ip route del default via ${gateway}
ExecStart=/usr/bin/ip route add ${net1} dev ${eth}
ExecStart=/usr/bin/ip route add ${net2} dev ${eth}
ExecStop=/usr/bin/ip route add default via ${gateway}
ExecStop=/usr/bin/ip route del ${net1} dev ${eth}
ExecStop=/usr/bin/ip route del ${net2} dev ${eth}

[Install]
WantedBy=multi-user.target

Finally, the big switch.
switch from dhcp to systemd-networkd

1
2
3
4
systemctl disable dhcpcd.service
systemctl enable systemd-networkd
systemctl enable systemd-networkd-wait-online.service
systemctl enable route.service