LLI Wiki — My Digital Knowledge Base

Configure per-interface DNS with systemd-networkd

Set per-interface DNS servers and split DNS with systemd-networkd and systemd-resolved.

On a Linux system that uses systemd-networkd and systemd-resolved, you can set DNS servers per interface and send selected domains to a dedicated DNS server (split DNS).

Check the current state

networkctl list
networkctl status
systemd-resolve --status
cat /etc/resolv.conf

With systemd-resolved, /etc/resolv.conf usually points to the local stub resolver 127.0.0.53.

Configuration files

File Role
/etc/systemd/network/*.network Per-interface network configuration (takes precedence over /run)
/run/systemd/network/ Default files generated at runtime (for example 10-netplan-eth0.link)
/etc/systemd/resolved.conf Global resolver configuration

DNS for a VPN interface

Example for a WireGuard interface wg0: queries for example.com are sent to the DNS servers of the tunnel.

[Match]
Name=wg0

[Network]
LinkLocalAddressing=0
Domains=~example.com
DNSOverTLS=no
DNSSEC=no
DNS=192.0.2.10
DNS=192.0.2.11
Address=192.0.2.12/16

The ~ prefix marks a routing-only domain: queries for this domain are sent to the DNS servers of this interface, and the domain is not added to the search domains.

Static DNS on a DHCP interface

[Match]
Name=eth0

[Network]
DHCP=ipv4
DNS=192.0.2.21

[DHCP]
UseDNS=false

UseDNS=false ignores the DNS servers provided by DHCP, so only the static DNS server is used.

Apply the configuration

sudo systemctl restart systemd-networkd
sudo systemctl restart systemd-resolved

Protect a configuration file

sudo chattr +i /etc/systemd/network/eth0.network

The immutable attribute prevents the file from being modified or deleted. To edit it, remove the attribute first with sudo chattr -i.

Notes

References

Mastodon LLIMastodon SocialFosstodon