Systemd – Configure Your Network With Networkd

Systemd-networkd is a network configuration manager in systemd.
It can manage the networks of a Linux system, and configure network devices.
Its configuration is based on INI-style configuration files.

Systemd-networkd can be managed at runtime using the networkctl tool.

In this example you create a network bridge device.

Physical device: enp1s0
Bridge device: bridge0
Interface IP: 10.10.0.10/24

You have to change this information for your own system.

Create the following files in /etc/systemd/network/:

sudo touch /etc/systemd/network/10-bridge0.netdev
sudo touch /etc/systemd/network/20-enp1s0.network
sudo touch /etc/systemd/network/30-bridge0.network

Configuration files are processed in lexicographical order.
For .network files, the first matching file is applied to an interface.

Create the bridge network device in /etc/systemd/network/10-bridge0.netdev with
the following configuration:

[NetDev]
Name=bridge0
Kind=bridge

Attach your physical network interface to the bridge by configuring /etc/systemd/network/20-enp1s0.network:

[Match]
Name=enp1s0
[Network]
Bridge=bridge0

Configure the bridge0 interface in /etc/systemd/network/30-bridge0.network:

[Match]
Name=bridge0
[Network]
Address=10.10.0.10/24
Gateway=10.10.0.1
DNS=8.8.8.8

Check your existing network configuration.
Depending on your installation, the enp1s0 interface might already be configured
through ifupdown (/etc/network/interfaces) or NetworkManager.

Make sure the interface is not managed by another network management service.
Remove or disable the conflicting configuration before proceeding.

Warning:

Switching network management services remotely is a potentially disruptive operation.
If the bridge configuration fails, you might lose SSH access.

Enable and start systemd-networkd:

sudo systemctl enable --now systemd-networkd

Verify your configuration:

sudo networkctl list
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback carrier unmanaged
2 enp1s0 ether enslaved configured
3 bridge0 bridge routable configured

Check your bridge’s status:

sudo networkctl status bridge0

If the system uses systemd-resolved, you should enable it too:

sudo systemctl enable --now systemd-resolved

Where appropriate, configure /etc/resolv.conf to point to the systemd-resolved stub resolver:

sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf

Don’t blindly execute the symlink command on an existing system.
Check the current /etc/resolv.conf arrangement first.

  1. systemd-networkd configures the interface and supplies DNS configuration.
  2. systemd-resolved handles DNS resolution.

Reload the configuration:

sudo networkctl reload

If you have to reconfigure a relevant interface:

sudo networkctl reconfigure bridge0
sudo networkctl reconfigure enp1s0

You can reboot the server to see if the config survives it:

sudo reboot

The machine should boot up with the expected interface configuration.

Alternatively, you can configure the bridge to obtain its network configuration through DHCP:

[Network]
DHCP=yes

Final Thoughts

If you need more help, use:

  • man systemd-networkd for general help.
  • man systemd.network for network configuration.
  • man systemd.netdev for device settings.
  • man networkctl for run time operations.

You can join our private IRC network at irc.silentarchitect.org/6697
or visit our Discord server at https://discord.gg/nxvna45STM.


Discover more from Tom's IT Cafe

Subscribe to get the latest posts sent to your email.

Leave a signal