Network Configuration with Systemd-networkd on Ubuntu/Debian / Linux / Debian / Network Configuration with Systemd-networkd on Ubuntu/Debian

Systemd provides the systemd-networkd service that can be used to configure network settings on a Linux machine. In this article, we will look at how to use systemd-networkd to configure a network on Debian/Ubuntu distro as an example.

Check that the systemd version on Linux is at least 210:

$ systemctl --version

The Network Manager is used by default in modern Linux distros for managing network interfaces and settings. Network Manager is usually convenient to use on desktop computers as it has a GUI for all graphical environments, makes it easy to work with WLAN interfaces, and allows you to create and manage VPN connections. Due to its high resource usage, Network Manager is not practical on Linux servers (20 MB vs 2 MB for systemd-networkd).

Check that NetworkManager is running:

$ nmcli connection
$ systemctl status NetworkManager

disable network manager and switch to systemd-networkd

Disable the NetworkManager daemon:

$ sudo systemctl stop NetworkManager
$ sudo systemctl disable NetworkManager

If you have networks configured through /etc/network, you will need to disable the use of network settings from the /etc/network/interfaces file. The easiest way to do this is to simply rename this file:

$ sudo mv /etc/network/interfaces /etc/network/

The systemd-networkd configuration files can be placed in either /etc/systemd/network or /usr/lib/systemd/network (lower priority).

There are three different types of configuration files:

  • .link – describe the physical parameters of interfaces (name, MAC, MTU settings);
  • .netdev – used to configure virtual interfaces and bridges;
  • .network – contain interface network settings (IP, DNS, Gateway)

Let’s create a configuration file with static network settings for the enp0s3 interface. The name of the file can be anything you like, the main thing is that it has the correct extension:

$ sudo mcedit /etc/systemd/network/
Description=Local network
# If you want to use DHCP, leave only the DHCP=yes option.

In the [Match] section, you can set the following options:

  • Name= network interface name (for example enp2s0 or en*). You can get the interface name using the ip a command
  • Hosthostname
  • Virtualization = no (allows you to check whether the operating system is running in a virtual environment)
  • MACAddress=AA:AA:AA:AA:AA:AA

There can be more than one condition in a [Match] section. The network profile will be applied if all the conditions (!!!) in this section are met.

Enable the systemd-networkd:

$ sudo systemctl enable systemd-networkd
$ sudo systemctl start systemd-networkd

Check the status of the network interfaces:

$ networkctl list

View network settings:

$ networkctl status

You must restart networkd after making changes to the network configuration files:

$ sudo systemctl restart systemd-networkd

List systemd-networkd logs:

$ journalctl -u systemd-networkd.service
Leave a Reply

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