Enabling and Configuring systemd‑resolved on Debian 12 for Local DNS Caching and DNSSEC
Enable Debian 12’s systemd‑resolved, set up local DNS caching, enable DNSSEC, and point /etc/resolv.conf to the stub listener. Follow the step‑by‑step guide to verify the service, configure NetworkManager, and recover if needed.
23 Jul 2025, 00:02 UTC

Desired Outcome
Activate systemd‑resolved on Debian 12, set up local DNS caching, enable DNSSEC validation, and ensure the system’s /etc/resolv.conf points to the stub listener without conflicts from other resolver services.
Prerequisites
- Debian 12 (Bookworm) installed with systemd 252+.
- Root or
sudoprivileges to edit system files and control services. - Optional: NetworkManager installed; if so, it must be configured to use
systemd‑resolvedor left unchanged.
Focused Procedure
- Verify systemd‑resolved is available
systemctl list-unit-files | grep systemd-resolvedOutput should contain
systemd-resolved.servicewithenabledordisabledstatus. - Enable and start the service
sudo systemctl enable --now systemd-resolvedCheck the service is active:
systemctl status systemd-resolved - Configure DNS servers and DNSSEC in
/etc/systemd/resolved.conf[Resolve] DNS=8.8.8.8 8.8.4.4 FallbackDNS=1.1.1.1 1.0.0.1 Cache=yes DNSSEC=yes DNSSECTrustAnchorFile=/etc/systemd/resolved.dnssec-anchorReplace the IPs with your preferred upstream resolvers. The
DNSSECTrustAnchorFilecan be omitted if you rely on the built‑in anchors. - Link
/etc/resolv.confto the stub listenersudo rm -f /etc/resolv.conf sudo ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.confThis symlink ensures all DNS queries go through
systemd‑resolvedon127.0.0.53. - Adjust NetworkManager (if present)
- Open
/etc/NetworkManager/NetworkManager.confand add or modify:
[main] dns=systemd-resolved - Open
- Restart NetworkManager:
- Reload systemd daemon to apply configuration changes
sudo systemctl daemon-reload sudo systemctl restart systemd-resolved
sudo systemctl restart NetworkManager
Alternatively, set dns=none to let systemd‑resolved handle DNS entirely.
Expected Checks
- Service status
systemctl status systemd-resolvedShould show
Active: active (running). - Verify stub listener
systemd-resolve --statusLook for
DNS Servers:listing the addresses set inresolved.confandDNSSEC: yes. - Test DNS resolution via stub
dig @127.0.0.53 example.comThe answer section should come from one of the configured upstream servers and include a
ADflag if DNSSEC is validated. - Check
/etc/resolv.confsymlinkls -l /etc/resolv.confIt must point to
/run/systemd/resolve/stub-resolv.conf.
Recovery Options
- To disable
systemd‑resolvedand revert to the default resolver, remove the symlink and restore the original/etc/resolv.conf(e.g.,sudo mv /etc/resolv.conf.bak /etc/resolv.confif you backed it up). - Disable the service:
sudo systemctl disable --now systemd-resolved - If NetworkManager was configured to use
systemd‑resolved, changedns=noneordns=defaultand restart.
Limitations and Practical Verification
systemd‑resolved requires systemd 252+, which is present in Debian 12. Older Debian releases use dnsmasq or bind9 by default. If you run multiple resolver services simultaneously, the last one to write to /etc/resolv.conf will win, causing unpredictable behavior. Always keep only one active resolver.
To double‑check that no other resolver is running, list active services:
systemctl list-units --type=service | grep -E 'dns|bind|dnsmasq'
Any matching units should be stopped or disabled before relying on systemd‑resolved.
Concrete Example
Suppose you want to use Google’s public DNS with DNSSEC and a local caching layer. After following the steps above, a quick test:
dig @127.0.0.53 www.google.com
should return an answer with the AD flag set, indicating DNSSEC validation succeeded, and the query should be served from the local cache on subsequent queries.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.