systemd-networkd doesn’t just assign IP addresses; it orchestrates network connectivity by defining the lifecycle of network devices and their associated configurations.
Let’s see it in action. Imagine you have a server with two network interfaces, eth0 and eth1. You want eth0 to get an IP address via DHCP, and eth1 to have a static IP address.
First, you need to tell systemd-networkd about your interfaces. Create a file named /etc/systemd/network/20-wired.network. The 20 in the filename determines the order of application, ensuring this configuration is applied before any later ones.
[Match]
Name=eth0
[Network]
DHCP=ipv4
This configuration tells systemd-networkd to match the interface named eth0 and to request an IPv4 address using DHCP.
Now, for the static configuration on eth1. Create another file, /etc/systemd/network/20-static.network:
[Match]
Name=eth1
[Network]
Address=192.168.1.100/24
Gateway=192.168.1.1
DNS=8.8.8.8
This config matches eth1, assigns it the static IP address 192.168.1.100 with a /24 subnet mask, sets the default gateway to 192.168.1.1, and specifies Google’s public DNS server 8.8.8.8.
After creating these files, you need to enable and start the systemd-networkd service:
sudo systemctl enable systemd-networkd
sudo systemctl start systemd-networkd
To apply the new configurations without rebooting, you can tell systemd-networkd to re-read its configuration and re-configure the network:
sudo networkctl reload
Or, if you want to be more specific and just reconfigure the interfaces:
sudo networkctl reconfigure eth0
sudo networkctl reconfigure eth1
You can verify the status of your interfaces with networkctl status:
IDX LINK STATE FROM PROTOCOL
1 lo routable - loopback
2 eth0 routable - inet,inet6
3 eth1 routable - inet,inet6
And to see the IP addresses and other details:
networkctl status eth0
Output might look like:
● eth0
Current state: routable
Address: 192.168.0.50/24 (DHCP)
fe80::a00:27ff:fe4b:1234/64 (DHCPv6)
Gateway: 192.168.0.1
DNS: 192.168.0.1
And for eth1:
networkctl status eth1
Output might look like:
● eth1
Current state: routable
Address: 192.168.1.100/24
fe80::a00:27ff:fe4b:5678/64
Gateway: 192.168.1.1
DNS: 8.8.8.8
systemd-networkd manages network configuration by applying .network files based on their lexicographical order and the [Match] criteria. When a .network file is processed, systemd-networkd attempts to bring up the interface according to the settings in the [Network] section. For DHCP, it interacts with a DHCP client (often dhclient or systemd-networkd’s built-in client). For static configurations, it directly configures the interface using iproute2 commands under the hood. The [Match] section is crucial; Name= is the most common, but you can also match based on MACAddress=, Driver=, Type=, and Path=, allowing for very granular control over which configuration applies to which device.
One common pitfall is forgetting to disable other network management daemons like NetworkManager or ifupdown (from /etc/network/interfaces) when systemd-networkd is active. They can conflict, with one trying to manage an interface while systemd-networkd also attempts to control it, leading to unpredictable behavior. systemd-networkd operates by default by not managing interfaces unless explicitly configured to do so via a .network file. If you have a default configuration that brings up interfaces, you might need to ensure no other service is interfering.
The next step in mastering systemd-networkd is understanding how to manage multiple IP addresses on a single interface or how to configure VLANs.