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) still tries 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.
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 could ever want to know about networkd in systemd, courtesy of www.freedesktop.org:
- General description of systemd-networkd
- Configure general systemd-network behavior with networkd.conf
- Query and configure managed interfaces using the networkctl command
- Configure individual links using a systemd.link configuration
- Configure networks using a systemd.network configuration
- Configure network name resolution using resolved.conf
The important bits for me were:
- I had to see what networkd sees in my system right now, then
- tell it to manage the interfaces using a
systemd.network
file, and finally - 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’s 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.
Read on to learn how to fix this issue.
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.