Resolve DNS Cache Poisoning on Raspberry Pi with resolvectl – One‑Step Fix

DNS cache poisoning is a classic attack that can redirect traffic from a legitimate domain to a malicious IP. On a Raspberry Pi running a recent Debian‑based OS (e.g., Raspberry Pi OS 2026‑stable), the default resolver is systemd‑resolved, which exposes the resolvectl command. This guide shows how to harden that resolver in a single, repeatable step, with practical examples, caveats, and troubleshooting tips.


Why the Pi is a Target

  • Low‑cost, always‑on devices are often used as home routers, media servers, or IoT gateways.
  • Many users leave the default DNS settings unchanged, pointing to public resolvers (Google, Cloudflare, ISP).
  • A compromised Pi can become a pivot point for lateral movement or a source of DNS‑based exfiltration.

Hardening the resolver is a low‑effort, high‑impact measure.


1. Understand the Threat Landscape

Attack VectorWhat HappensImpact on a Pi
Cache poisoningMalicious DNS responses are accepted and cached.All services on the Pi (web, SSH, VPN) may be redirected.
Man‑in‑the‑Middle (MITM)Attacker intercepts DNS queries and supplies forged answers.The Pi may resolve to attacker‑controlled IPs.
DNS rebindingA malicious site forces the Pi to resolve to internal IPs.Remote code execution via local services.

The most common vector on a Pi is a compromised upstream resolver (e.g., a rogue Wi‑Fi AP). Once the Pi trusts the bogus answers, it can be used to redirect traffic to a malicious site or to exfiltrate data.


2. Baseline: What the Pi Does Right

  • systemd‑resolved runs as a system service (systemd-resolved.service).
  • It supports DNSSEC validation if enabled.
  • It can use multiple upstream resolvers (fallbacks).
  • It exposes a D‑Bus API and the resolvectl CLI.

By default, DNSSEC is disabled on most Pi OS images. Enabling it is the first step toward preventing cache poisoning.


3. One‑Step Fix: Enable DNSSEC Validation

The single command that flips the resolver into a hardened state is:

sudo resolvectl set-dnssec true

This writes to /etc/systemd/resolved.conf.d/dnssec.conf and restarts the service. After the restart, systemd-resolved will reject any DNS response that fails DNSSEC validation.

3.1 Verify the Change

resolvectl status | grep -i dnssec

You should see:

DNSSEC: enabled

If you still see “disabled”, check the file:

cat /etc/systemd/resolved.conf.d/dnssec.conf

It should contain:

[Resolve]
DNSSEC=true

3.2 Test with a Known Poisoned Domain

Use dig to query a domain that has a known DNSSEC failure:

dig @8.8.8.8 example.com +dnssec +noall +answer

Now query through the Pi’s resolver:

dig @127.0.0.53 example.com +dnssec +noall +answer

If DNSSEC is enabled, the response will be rejected or marked as “SERVFAIL”. You can also use resolvectl:

resolvectl query example.com

The output will include a line:

DNSSEC: validated

or

DNSSEC: validation failed

4. Fine‑Tuning: Choosing Upstream Resolvers

Even with DNSSEC enabled, you should control which upstream resolvers the Pi trusts. The default is to use the router’s DNS server, which may be insecure.

4.1 Set Trusted Public Resolvers

Create a drop‑in file:

sudo tee /etc/systemd/resolved.conf.d/trusted-resolvers.conf <<EOF
[Resolve]
DNS=1.1.1.1 1.0.0.1
FallbackDNS=8.8.8.8 8.8.4.4
EOF
  • 1.1.1.1 and 1.0.0.1 are Cloudflare’s public resolvers with built‑in DNSSEC support.
  • 8.8.8.8 and 8.8.4.4 are Google’s, also DNSSEC‑enabled.

Restart:

sudo systemctl restart systemd-resolved

4.2 Verify the Upstream List

resolvectl status | grep -i 'DNS Servers'

You should see the IPs you just added.

4.3 Trade‑offs

OptionProsCons
Public resolversNo ISP tampering, DNSSEC readySlight latency increase
Local routerLower latencyRisk of compromised firmware
Custom resolverFull controlRequires maintenance

For most homelabs, public resolvers strike a good balance.


5. Advanced Hardening: Disable IPv6 DNS Queries

Some attackers use IPv6 to bypass DNSSEC checks if the resolver is misconfigured. Disable IPv6 DNS queries to avoid this vector:

sudo resolvectl set-allow-duplicate-ips false

Alternatively, block IPv6 DNS traffic at the firewall:

sudo iptables -A OUTPUT -p udp --dport 53 -d ::/0 -j DROP

Caveat: Disabling IPv6 may break services that rely on it (e.g., certain VPNs). Test your environment first.


6. Monitoring and Alerting

A hardened resolver is only as good as your ability to detect failures.

6.1 Systemd Journal

journalctl -u systemd-resolved | grep -i 'dnssec'

Look for “validation failed” or “rejected” entries.

6.2 Prometheus Exporter

If you run Prometheus, install prometheus-systemd-exporter to expose metrics:

sudo apt install prometheus-systemd-exporter

Add a rule in Prometheus:

- job_name: 'systemd_resolved'
  static_configs:
  - targets: ['localhost:9100']

Alert on systemd_resolved_dnssec_validation_failed_total exceeding a threshold.

6.3 Simple Bash Watchdog

Create /usr/local/bin/dnssec_watchdog.sh:

#!/usr/bin/env bash
if resolvectl status | grep -q 'DNSSEC: validation failed'; then
  logger -p auth.err "DNSSEC validation failure detected on $(hostname)"
fi

Make it executable and add to cron:

crontab -e
*/5 * * * * /usr/local/bin/dnssec_watchdog.sh

7. Troubleshooting Common Issues

SymptomLikely CauseFix
resolvectl status shows DNSSEC disabledConfiguration file missing or overwrittenRe‑run sudo resolvectl set-dnssec true
DNS queries fail after enabling DNSSECUpstream resolver does not support DNSSECSwitch to Cloudflare or Google
dig @127.0.0.53 returns SERVFAIL for all queriesSystem clock skewSync time with NTP (sudo timedatectl set-ntp true)
Firewall blocks DNS trafficNew iptables ruleAllow UDP/TCP port 53 (sudo iptables -A OUTPUT -p udp --dport 53 -j ACCEPT)

8. Real‑World Scenario: A Pi Acting as a Home Router

Imagine your Pi is the DHCP server for your home network. An attacker on the same Wi‑Fi could set up a rogue AP that advertises the Pi’s IP as a DNS server. With DNSSEC disabled, the Pi would happily cache the attacker’s forged answers.

By enabling DNSSEC and pointing the Pi to trusted public resolvers, the attacker’s forged responses are immediately rejected. The Pi will then fall back to the fallback resolvers, ensuring continuity of service without compromising security.


9. Summary of Steps

  1. Enable DNSSEC: sudo resolvectl set-dnssec true
  2. Set trusted upstream resolvers: add Cloudflare/Google IPs to /etc/systemd/resolved.conf.d/trusted-resolvers.conf
  3. Restart systemd‑resolved: sudo systemctl restart systemd-resolved
  4. Verify: resolvectl status
  5. Optional: Disable IPv6 DNS queries or block via firewall
  6. Monitor: Use journal, Prometheus, or a simple watchdog script

These steps are idempotent; you can run them on any Debian‑based Pi OS without side effects.


10. Further Reading


See also