systemd-networkd Explained: Declarative Networking Without NetworkManager
NetworkManager is the right answer on a laptop. On a server it is a daemon with a D-Bus API, a client tool and a state database, solving a problem servers do not have: a network that changes.
systemd-networkd is the alternative, and it is three kinds of small config file.
Enabling it
# check what is managing the network now
systemctl status NetworkManager systemd-networkd 2>/dev/null
networkctl list
ip -br addr
# switch, carefully, on a machine you can reach physically
sudo systemctl disable --now NetworkManager
sudo systemctl enable --now systemd-networkd
sudo systemctl enable --now systemd-resolved
Do this with console access available. Disabling the thing managing your network over ssh is how you lose the connection and the ability to fix it. Our new server guide makes the general point and it applies with force here.
Running both at once produces two daemons fighting over interfaces. Pick one.
The three file types
All live in /etc/systemd/network/, with defaults in /usr/lib/systemd/network/.
| Extension | Configures | Applied by |
|---|---|---|
.network | Addresses, routes, DNS | networkd |
.link | Naming, MAC, offloads | udev, early |
.netdev | Virtual devices: bridges, VLANs, bonds | networkd |
A .network file
# /etc/systemd/network/20-wired.network
[Match]
Name=enp3s0
[Network]
DHCP=yes
IPv6AcceptRA=yes
Static, which is the server case:
# /etc/systemd/network/20-wired.network
[Match]
Name=enp3s0
[Network]
Address=10.0.0.10/24
Gateway=10.0.0.1
DNS=10.0.0.1
DNS=1.1.1.1
Domains=internal.example.com
IPv6AcceptRA=no
[Address]
Address=10.0.0.11/24
Label=secondary
[Route]
Destination=192.168.50.0/24
Gateway=10.0.0.254
Metric=100
sudo networkctl reload
sudo networkctl reconfigure enp3s0
networkctl status enp3s0
networkctl reload then reconfigure applies changes without restarting the daemon, which matters on a machine you are connected to.
Match ordering, the usual gotcha
# which file was applied
networkctl status enp3s0 | grep -i 'network file'
ls /etc/systemd/network/ /usr/lib/systemd/network/
Files are processed in lexical order, and the first [Match] that matches wins. A permissive file with a low number shadows everything after it:
# 10-catch-all.network, which would win over 20-wired.network
[Match]
Name=en*
Which is why the convention is to number deliberately, leaving room: 10- for specific hosts, 20- for general interfaces, 99- for a fallback.
Match can key on more than the name:
[Match]
MACAddress=aa:bb:cc:dd:ee:ff
Driver=e1000e
Type=ether
Host=myserver
Virtualization=no
A .link file, for renaming
# /etc/systemd/network/10-rename-wan.link
[Match]
MACAddress=aa:bb:cc:dd:ee:ff
[Link]
Name=wan0
MACAddressPolicy=persistent
.link files are applied by udev, much earlier than .network files. That is why renaming belongs here: by the time networkd runs, the name must already be settled.
Renaming to something meaningful is genuinely useful on a router or firewall, where wan0 and lan0 beat enp3s0 and enp4s0. Our udev guide covers the predictable naming scheme this overrides and our ip command guide covers inspecting the result.
A .netdev file, for virtual devices
# /etc/systemd/network/10-br0.netdev
[NetDev]
Name=br0
Kind=bridge
# /etc/systemd/network/20-br0-bind.network
[Match]
Name=enp3s0
[Network]
Bridge=br0
# /etc/systemd/network/30-br0.network
[Match]
Name=br0
[Network]
DHCP=yes
Three files for one bridge, which is the pattern: create the device, enslave the physical interface, configure the bridge. Our VLANs and bridges guide covers why you would, and this is the cleanest way to express it for a KVM host.
VLANs and bonds follow the same shape:
# /etc/systemd/network/10-vlan100.netdev
[NetDev]
Name=vlan100
Kind=vlan
[VLAN]
Id=100
# /etc/systemd/network/10-bond0.netdev
[NetDev]
Name=bond0
Kind=bond
[Bond]
Mode=802.3ad
LACPTransmitRate=fast
MIIMonitorSec=100ms
Our network bonding guide covers the modes.
WireGuard too, which is a tidy way to make a tunnel a first-class interface:
# /etc/systemd/network/50-wg0.netdev
[NetDev]
Name=wg0
Kind=wireguard
[WireGuard]
PrivateKeyFile=/etc/systemd/network/wg0.key
ListenPort=51820
[WireGuardPeer]
PublicKey=...
AllowedIPs=10.8.0.2/32
PrivateKeyFile rather than inline, with mode 600, because .netdev files are world-readable by default. Our WireGuard guide covers the rest.
Wifi, and why networkd is the wrong tool for a laptop
networkd configures addressing. It does not do wireless association.
# you still need one of these
sudo systemctl enable --now wpa_supplicant@wlan0
sudo systemctl enable --now iwd
# /etc/systemd/network/25-wireless.network
[Match]
Name=wlan0
[Network]
DHCP=yes
IgnoreCarrierLoss=3s
That works for a machine on one fixed network. For a laptop moving between home, office and a phone hotspot, with captive portals and per-network settings, you are reimplementing NetworkManager badly.
Use NetworkManager on anything that roams. Our NetworkManager guide covers it and our wifi guide covers the supplicant layer.
netplan sits on top
On Ubuntu servers you probably are using networkd already, through netplan.
ls /etc/netplan/
sudo netplan get
sudo netplan generate
ls /run/systemd/network/
netplan reads YAML and generates networkd configuration. Which means:
- Edit the YAML, not the generated files
- The files in
/run/systemd/network/are regenerated and your edits are lost netplan tryapplies with an automatic rollback, which is the safest way to change a remote server’s network
sudo netplan try --timeout 60
Our netplan guide covers it. netplan try is worth knowing about specifically because it reverts if you do not confirm, which saves the connection you just broke.
DNS
networkd passes DNS servers it learns to systemd-resolved.
resolvectl status
resolvectl status enp3s0
resolvectl query example.com
# per-link DNS, which is the feature resolved adds
[Network]
DNS=10.0.0.1
Domains=internal.example.com ~corp.example.com
DNSOverTLS=opportunistic
~corp.example.com is a routing-only domain: queries for it go to this link’s DNS, and the link is not used for anything else. That is how you make a VPN resolve internal names without sending every query down it.
Without resolved you manage /etc/resolv.conf yourself and lose per-link resolution. Our DNS guide covers the model, and Unbound is the option if you want to resolve rather than forward.
Diagnosing
# the first command, always
networkctl status
networkctl status enp3s0
networkctl list
# which file matched
networkctl status enp3s0 | grep -iE 'network file|link file'
# the log
journalctl -u systemd-networkd -b --no-pager | tail -40
journalctl -u systemd-networkd -f
# validate without applying
systemd-analyze verify /etc/systemd/network/20-wired.network
Causes in order:
- A broader
[Match]in a lower-numbered file winning - Interface name wrong, since predictable names differ per machine
- Both networkd and NetworkManager enabled
.linkchanges needing a reboot, because udev applies them early- No
[Network]section at all, so the interface is matched and left unconfigured
networkctl status naming the file it used resolves the first two immediately, and it is the single most useful command here.
Frequently Asked Questions
Should I use systemd-networkd or NetworkManager?
networkd for servers, containers and virtual machines, where the configuration is static and declarative files are an advantage. NetworkManager for laptops and desktops, because it handles roaming between wifi networks, VPN integration and per-user settings, which networkd does not attempt.
What is the difference between a .network and a .link file?
A .network file configures addressing and routing for a matched interface, which is what you write most often. A .link file configures link-layer properties such as renaming the device, MAC address policy and offload settings, and it is applied by udev much earlier in boot.
Why is my .network file being ignored?
Files are processed in lexical order and the first one whose Match section matches an interface wins, so a broadly matching file with a lower number takes precedence. Check with networkctl which file was applied to the interface, and number your files deliberately.
Does systemd-networkd handle wifi?
It handles the addressing once the link is up, and it does not do the wireless association itself. You need wpa_supplicant or iwd for that, with networkd configuring the interface afterwards. For a machine that moves between networks, NetworkManager or iwd with its own tooling is far less work.
How does netplan relate to systemd-networkd?
netplan is a configuration front end that reads its own YAML and generates configuration for a backend, which on Ubuntu servers is systemd-networkd. So on a netplan system you edit the YAML and netplan writes the networkd files, and editing the generated files directly is pointless because they are regenerated.
Do I need systemd-resolved with networkd?
Not strictly, and they are designed to work together. networkd passes DNS servers it learns to resolved, which manages resolv.conf and per-link resolution. Without resolved you must manage resolv.conf yourself, which loses per-interface DNS and the DNS over TLS support.