Diagnosing a DNS cache miss after a systemd‑resolved restart

A “no such host” after you restart systemd‑resolved usually means more than a flaky network. It’s often a symptom of stale state, a mis‑wired socket, or a broken link to your upstream nameservers. Below is a walk‑through that keeps the commands you need and skips the fluff.


Why systemd‑resolved matters for security

On Debian, Ubuntu, Fedora and the likes, systemd‑resolved is the default stub resolver. It keeps a local cache, validates DNSSEC, and is the single point that all processes hit when they read /etc/resolv.conf. If it’s not behaving, you can end up:

  • Resolving to the wrong IP (open‑redirect or MITM).
  • Falling back to an untrusted upstream (DNS tunneling).
  • Losing connectivity and triggering legacy resolvers that ignore your security policy.

So a cache miss after a restart is a red flag that deserves a systematic look.


1. Verify the state of systemd‑resolved

# 1.1 Is the service running?
systemctl status systemd-resolved.service

# 1.2 What’s the current config?
resolvectl status

resolvectl status gives you the global state, per‑link settings, and the list of upstream servers. Pay attention to:

  • DNS Servers – do they match what you expect (e.g., 192.0.2.53)?
  • DNSSEC – is it yes or no? A mismatch can break validation.
  • Cache – a sudden drop to zero after a restart is normal, but if it stays at zero the cache might not be populating.

2. Test a simple lookup

# 2.1 Basic lookup
resolvectl query example.com

# 2.2 Where did the answer come from?
resolvectl query example.com | grep "Source"

If the answer shows Source: local but the record is missing, the cache is empty. If it shows Source: 192.0.2.53, the upstream server responded. NXDOMAIN or SERVFAIL points to an upstream or DNSSEC problem.


3. Check the socket that clients use

systemd‑resolved listens on /run/systemd/resolve/stub-resolv.conf (usually symlinked from /etc/resolv.conf) and on the DNS stub port 53. Verify that the socket is bound:

ss -ltnp | grep ':53 '

You should see something like:

LISTEN  0  511  127.0.0.53:53  0.0.0.0:*  users:(("systemd-resolve",pid=1234,fd=4))

If the socket is missing, clients fall back to whatever /etc/resolv.conf points at, which may be insecure.


4. Inspect the cache file

systemd‑resolved writes its cache to /var/lib/systemd/resolve/resolv.conf. After a restart the cache is cleared. If you see a persistent, empty file, the daemon may not be writing to it:

ls -l /var/lib/systemd/resolve/
cat /var/lib/systemd/resolve/resolv.conf | head

If the file is zero bytes, check the journal for errors:

journalctl -u systemd-resolved --since "10 minutes ago"

Common messages:

  • Failed to open cache file – permission issue.
  • DNSSEC validation failed – upstream server not signed or mis‑configured.

systemd‑resolved can override DNS settings per interface. If NetworkManager or systemd‑networkd mis‑configures a link, the global list gets ignored.

resolvectl status eth0

Look for DNS Servers under the link section. If it’s empty, the link isn’t providing DNS, and the daemon falls back to the global list. A stale link config (e.g., a removed VPN interface still listed) can cause a cache miss because the daemon thinks it has a reachable DNS server.


6. Test with dig or nslookup

resolvectl sometimes masks subtle issues. Query the stub resolver directly:

dig @127.0.0.53 example.com

A SERVFAIL means the stub isn’t forwarding the query. A valid answer means the cache works but the application isn’t using the stub (maybe /etc/resolv.conf points elsewhere).


Keep /etc/resolv.conf as a symlink to /run/systemd/resolve/stub-resolv.conf. If it points elsewhere, processes bypass systemd‑resolved.

ls -l /etc/resolv.conf

If you see:

/etc/resolv.conf -> /etc/old-resolv.conf

or a plain file, restore the symlink:

rm /etc/resolv.conf
ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf

8. Inspect upstream nameserver health

