Course contentsShow
← Linux
Lesson 619 of 1,8196. Systemd Internals and Unit OrchestrationFree lesson

Network Interface Management

Integrate systemd-networkd for declarative network configuration on server instances.

In this lesson, you will learn how to transition from legacy networking tools to a modern, declarative approach using systemd-networkd.

Why Declarative Networking?

In traditional Linux environments, networking was often managed by a mix of shell scripts, ifupdown, or external daemons like NetworkManager. While powerful, these methods can lead to "configuration drift," where the running state of your network interfaces diverges from your original plan. systemd-networkd solves this by treating network configuration like any other systemd unit: it is declarative, persistent, and tightly integrated into the system lifecycle.

Configuring with .network Files

systemd-networkd looks for configuration files in /etc/systemd/network/. These files are organized into sections using an INI-style syntax, similar to service units. You define a [Match] section to identify which hardware interface the rules apply to, followed by a [Network] section to assign IP addresses, DNS, or gateways.

For example, to configure a static IP on an interface named eth0, you would create /etc/systemd/network/10-static.network:

[Match]
Name=eth0

[Network]
Address=192.168.1.50/24
Gateway=192.168.1.1
DNS=8.8.8.8

Managing the Lifecycle

Because systemd-networkd is a native systemd service, you manage it using the standard systemctl commands you’ve already mastered. After creating or modifying a .network file, you simply restart the service to apply the new state:

sudo systemctl restart systemd-networkd

By using this approach, your network configuration remains predictable across reboots. Because it integrates with the systemd dependency graph, you can ensure that services requiring network access (like a web server) wait until systemd-networkd confirms the interface is "online" before attempting to bind to an address. This eliminates common race conditions where applications fail at boot because the interface wasn't fully initialized.

By aligning your network configuration with the declarative philosophy of systemd, you make your infrastructure significantly easier to audit, debug, and automate.

Key Takeaway: Use declarative .network files in /etc/systemd/network/ to manage interface states predictably and ensure your network configuration integrates directly into the systemd service dependency lifecycle.