SYNOPSYS

I’ve recently migrated my archlinux init scripts from the beloved BSD based shell scripts, to a pure systemd architecture.
I’m not in love with the new hipe stuff, but systemd is well designed and fast, time to move on.
Saddly stock scripts only support DHCP, and I like having my stations relying on static IP.
I just read this and this Lennart goes too far, fun is about to come…

PROCEDURE

/etc/conf.d/network

1
2
3
4
5
interface=eth0
address=192.168.0.100
netmask=255.255.255.0
broadcast=192.168.0.255
gateway=192.168.0.1

/etc/resolvconf.conf

1
2
3
resolv_conf=/etc/resolv.conf
search_domains=lan
name_servers=192.168.0.1

/usr/lib/systemd/system/network.service

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
[Unit]
Description=Network Connectivity
Wants=network.target
Before=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/network
ExecStart=/sbin/ip link set dev ${interface} up
ExecStart=/sbin/ip addr add ${address}/${netmask} broadcast ${broadcast} dev ${interface}
ExecStart=/sbin/ip route add default via ${gateway}
ExecStop=/sbin/ip addr flush dev ${interface}
ExecStop=/sbin/ip link set dev ${interface} down

[Install]
WantedBy=multi-user.target

as root

1
2
3
4
5
systemctl stop dhcpcd@eth0.service
systemctl disable dhcpcd@eth0.service
resolvconf -u
systemctl start network.service
systemctl enable network.service