A cache miss can stem from an unreachable or mis‑configured upstream. Verify connectivity:

# Replace 192.0.2.53 with your upstream
dig @192.0.2.53 example.com +short

No response or SERVFAIL means the upstream is down. systemd‑resolved will keep the cache empty until it can reach a working server. If you’re using a public resolver (e.g., Cloudflare 1.1.1.1), double‑check the IP and that your firewall allows outbound UDP/TCP 53.


9. Look for firewall interference

A rule that blocks outbound DNS can cause cache misses. Verify that UDP/TCP 53 is allowed:

# On firewalld
firewall-cmd --list-ports | grep 53

# On iptables
iptables -L OUTPUT -v -n | grep 53

If the rule is missing, add it:

firewall-cmd --add-port=53/udp --permanent
firewall-cmd --add-port=53/tcp --permanent
firewall-cmd --reload

10. Consider DNSSEC and trust anchors

If DNSSEC is enabled (DNSSEC=yes) but the trust anchor is missing or corrupted, systemd‑resolved will refuse to cache any records. Check the anchor file:

cat /etc/systemd/resolved.conf.d/trust-anchors.conf

If you see a malformed line, correct it or temporarily disable DNSSEC to confirm:

sudo systemctl edit systemd-resolved
# Add:
# [Resolve]
# DNSSEC=no
sudo systemctl daemon-reload
sudo systemctl restart systemd-resolved

Disabling is fine for debugging but re‑enable it in production to keep validation.


11. Re‑populate the cache manually

If you suspect the cache is stale or empty and you want to force a refresh:

# Flush the cache
resolvectl flush-caches

# Force a lookup
resolvectl query example.com

If the lookup succeeds, the cache repopulates. If it still fails, the problem is upstream or in configuration.


12. Common pitfalls and trade‑offs

PitfallWhat it looks likeFixTrade‑off
/etc/resolv.conf points to a static fileApps ignore systemd‑resolvedRe‑create symlinkNone
Upstream DNS blocked by firewallSERVFAIL on all queriesOpen port 53Exposes DNS traffic to the network
DNSSEC enabled but trust anchor missingNXDOMAIN on all queriesAdd anchor or disableLoss of validation if disabled
Stale per‑link DNS configNo DNS on active interfaceDelete old link configMay affect VPNs or temporary interfaces
systemd‑resolved not listening on 53dig @127.0.0.53 failsRestart serviceService downtime

13. Automating the check

For production, a small script can run the most critical checks and alert you if something is wrong:

#!/usr/bin/env bash
# dns-check.sh
if ! ss -ltnp | grep -q ':53 '; then
  echo "❌ systemd-resolved not listening on 53"
fi

if ! resolvectl status | grep -q "DNS Servers:"; then
  echo "❌ No DNS servers configured"
fi

if ! dig @127.0.0.53 example.com +short; then
  echo "❌ DNS lookup failed"
fi

Run it via systemd‑timer or cron and ship the output to a log or alerting system.


14. Security‑centric takeaways

  1. Keep the stub resolver active – it’s the single point of control. A broken stub forces apps to use whatever /etc/resolv.conf points at, potentially bypassing DNSSEC.
  2. Validate upstream servers – use DNSSEC and a trusted anchor. Disable only for debugging, not in production.
  3. Restrict outbound DNS – firewalls should allow only the necessary ports to known upstreams. This limits the attack surface for DNS hijacking.
  4. Audit per‑link settings – stale VPN or interface configs can silently redirect DNS traffic. Run resolvectl status on all links regularly.
  5. Automate health checks – a simple script can catch a broken cache before users notice.

15. Final sanity check

After you’ve applied the fixes, run a full diagnostic:

systemctl restart systemd-resolved
resolvectl status
dig @127.0.0.53 example.com +short

If the lookup returns a valid IP and the cache shows entries, the problem is resolved. If not, dive back into the journal and firewall rules.


See also