I decided to switch the network manager from netctl to systemd-networkd on a whim during the night and the switch went smoothly. This article documents the switching process and briefly describes how the combination of systemd-networkd + iwd works.

Introduction

netctl

netctl is archlinux’s own son, upstream at https://git.archlinux.org/netctl.git/, and is the only network management tool other than systemd-networkd to access the base group. netcl relies on dhcpcd or dhclient It relies on dhcpcd or dhclient to obtain dynamic IP addresses, wpa_supplicant to access encrypted WiFi, and wifi-menu to interactively select hotspots and enter passwords from the command line. A series of systemd service files (netctl@.service, netctl-ifplugd@.service, netctl-auto@.service) are also provided to help users configure, e.g. after enabling netctl-auto@< interface>.service, your NIC can be automatically switched in the optional profile.

systemd-networkd

As its name implies, this is a member of the systemd family. It is primarily responsible for detecting and configuring network devices, and in particular it can be used to configure the network of containers started by systemd-nspawn.

iwd

iwd (iNet wireless daemon) is a WiFi backend developed by Intel to replace wpa_supplicant. Its main goal is to optimize resource utilization by not relying on any external libraries but by maximizing the functionality provided by the Linux kernel. iwd works well with systemd-network.

Usage Scenario Introduction

I don’t need to switch/add/modify/delete Wi-Fi configuration frequently, so I don’t need a service that is resident in the notification area to switch. Also, my VPN is already fully managed through systemd, so I don’t need a network management tool to do that for me. What I need is a combination of tools: one for managing network devices and one for connecting to WiFi and authenticating. The previous combination was netctl + wpa_supplicant, but now I have a new favorite: systemd-networkd + iwd.

How to use

Disabling netctl

First you need to disable the services associated with netctl to avoid conflicts between multiple network management tools together.

1
2
:) systemctl stop netctl-auto@<interface>.service
:) systemctl disable netctl-auto@<interface>.service

Configure the network card

Then follow the Wiki instructions to write the configuration for the wireless NIC under /etc/systemd/network.

For the wireless NIC, the minimal configuration is as follows.

1
2
3
4
5
[Match]
Name=wlp2s0

[Network]
DHCP=ipv4
  • Match is mainly used to match the managed devices, which can be selected by device name, MAC address, etc.
  • Network is used for network related specific configuration, such as DHCP, DNS, etc.

I have coredns enabled locally as a DNS service, so I need to add some extra configuration to get IPv4 addresses via DHCP, but not use the DNS issued by DHCP.

1
2
3
4
5
6
7
8
9
[Match]
Name=wlan0

[Network]
DHCP=ipv4
DNS=127.0.0.1

[DHCP]
UseDNS=false

iwd seems to change the name of the network device when it starts, and my NIC was changed to wlan0.

After the configuration is written, you can start the systemd-networkd service.

1
:) systemctl start systemd-netword

If you have changed the network configuration, just restrart it.

For more specific configuration, see ArchWiki or man systemd-networkd.

Configuring iwd

iwd is not a self-contained package, so you need to install it yourself first.

1
:) pacman -S iwd

Before we can start using it, we need to start and enable the iwd service.

1
2
:) systemctl start iwd
:) systemctl enable iwd

Then you can use iwctl to manage it. iwctl enters an interactive command line interface by default, which is still a great experience.

1
2
:) iwctl
[iwd]#

At this point, entering help will return all supported commands, each command is relatively intuitive, as long as a little understanding of the technical terms related to WiFi can quickly get started, in addition, all commands in this interface support auto-completion, praise.

First of all, let’s see what devices we have.

1
2
3
4
5
6
[iwd]# device list
Devices                                   *
--------------------------------------------------------------------------------
Name                Address             Powered   Adapter   Mode
--------------------------------------------------------------------------------
wlan0               xx:xx:xx:xx:xx:xx   on        phy0      station

The interface is dynamic and the * in the upper right corner will keep flashing to indicate that the interface is live.

We can then manually trigger an STA scan.

1
[iwd]# station wlan0 scan

After that, you can see what WiFi hotspots are available for connection.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
[iwd]# station wlan0 get-networks
                               Available networks                             *
--------------------------------------------------------------------------------
    Network name                    Security  Signal
--------------------------------------------------------------------------------
    CU_SNZQ                         psk       ****
    xjzy                            psk       ****
    Tenda_30BDD0                    psk       ****
    TP-LINK_D82B80                  psk       ****
    TP-LINK_lee                     psk       ****
    ziroom201                       psk       ****
    mhshome                         psk       ****
    TP-LINK_he                      psk       ****
    TP-LINK_450C                    psk       ****
    yuzhe                           psk       ****
    z212-202                        psk       ****
    Bill's Router                   psk       ****
    tcs                             psk       ****
  > XXXXXXXXXXX                     psk       ****

This interface is also dynamic and allows you to check the signal strength of the machines that are currently connected to the network.

Finally, you will be able to select the SSID you want to connect to the network, and if you need to enter a password, iwd will also show a prompt to enter the password.

1
[iwd]# station wlan0 connect XXXXXXXXXXX

Here is a point that needs to be raised: after iwd successfully connects to the network through the interactive interface, it automatically generates the corresponding configuration file under /var/lib/iwd, and then iwd connects automatically. So on the one hand, you don’t need to write the configuration file manually, and on the other hand, the switching process is automatic and does not require manual intervention.

The configuration file name generated by iwd has certain rules, using SSID as the file name, and then using encryption as the suffix, e.g. *.open means it is an open network, and *.psk means it is a network using PSK encryption.

Check the status

After all the configurations are done, you can check the status of WiFi and NIC separately.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
:) iwctl device wlan0 show
                                 Device: wlan0
--------------------------------------------------------------------------------
  Settable  Property            Value
--------------------------------------------------------------------------------
            Name                wlan0
         *  Mode                station
         *  Powered             on
            Address             xx:xx:xx:xx:xx:xx
         *  WDS                 off
            Adapter             phy0
:) networkctl status
●        State: routable
       Address: 192.168.0.103 on wlan0
                xxxx::xxxx:xxxx:xxxx:xxxx on wlan0
       Gateway: 192.168.0.1 (TP-LINK TECHNOLOGIES CO.,LTD.) on wlan0
           DNS: 127.0.0.1

Reference

  • https://wiki.archlinux.org/index.php/Systemd-networkd
  • https://wiki.archlinux.org/index.php/Iwd
  • https://xuanwo.io/2019/06/13/switch-to-systemd-networkd/