Systemd-networkd

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
[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 ${network} dev ${etx}
ExecStop=/usr/bin/ip route add default via ${gateway}
ExecStop=/usr/bin/ip route del ${network} 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