Where does the configuraiton in /run/systemd/network come from in a fresh install of 22.04 server?

I have run the following sudo find / -type f -name "*.network" -not -path "/var/lib/docker/*" to show all the .network files on a fresh 22.04 server install.

Aside from the .network files under /run/systemd/network/ I don’t see any other .network files on the system.

Given that /run is tempfs, where is the configuration that I can see in the .network files in /run/systemd/network/ coming from, hard coded defaults in the source code of networkd?

Asked By: Chris Magnuson

||

The default networking setup for Ubuntu 22.04 Server is to use the Netplan utility to configure and manage networking through YAML files located in /etc/netplan/.

The history and general use of Netplan with Ubuntu can be read in the article, A declarative approach to Linux networking with Netplan.

In this article, it states that Netplan will generate network configuration files in /run/systemd/network/.

Netplan takes declarative YAML files from /etc/netplan/ as an input
and generates corresponding network configuration for the relevant
network stack backend in /run/systemd/network/ or /run/NetworkManager/
depending on the system configuration.

The system service, systemd-networkd, is the backend renderer that manages networks and reads configuration files in /usr/lib/systemd/network, /run/systemd/network, and /etc/systemd/network.

From the systemd-networkd man page:

systemd-networkd is a system service that manages networks. It
detects and configures network devices as they appear, as well as
creating virtual network devices.

And…

The configuration files are read from the files located in the
system network directory /usr/lib/systemd/network, the volatile
runtime network directory /run/systemd/network and the local
administration network directory /etc/systemd/network.


For a practical example:

Look in the /etc/netplan/ directory. There’s a file named something like, 00-installer-config.yaml. Edit this file to change your network settings. Afterwards, run sudo netplan apply to apply these changes. Then look in /run/systemd/network/ directory for a file named something like 10-netplan-enp0s3.network. Inspect the contents of this file and you’ll see the changes you made in your Netplan YAML configuration file.


More info about Netplan can be read at the following pages:

More info about systemd-networkd can be found at the man page linked above as well as the Arch Linux Wiki: systemd-networkd

Answered By: mpboden