Simplify Linux networking with systemd-networkd

No! Not another flipping network tool!

If you’ve been using Linux for as long as I have, then first: you’re old. Old people tend to be resistant to change. It’s not because we get more conservative as we age (although I’ve heard that one before). I think it’s two things:

  1. Time speeds up when you’re older
  2. You stop tweaking your OS and want it to “just work” So no more Deviant Art wallpaper or funky themes for me. But also, no changey. This systemd-networkd thing should be hurty, so why do I like it?

Systemd doesn’t suck any more

It’s ok accept systemd and move on.

systemd-networkd feels oldschool

Remember when you could edit a .conf file and restart a service? Networking on Linux hasn’t been like that for decades. So systemd-networkd is a breath of fresh air.

Installing

Use your OS package manager to install systemd-networkd Then uninstall whatever other thing you were using (NetworkManager, WICD, wicked)

Default configs: /lib/systemd/network

The default configs in /lib/systemd/network may automatically handle ethernet, but they won’t handle wireless. Don’t mess with these files though! If you want to override a file, it’s better to copy it to /etc/systemd/network and edit it there, because the systemd-networkd package owns the ones under /lib, and it will nuke your edits the next time you upgrade the package.

Your configs: /etc/systemd/network/

eth0 dhcp for ipv4, disable ipv6

/etc/systemd/network/ethernet.network

[Match]
Name=eth0

[Network]
DHCP=yes
LinkLocalAddressing=no
IPv6AcceptRA=no

bridge device

First, you need to create a new device: /etc/systemd/network/bridge.netdev

[NetDev]
Name=br0
Kind=bridge

You can install bridge-utils and use these to inspect the bridge. To configure the br0 network, create another file: /etc/systemd/network/bridge.network

[Match]
Name=br0

[Network]
Address=192.168.0.3/24
Gateway=192.168.0.1
DNS=192.168.0.1

At this point, you should be seeing a pattern. A configuration file can match a device name or type. Its network section can use DHCP or a static configuration

The final step is to add devices to the bridge: /etc/systemd/network/bridged-devices.network

[Match]
Name=eth0 wlan0

[Network]
Bridge=br0

Ordering is very important, when you’re creating a bridge:

  1. Create devices (ethernet and wireless s important to note that these devices should exist first, then the bridge network, and finally the bridged-devices.

Using hostapd? Make sure it starts after the wireless device

This should be handled by your OS, but may not be. If hostapd fails to start because the device is missing, you might get a systemctl status like this:


BindsTo=sys-subsystem-net-devices-wlan0.device After=sys-subsystem-net-devices-wlan0.device ```