Home / Exciting tips / Linux / How to set up systemd-networkd on Linux

How to set up systemd-networkd on Linux

Systemd-networkd is a system tool that runs in the background on Linux systems and manages network configurations. It can detect networking devices as they are plugged in and even create virtual networking devices. This tool is especially useful with complex network configurations, such as servers and containers. In this guide, we will go over how to set up systemd-networkd on Linux.

Note: in this guide, we will only be focusing on Ethernet connections. While it is possible to use WiFi with systemd-networkd, it isn’t straightforward to set up, and there are much better tools to use for WiFi on Linux, like Network Manager.

Enabling and starting services

To use the systemd-networkd daemon to handle your networking configurations on Linux, it needs to be turned on. By default, this service is shut off. To turn it on, open up a terminal window on the Linux desktop. Once the terminal window is open, run the systemctl enable command on the systemd-networkd.service file and the systemd-resolved.service file. 

sudo systemctl enable systemd-resolved.service
sudo systemctl enable systemd-networkd.service

Once the two service files are enabled, they will boot up each time the computer turns on. However, if you would like to start using the services now, without rebooting, you can initialize them using the systemctl start command on the two service files previously enabled.

sudo systemctl start systemd-resolved.service
sudo systemctl start systemd-networkd.service

With both services now started, your computer and the systemd init system will be able to see the service and interact with it. To check to see if both service files have started up successfully, make use of the status command.

systemctl status systemd-resolved.service
systemctl status systemd-networkd.service

Look for “active (running)” to confirm that the service file is running successfully. If you do not see “active (running), the service files have not started up correctly. Reboot your Linux PC, and the service file should be active.

Disable NetworkManager

Systemd-networkd does not work if there are other networking tools running. On most Linux operating systems, NetworkManager is the network tool of choice. To disable it, enter the following commands below in a terminal window.

sudo systemctl disable NetworkManager.service
sudo systemctl stop NetworkManager.service

Finding your wired adapter

To use systemd-networkd, you need to locate your wired adapter. The reason you need to identify it is that the adapter needs to be specified in the configuration file for the network connection profile.

On Linux, there are many different ways to figure out what the device ID of your wired adapter is. In this guide, we’ll focus on the networkctl list command. This command is straightforward to read, even for beginner users, and doesn’t cloud the terminal output with tons of useless information.

To figure out what your wired (ethernet) adapter is on Linux, run the following command in a terminal window.

networkctl list | grep ether

Look through the list for your network device. It will likely start with “enp” or “eth.” Ignore devices that begin with “virb” or “vnet” unless you know what you are doing, as those devices are virtual machine networking adapters.

Once you’ve figured out the name of your networking device, open up a second terminal and move on to the next section of the guide.

Creating configuration files

The systemd-networkd configuration process is very easy, which might sound strange, considering it is a command-line network management utility. However, in typical systemd fashion, it is effortless to understand and set up.

In this section of the guide, we will go over how to create a basic configuration file to use ethernet with systemd-networkd. We will not cover more advanced configurations. If you desire a more advanced setup than what is covered in this post, refer to the systemd-networkd manual by running the man systemd-networkd command in a terminal window.

To create a new configuration file for systemd-networkd, launch a terminal window. Once the terminal window is open, run the sudo -s command to elevate the terminal session to the root account.

sudo -s

With the terminal as root, use the touch command to create a new config file in the /etc/systemd/network/ folder.

touch /etc/systemd/network/20-wired.network

After creating the new configuration file, open it up in the Nano text editor for editing purposes.

nano -w /etc/systemd/network/20-wired.network

In the Nano text editor, paste the following code. However, keep in mind that this code needs to be changed, so do not save it until the editing process is complete.

Note: change “ETHERNET-ID” with the name of your wired adapter found in the previous section of the guide.

[Match]Name=ETHERNET-ID

[Network]DHCP=yes

Now that the code is inside of the configuration file save the edits with Ctrl + O and exit with Ctrl + X.

Start using systemd-networkd

Systemd-networkd is configured. Now, it is time to use it. To use systemd-networkd, you will need to run the restart command. This command will reboot the systemd-networkd service so that it can see the new configuration file you’ve created.

systemctl restart systemd-networkd

Upon restarting the service, you should be using your network card with systemd-networkd.

Looking for something else? Check out our list of best Linux network monitoring tools.

About excitingtips

Check Also

How to set up the Jellyfin media server on Linux

Jellyfin is an open-source fork of the Emby media server. They’re very similar in software, …

Leave a Reply

Your email address will not be published. Required fields are marked *