A network needs a real recursive resolver — not the ISP’s, not 8.8.8.8 — that we control, log, and can rate-limit. PowerDNS Recursor (pdns-recursor) is a strong fit: small, fast, scriptable via Lua, and operationally simple compared to BIND in recursive mode. This article is the install + first-tune procedure: package, ACLs, RPZ hook-ins, and the dials we adjust before declaring it ready.
How to verify
Before installing, confirm what is on the loopback and the host’s main address. The most common interference is systemd-resolved holding 127.0.0.53.
ss -lunp | grep ':53\b'
resolvectl status | head -20
dpkg -l | grep -E 'pdns-recursor|bind9|unbound'
dig @127.0.0.1 cloudflare.com +short
journalctl -u pdns-recursor -n 30 --no-pager 2>/dev/null || true
If pdns-recursor is already installed and running, the last dig returns an A record. If not, the next steps build it.
What’s happening
pdns-recursor is a recursive-only resolver. It does not serve authoritative zones — that is the job of pdns-server (a different package and daemon). On a query, it walks the DNS hierarchy from the root hints, caches answers per their TTLs, validates DNSSEC if asked, and returns the result. Two design choices stand out compared to BIND:
- Lua scripting hooks. Inbound and outbound queries can be inspected and modified by Lua functions (
preresolve,postresolve,nodata,nxdomain). This is how policy is expressed — not via giant config blocks but via small functions. - Separate threads for cache and resolution. The cache is a lock-free per-thread structure; resolution runs on a separate pool. Scales well to millions of queries per second on commodity hardware.
The daemon ships its own root hints and refreshes them periodically — no need to maintain a local named.root.
The procedure
-
Install the package. On Ubuntu,
pdns-recursoris in the main archive but the version lags PowerDNS upstream. For newer features (4.9+), use the official PowerDNS repository:sudo apt update sudo apt install -y pdns-recursor sudo systemctl status pdns-recursor -
Disable
systemd-resolvedstub if you want loopback. Otherwise the listener will collide:sudo sed -i 's/^#\?DNSStubListener=.*/DNSStubListener=no/' /etc/systemd/resolved.conf sudo systemctl restart systemd-resolved -
Configure ACLs and listeners.
/etc/powerdns/recursor.conf:local-address=127.0.0.1, ::1, 10.0.5.10 local-port=53 allow-from=127.0.0.0/8, ::1/128, 10.0.0.0/8, 192.168.0.0/16 dnssec=validate security-poll-suffix= threads=4 max-cache-entries=2000000 max-mthreads=2048 query-local-address=10.0.5.10 loglevel=4 quiet=yesallow-fromis non-negotiable — without it, the recursor will answer queries from anywhere on the internet, making the box an open resolver. Cloud abuse desks notice fast. -
Add Lua policy (optional but recommended). Drop a
/etc/powerdns/recursor.lua:-- Block specific domains at the resolver blocklist = { ["malware.example."] = true, ["tracker.example."] = true, } function preresolve(dq) if blocklist[dq.qname:toString()] then dq:addAnswer(pdns.A, "0.0.0.0", 60) return true end return false endReference it from
recursor.conf:lua-dns-script=/etc/powerdns/recursor.lua -
Reload and verify. PowerDNS Recursor supports
rec_controlfor runtime operations:sudo systemctl restart pdns-recursor sudo rec_control get-all | head -20 dig @127.0.0.1 cloudflare.com +short dig @127.0.0.1 dnssec-failed.org +dnssecdnssec-failed.orgis a test domain with intentionally broken DNSSEC — your validating recursor should return SERVFAIL. -
Wire up a Response Policy Zone if needed. For blocklists at scale, a Lua table does not scale to millions of entries. Use RPZ instead — see DNS RPZ for the full pattern. PowerDNS Recursor loads RPZs from a primary via AXFR:
# in /etc/powerdns/recursor.conf: # uses Lua config: rpzPrimary("203.0.113.50:53", "blocklist.rpz") lua-config-file=/etc/powerdns/recursor.lua-configAnd
/etc/powerdns/recursor.lua-config:rpzPrimary({"203.0.113.50:53"}, "blocklist.rpz", {policyName="blocklist", refresh=120}) -
Plumb metrics. Recursor exports Carbon/StatsD and a JSON API. For Prometheus, scrape
/api/v1/servers/localhost/statisticsvia an exporter or use the built-inwebserver=yes+api-key=.
Common pitfalls
allow-fromtoo permissive. Putting0.0.0.0/0because “we’ll firewall it” — until someone reorders the firewall rules. Treatallow-fromas the last line of defence, not the first.query-local-addressmatching listener address. If the box has multiple interfaces, outbound queries should leave from a routable address that returns the response to the same interface. Misalignment causes silent timeouts.- Cache too small for the query mix.
max-cache-entries=1000000sounds large until you serve a million users hitting a long tail. Bumping cache size is cheap RAM-wise; bumpingthreadswithout checking lock contention can hurt. - Lua script panics taking out the resolver. A Lua error in
preresolvefor one query does not kill the daemon, but a syntax error in the script file prevents the next reload from succeeding. Always runrec_control reload-lua-scriptand check the journal. - DNSSEC validation failures masking real issues. A spike in SERVFAIL is sometimes a downstream zone with broken signatures, not your resolver. Cross-check by querying the same name via
dig @1.1.1.1— if it also SERVFAILs, the upstream zone is broken.
In the engagements we run, PowerDNS Recursor is the resolver of choice when the client needs Lua-based policy or RPZ at high QPS. We deploy it in pairs behind a VIP, push the Lua policy via configuration management, monitor cache hit ratio and resolver-side latency, and roll updates on a schedule. See our managed operations service for the broader operating model.