Skip to content

systemd-resolved: set and change DNS servers with resolvectl

systemd-resolved handles DNS on most modern Linux systems. Set or change DNS servers per interface or globally with resolvectl, and keep resolv.conf right.

On most modern Linux systems a service called systemd-resolved handles DNS, which is why /etc/resolv.conf is a symlink to a file that says nameserver 127.0.0.53. That address is a local stub, a small listener on the loopback interface that catches every query your programs make and hands it to the real resolver inside systemd-resolved. The resolver caches answers, sends each query to the right upstream server for each network interface, and can validate DNSSEC or encrypt queries with DNS-over-TLS. So you are not meant to edit resolv.conf; typing 8.8.8.8 into it by hand is how people quietly break their own DNS. To change DNS servers, use resolvectl dns <interface> <server> for a quick, temporary change, or set DNS= in /etc/systemd/resolved.conf (or in the network configuration) for one that survives a reboot.

What you’ll accomplish

  • Understand what the 127.0.0.53 stub is, why /etc/resolv.conf is a symlink, and which symlink target you actually want.
  • Read the full DNS state of a machine with resolvectl status, including per-interface servers and search domains.
  • Set DNS servers globally and per-link, the correct way, so they survive a reboot and a network change.
  • Turn on DNSSEC validation and DNS-over-TLS, and know when each one will bite you.
  • Diagnose the classic failures: a hand-edited resolv.conf, settings that never apply, and conflicts with NetworkManager.

Prerequisites

  • systemd 249 or newer with systemd-resolved present. Check with resolvectl --version; anything from the last several years is fine, and the features here are stable across 249 through 255.
  • A distribution that ships it enabled: Ubuntu 18.04 and later, Fedora, and most desktop spins. Root or sudo for anything that writes config or restarts the service.
  • Worth knowing up front: not every distro uses this. Debian installs systemd-resolved but does not enable the stub by default; Alpine and most container base images do not run systemd at all. If resolvectl status errors out or /etc/resolv.conf is a plain file, you are on a system that resolves DNS some other way, and the When this is the wrong approach section is where you should start.

How it works

The whole design turns on one indirection. Your programs call getaddrinfo(), which reads /etc/resolv.conf, which — on a systemd-resolved system — contains a single line: nameserver 127.0.0.53. So every lookup goes to that loopback address, where the stub is listening. The stub is not a full resolver; it is a doorway into systemd-resolved, which holds the cache, the per-interface server lists, and the DNSSEC and encryption logic.

The path of a DNS query from an application through the /etc/resolv.conf symlink to the 127.0.0.53 stub, into systemd-resolved, and out to the per-link or global upstream DNS servers

The part that trips everyone up is which file /etc/resolv.conf points at, because systemd-resolved maintains two of them and they behave completely differently. The recommended one is /run/systemd/resolve/stub-resolv.conf: it contains only nameserver 127.0.0.53, so all traffic goes through the stub and you get the full feature set — caching, per-link routing, DNSSEC, DNS-over-TLS. The other is /run/systemd/resolve/resolv.conf, which lists your actual upstream servers directly; clients talk to them without the stub, which means no local cache and no split-DNS routing. And there is a third possibility that is the source of most bug reports: /etc/resolv.conf is a plain static file someone created, not a symlink to either runtime file, in which case systemd-resolved is running but nothing you configure through it ever reaches your programs.

Per-link versus global is the other concept to hold. Each network interface can carry its own DNS servers and search domains — typically learned from DHCP or a VPN — and systemd-resolved routes a query to the right interface based on its search domains. A query for internal.corp goes to the VPN’s resolver while everything else goes to your home router, all at once. Global servers, set in resolved.conf, are the fallback used when no per-link server claims the query.

Step-by-step

1. Read the current state first. Before changing anything, get the full picture. resolvectl status prints the global config and then every link:

resolvectl status
Global
         Protocols: +DNSOverTLS +DNSSEC=allow-downgrade
  resolv.conf mode: stub

Link 2 (enp1s0)
    Current Scopes: DNS
         Protocols: +DefaultRoute +DNSOverTLS
Current DNS Server: 192.168.1.1
       DNS Servers: 192.168.1.1
        DNS Domain: lan

The resolv.conf mode: stub line confirms the symlink is pointing at the good file. Current DNS Server is the one actually in use for that link right now.

2. Confirm the symlink is what you think. This single command settles more DNS arguments than any other on the page:

ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 37 Jul 19 09:14 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf

If it points at stub-resolv.conf, you are set. If it points at resolv.conf (no stub-), you have the compatibility mode. If ls -l shows a regular file with no arrow, systemd-resolved is not in charge and your resolvectl changes will be ignored.

3. Set the global DNS servers. Edit the main config file. Open /etc/systemd/resolved.conf and set the servers under the [Resolve] section:

sudo nano /etc/systemd/resolved.conf
[Resolve]
DNS=9.9.9.9 149.112.112.112
FallbackDNS=1.1.1.1
Domains=~.

DNS= is your preferred upstream, FallbackDNS= is used only if the primaries fail, and Domains=~. makes this link the default route for all queries not claimed elsewhere.

4. Prefer a drop-in over editing the main file. So a package upgrade never clobbers your change, put it in a drop-in instead of the main file:

