The one where I leave it to systemd-networkd

Published:
January 31, 2024

I like keeping my Debian 12 installation bare bones. Sometimes bare bones means accidentally disabling your only link to the outside world.

Among other recent cleanup operations, I managed to make my Ethernet interface (enp7s0) not go up automatically anymore after booting my machine. Jogging my memory of what I might have done on the previous day, I recalled trying to purge Gnome-related utilities. Among those was the Gnome NetworkManager, which even without a GUI or Desktop Environment (I don’t use Gnome) will still try to configure network interfaces in the background. As a consequence, my Ethernet interface would not go up automatically anymore.

The idea of needing a Desktop Environment to enjoy the side-effect of having a working network interface is perplexing. I’d rather leave it something that works, independent of a graphical user interface.

But, I got tired of having to run

ip link set enp7s0 up
dhclient enp7s0

every time I start my computer, and I began to investigate what other means of automatically configuring the interface and especially acquiring a DHCP lease exist. Many Linux distributions use Systemd as their PID 1. Since Systemd is an all-embracing kraken, it also happens to manage network interfaces. Since I vaguely remember enabling some systemd units before like so

# Yours truly scoured StackOverflow and blog spam to come up with these
# incantations
sudo systemctl enable --now systemd-networkd.service
sudo systemctl enable --now systemd-networkd-wait-online@enp7s0.service

and still not seeing the desired result of my interface being configured (perhaps I expect too much magic), I set out to actually Read The Damn Manual.

Here’s everything you will ever want to know about networkd in systemd, courtesy of www.freedesktop.org:

The important bits for me were:

  1. I had to see what networkd sees in my system right now, then
  2. tell it to manage the interfaces using a systemd.network file, and finally
  3. reload and apply any new configuration.

To query the current state of networkd, I ran networkctl list and saw the following:

IDX LINK   TYPE     OPERATIONAL SETUP
  1 lo     loopback carrier     unmanaged
  2 enp7s0 ether    routable    unmanaged

The interface connected to my network is enp7s0, and it is not managed by networkd (unmanaged) and instead brought up manually by me using ip link set enp7s0 up and dhclient enp7s0. Networkd acknowledges the presence of the interface, but hasn’t been barked at by a config file to manage it for me, yet. The networkctl manual tells us about the meaning of unmanaged:

unmanaged systemd-networkd is not handling the link.

Let’s fix that, and you will see it’s simple. (but not easy, it only presents itself once you know about all the moving parts)

To tell systemd-network to manage an interface, I created the file 10-ethernet.network in /etc/systemd/network, and copied the following contents from /usr/lib/systemd/network/80-ethernet.network.example.

# /etc/systemd/network/10-ethernet.network
# SPDX-License-Identifier: MIT-0
#
# This example config file is installed as part of systemd.
# It may be freely copied and edited (following the MIT No Attribution license).

# Enable DHCPv4 and DHCPv6 on all ethernet links
[Match]
Type=ether
# If we want to be really fancy we could match for enp7s0 like so
Name=enp7s0

[Network]
DHCP=yes

After which, I just had to run networkctl reload. I query the status again using networkctl list and get the desired result:

IDX LINK   TYPE     OPERATIONAL SETUP
  1 lo     loopback carrier     unmanaged
  2 enp7s0 ether    routable    configured

2 links listed.

Finally, running networkctl status shows us the following:

‚óŹ        State: routable
  Online state: online
       Address: 10.0.56.202 on enp7s0
                fe80::dabb:c1ff:fed0:357c on enp7s0
       Gateway: 10.0.48.1 on enp7s0
           DNS: 10.0.48.1

Beautiful. And that’s it! Let’s see if it holds up after a reboot.

I would be thrilled to hear from you! Please share your thoughts and ideas with me via email.

Back to Index