Index ¦ Archives ¦ Atom

Using systemd-networkd with wpa_supplicant to manage wireless network configuration

As of version 210, systemd now includes support for basic network configuration through udev and networkd. Systemd-networkd is a system daemon that manages network configuration. It detects and configures network devices as they appear, as well as creates virtual network devices.

There are a lot of tools for managing wireless network (i.e. wifi) configuration for linux: connman, netcfg, netifd, NetworkManager, WICD, wicked, etc…

They sometimes do a worse job than the underlying tools themselves will do when used directly, for example with roaming. Here I’ll describe my network setup that uses wpa_supplicant and systemd-networkd and works seamlessly.

Systemd-networkd configuration

Systemd-networkd uses /etc/system/network/ for configuration files. It is not intended to configure low-level settings of network interfaces as this remains udev’s job.

Any .network file present in /etc/system/network/ will apply a network configuration for a matching device. I currently have two files in this directory, eth.network and wlp2s0.network. There structure is pretty self-explanatory:

/etc/systemd/network/eth.network

1
2
3
4
5
6
[Match]
# Will match eth0, eth1, ethX…
Name=eth*
[Network]
# This will start DHCP on each interface whose name starts with eth
DHCP=yes

/etc/systemd/network/wlp2s0.network

1
2
3
4
[Match]
Name=wlp2s0
[Network]
DHCP=yes

Refer to systemd.network (5) for more informations.

wpa_supplicant configuration

Wpa_supplicant will be used for roaming and connection to wireless network. Here is my {basic,classic} configuration:

/etc/wpa_supplicant/wpa_supplicant-wlp2s0.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
ctrl_interface=/var/run/wpa_supplicant
eapol_version=1
ap_scan=1
fast_reauth=1

network={
    ssid="Foobar1"
    psk="password1"
    priority=1
}
network={
    ssid="Foobar2"
    psk="password2"
    priority=2
}

I usually add new network to this file using this command: wpa_passphrase <ESSID> <passphrase> >> wpa_supplicant-wlp2s0.conf

By enabling systemd-networkd.service and wpa_supplicant@wpl2s0.service, wpa_supplicant will automatically connect to any network available on the wlp2s0 interface, as configured in the wpa_supplicant-wlp2s0.conf file, bringing up the wlp2s0 interface. Since this interface is matched by the systemd-networkd configuration, the support for dhcpv4 will be enabled and this interface will get an ip. And if one wireless AP suddenly disappears, wpa_supplicant will handle the roaming.

By enabling systemd-resolved.service, systemd will automatically configure /run/systemd/network/resolv.conf when using DHCP instead of your /etc/resolv.conf. As stated in the man page of systemd-resolved, as /run/systemd/network/resolv.conf should not be used directly but only through a symlink from /etc/resolv.conf, I made a symlink.

It just works. And since you cannot use Archlinux without systemd nowadays, due to its viral nature, well, I’m using it.

References:

© Rémy Grünblatt 🍃. Built using Pelican. Theme by Giulio Fidente on github.