sudo mkdir -p /etc/systemd/resolved.conf.d
sudo tee /etc/systemd/resolved.conf.d/dns.conf <<'EOF'
[Resolve]
DNS=9.9.9.9 149.112.112.112
FallbackDNS=1.1.1.1
EOF

Drop-ins in resolved.conf.d are merged on top of the main file, and this is the pattern to reach for on any managed fleet.

5. Apply the change. Restart the service so it reloads config:

sudo systemctl restart systemd-resolved
(no output on success)

A restart briefly flushes the cache, which is harmless. There is no reload-only path for server changes, so restart is correct here.

6. Set DNS on one link only, at runtime. To override a single interface without touching global config — useful for a VPN or a lab NIC — use resolvectl dns:

sudo resolvectl dns enp1s0 9.9.9.9
sudo resolvectl domain enp1s0 '~corp.example'
(no output on success)

This is not persistent by itself; it lasts until the link goes down or the machine reboots. For persistence, let the network manager own it (step 7) or use the global config above.

7. Let your network layer set per-link DNS persistently. On a systemd-networkd machine, put the DNS in the .network file so it is reapplied every time the link comes up:

[Match]
Name=enp1s0

[Network]
DNS=9.9.9.9
Domains=~corp.example

Write that to /etc/systemd/network/10-lan.network and run sudo networkctl reload. On a NetworkManager machine, set it on the connection profile instead — see the troubleshooting note below.

Validate it works

Prove the resolver is answering and using the servers you expect. resolvectl query runs a lookup through systemd-resolved itself, and tells you which server and protocol answered:

resolvectl query github.com
github.com: 140.82.112.3                       -- link: enp1s0
                                               -- Data is authenticated: no
-- Information acquired via protocol DNS in 21.4ms.
-- Data from: network

The link: line proves per-link routing is working. Now confirm the symlink target one more time and read the cache statistics to see hits accumulating:

resolvectl statistics
Cache
  Current Cache Size: 42
          Cache Hits: 1381
        Cache Misses: 203

A climbing Cache Hits number is the clearest sign that queries are genuinely flowing through the stub rather than around it. If hits stay at zero while you browse, something is bypassing systemd-resolved — jump to troubleshooting.

Troubleshooting

  • A hand-edited resolv.conf keeps getting overwritten. You put nameserver 8.8.8.8 in /etc/resolv.conf and it reverts on reboot. That is correct behaviour: the file is a symlink into a runtime directory that systemd-resolved regenerates. Stop editing it. Put your server in resolved.conf or the drop-in (steps 3 and 4), and let the symlink stand.
  • Your DNS setting never applies because resolv.conf is a static file. The most common silent failure. Someone replaced the symlink with a real file — often a container image or a cloud-init template did it. resolvectl reports your servers happily, but programs read the static file and ignore them. Fix it by restoring the symlink: sudo ln -sf ../run/systemd/resolve/stub-resolv.conf /etc/resolv.conf, then confirm with ls -l /etc/resolv.conf.
  • DNSSEC breaks split-horizon or captive-portal DNS. With DNSSEC=yes, an internal zone that returns unsigned or rewritten answers — common on corporate resolvers and hotel Wi-Fi — fails validation and the name goes dark with a SERVFAIL. The pragmatic setting is DNSSEC=allow-downgrade in resolved.conf, which validates when the chain is intact and steps aside when it clearly is not. If you need strict validation, exempt the internal domain with a negative-trust anchor rather than disabling DNSSEC everywhere.
  • Per-link DNS is ignored and everything uses the global server. Usually the link’s search domain is missing, so systemd-resolved has no reason to route anything to it. Check resolvectl status for a DNS Domain on that link; if it is blank, add one with resolvectl domain <link> '~internal.example'. The ~ prefix marks it a routing-only domain, which is what makes split DNS work.
  • NetworkManager and resolved disagree. On a NetworkManager system, per-link DNS set with resolvectl dns is transient and gets replaced when NetworkManager reasserts the connection. Set it on the profile instead: nmcli con mod "<name>" ipv4.dns 9.9.9.9 and nmcli con mod "<name>" ipv4.dns-search '~corp.example', then nmcli con up "<name>". NetworkManager pushes that into systemd-resolved and it sticks. If you see resolv.conf mode: foreign, some other tool owns the symlink and you should decide which one wins before going further. When a name resolves but the service behind it still fails, confirm the lookup itself with dig and read what the resolver logged with journalctl.

When this is the wrong approach

systemd-resolved earns its keep on a laptop or server that changes networks, runs a VPN, or needs split DNS. On a container, it is usually the wrong tool: containers do not run systemd, and the right answer is a plain /etc/resolv.conf with one or two upstream servers, injected by the orchestrator. Forcing systemd-resolved into an image adds a moving part for no benefit.

The same logic applies to a minimal single-purpose server with one static network and one resolver. If nothing about your DNS ever changes, a fixed /etc/resolv.conf — a real file, not a symlink — is simpler, has no daemon to restart, and cannot silently swallow your settings. Disable the stub with systemctl disable --now systemd-resolved and write the file directly. The reference for every knob mentioned here is the systemd-resolved service manual and the resolvectl manual. The honest boundary is this: systemd-resolved solves DNS policy on a machine that has interesting DNS to route. When the DNS is boring, so is the correct tool.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.