A recursive resolver needs to block lookups for known-bad domains — phishing, malware C2, tracker domains. The naive approach is a hosts file or a hand-edited blocklist; this scales to thousands of entries and breaks beyond that. Response Policy Zones (RPZ) is the production approach: an actual DNS zone whose contents are interpreted as policy actions, distributed via standard zone transfer, and applied transparently to client queries. This article explains the format, the actions, and the operational pattern.
How to verify
If RPZ is already in place on a resolver, queries for the blocked names return synthesized responses. The journal logs the policy hits:
dig @resolver.example.com malware.example +short # expected: NXDOMAIN or 0.0.0.0
sudo journalctl -u named -n 50 --no-pager | grep -i 'rpz'
sudo rndc rpzstats
sudo rec_control get-all | grep rpz # PowerDNS Recursor
If RPZ is loaded, the journal will show entries like rpz QNAME NXDOMAIN rewrite malware.example via rpz.policy.example. The stats give you per-policy hit counts.
What’s happening
RPZ is a recursive-resolver feature defined informally in an internet draft (originally by Paul Vixie). It is not in any RFC but is widely implemented: BIND, Unbound, PowerDNS Recursor, Knot Resolver. The mechanism:
- A regular DNS zone (e.g.
policy.example) is configured as a “policy zone” on the resolver. - The resolver downloads this zone via AXFR/IXFR like any other secondary.
- Records inside the zone are interpreted as policies. The owner names encode what to match, the rdata encodes what to do.
The matching dimensions:
- QNAME —
malware.example.policy.examplematches queries formalware.example. - IP —
32.10.0.0.198.rpz-ip.policy.examplematches responses whose answer is198.0.0.10. - NSDNAME —
bad-ns.example.rpz-nsdname.policy.examplematches when the response involves an NS namedbad-ns.example. - NSIP —
32.20.0.113.0.203.rpz-nsip.policy.examplematches when an NS resolves to203.0.113.20. - CLIENTIP —
32.5.5.0.10.rpz-client-ip.policy.examplematches based on the client’s source IP.
The actions (encoded as the rdata):
- NXDOMAIN —
CNAME .returns “this name does not exist.” - NODATA —
CNAME *.returns “no records of this type.” - PASSTHRU —
CNAME rpz-passthru.lets the query proceed unmodified (whitelist). - TCP-only —
CNAME rpz-tcp-only.forces clients to retry over TCP. - DROP —
CNAME rpz-drop.silently discards the query. - Local-data — any A/AAAA/CNAME rdata replaces the response (sinkhole to an inspection server).
The procedure
-
Author the RPZ zone. A small example:
$TTL 60 $ORIGIN policy.example. @ SOA rpz.example. hostmaster.example. ( 2026060201 600 60 86400 60 ) NS rpz.example. ; Block malware C2 with NXDOMAIN c2-server.example. CNAME . bad-tracker.example. CNAME . ; Sinkhole to an inspection server phishing.example. A 10.0.0.99 ; Whitelist a domain we want to bypass other filtering ok-internal.example. CNAME rpz-passthru. ; Match a CIDR — block responses to 198.51.100.0/24 24.0.100.51.198.rpz-ip CNAME . -
Host the RPZ zone on an authoritative server. Any authoritative (BIND, NSD, Knot) can serve it. The resolver pulls it via AXFR with TSIG. The serial governs propagation — increment on every change. Many teams use a CI pipeline that converts a threat intel feed into zone records and bumps the serial.
-
Configure the resolver. On BIND:
options { response-policy { zone "policy.example" policy nxdomain; zone "phishing.policy.example" policy given; } qname-wait-recurse no break-dnssec no; }; zone "policy.example" { type secondary; file "/var/cache/bind/policy.example"; primaries { 203.0.113.10 key rpz-transfer; }; allow-query { none; }; };policy givenmeans “use the action encoded in the record”;policy nxdomainoverrides to always return NXDOMAIN.break-dnssec nomeans RPZ does not lie to validating clients about DNSSEC-protected zones.qname-wait-recurse nomakes the policy apply before the resolver tries to recurse, saving query time.On PowerDNS Recursor:
rpzPrimary({"203.0.113.10:53"}, "policy.example", { policyName = "policy", refresh = 120, tsigname = "rpz-transfer", tsigalgo = "hmac-sha256", tsigsecret = "SECRET", }) -
Validate and verify. Restart the resolver, then test:
sudo systemctl restart named dig @127.0.0.1 c2-server.example +short # expect empty (NXDOMAIN) dig @127.0.0.1 phishing.example +short # expect 10.0.0.99 dig @127.0.0.1 google.com +short # expect normal answer sudo rndc rpzstats -
Wire in threat intel. Production RPZ feeds come from commercial providers (Spamhaus, Farsight, Quad9) or community lists (DNS-BH, OISD, Steven Black). The integration shape:
- Pull the feed.
- Convert each entry into an RPZ record.
- Re-sign or just update the zone file.
- Bump SOA serial.
- The resolver AXFRs/IXFRs the changes.
Cycle: every 5-60 minutes depending on feed cadence.
Operational notes
- Cache poisoning vs policy. RPZ runs after recursion when the resolver has the real answer; it overrides the response before sending to the client. Validating clients with DNSSEC see the policy as if the zone had no DNSSEC — which is why
break-dnssecdefaults to no. - Whitelist before blacklist. Always add
rpz-passthru.entries for known-good names that might match a wildcard rule. A single false positive on a popular name (cloud provider) breaks half your fleet. - Performance impact. Each query checks the policy zone. BIND uses a special radix tree for IP-prefix matching that scales well. Unbound’s RPZ implementation is newer; check version notes.
- CIDR encoding is fiddly. The
<prefix>.<reversed-octets>.rpz-ipencoding is hard to handwrite — generate it from a tool. Bit length goes first. - Auditing what was blocked. Enable RPZ logging with category
rpzin BIND. The journal will show every match. For SIEM ingestion, ship the log to a central pipeline; correlate by client IP. - DNS over HTTPS / DNS over TLS bypass. Clients that use DoH/DoT to an external resolver bypass your RPZ entirely. To enforce policy, block outbound 853/tcp and 443/tcp to public resolvers, or run a DoH/DoT proxy that applies the same RPZ.
In the engagements we run, RPZ is the standard mechanism for DNS-level threat blocking — it scales to millions of entries, integrates with existing DNS infrastructure, and produces auditable logs. We pair it with PowerDNS Recursor or Unbound on the resolver side, codify the feed → RPZ pipeline, and monitor block hit rates per category to confirm the policy is doing what is intended. See our managed operations service for the broader operating model.