Systemd comes with a component named systemd-networkd that you can use in-place of the de facto network manager on most Linux distros, the aptly named networkmanager. Why bother you may ask? If networkmanager works well for you, there is no need in my opinion to use anything else. But for the likes of me who enjoy working mostly in the terminal with minimal GUI apps, systemd-networkd is a simple and robust replacement for networkmanager.
For wired connections, you just need to set up your *.network config file, setting up wireless connections need a little bit more effort as systemd-networkd relies on other services like wpa_supplicant to connect to wifi networks.
NOTE: Only tested on ArchLinux & I can’t make any promises that this guide would work on other Linux distros.
The first step is to stop and disable all running services like networkmanager that you’re currently using to mange your network connections:
After that, you should set up two network configuration files, 50-wired.network (for wired) and 25-wireless.network (for wireless), all configurations for systemd-networkd are stored in the
/etc/systemd/network folder and the network interface for wired and wireless are
The 25 and 50 prefix in the config names are for a reason, this means wired connections would be prioritized over wireless ones, which is what most people would want.
At this point, if all you need is for your wired connection to work, simply start and enable the following systemd services:
For wireless network connections, as mentioned earlier, you need to configure wpa_supplicant and enable its systemd service to get things rolling. Create a config file for your wireless network interface which in my case is
wlp1s0, you can run
iw dev to get your own wireless interface name.
In the above configuration, if you don’t want to use your network password in plain text, run the
wpa_passphrase command line tool to generate your wpa_supplicant config. For example, running
wpa_passphrase MYSSID passphrase will output:
You can then safely remove the
#psk="passphrase" line and then add the rest to your
wpa_supplicant config or just simply run as root:
# wpa_passphrase MYSSID passphrase > /etc/wpa_supplicant/wpa_supplicant-wlp1s0.conf
From the man page of wpa_supplicant. it is noted that:
The priority of a network when selecting among multiple networks; a higher value means a network is more desirable. By default networks have priority 0. When multiple networks with the same priority are considered for selection, other information such as security policy and signal strength are used to select one.
All that needs doing after this is to enable and start the corresponding systemd service for your wpa_supplicant config, remembering to disable any existing wpa_supplicant to avoid any issues. For the one we made, it would be:
You should now be connected to your chosen wifi network, if you have any issues, you can check the status of the networkd and wpa_supplicant systemd service units: