<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>Response Policy Zones | A DevOps Blog</title><link>https://blog.bsdserver.nl/tag/rpz/</link><description>Hands-on DevOps and homelab content: Kubernetes clusters, self-hosted services, CI/CD pipelines and infrastructure as code, by Patrick de Ruiter of We Build Your Cloud.</description><language>en</language><image><url>https://blog.bsdserver.nl/images/app-icon.svg</url><title>A DevOps Blog</title><link>https://blog.bsdserver.nl/</link></image><lastBuildDate>Wed, 18 Nov 2026 09:00:00 +0100</lastBuildDate><atom:link href="https://blog.bsdserver.nl/tag/rpz/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title>Implementing DNS-Based Security with BIND Response Policy Zones</title><link>https://blog.bsdserver.nl/implementing-dns-based-security-with-bind-response-policy-zones/</link><guid isPermaLink="false">693b6d5379eb54000160a580</guid><dc:creator>Patrick de Ruiter</dc:creator><pubDate>Fri, 12 Dec 2025 01:18:11 +0000</pubDate><description>Response Policy Zones (RPZ) provide DNS-level security by allowing you to override DNS responses for specific domains.</description><category>BIND</category><category>DNS</category><category>Response Policy Zones</category><category>Security</category><category>Malware</category><category>Linux</category><media:content url="https://blog.bsdserver.nl/content/images/2026/01/bind-rpz.png" medium="image"/><content:encoded><![CDATA[<p>Response Policy Zones (RPZ) provide DNS-level security by allowing you to override DNS responses for specific domains. Malware, phishing and tracking all start with a DNS lookup; if the lookup fails, the connection never happens.</p>
<p>This post sets up RPZ on a BIND recursive resolver. It covers the policy actions and triggers, external blocklists with automatic updates, a block page, whitelisting and logging.</p>
<h2 id="why-rpz">Why RPZ? <a class="anchor" data-pagefind-ignore href="#why-rpz" aria-label="Link to this section">#</a></h2>
<ul>
<li><strong>One control point</strong>: every device using the resolver is protected, including IoT devices and guests you cannot install software on.</li>
<li><strong>Blocks before the connection</strong>: the client never gets an address for a blocked domain.</li>
<li><strong>Standard format</strong>: blocklists are ordinary DNS zones; they can be transferred between servers like any zone.</li>
<li><strong>Visibility</strong>: RPZ logs show which client looked up which blocked domain.</li>
</ul>
<h3 id="when-to-use-it">When to use it <a class="anchor" data-pagefind-ignore href="#when-to-use-it" aria-label="Link to this section">#</a></h3>
<ul>
<li><strong>Use it</strong> on resolvers you control, to block known-bad domains, ads or trackers network-wide.</li>
<li><strong>Skip it</strong> on authoritative-only servers: RPZ only applies to recursive queries. It also cannot help clients that bypass your resolver (hard-coded DNS servers, DNS over HTTPS).</li>
</ul>
<h2 id="how-rpz-works">How RPZ Works <a class="anchor" data-pagefind-ignore href="#how-rpz-works" aria-label="Link to this section">#</a></h2>
<p>RPZ is a zone loaded by the resolver. Each record in it is a rule: the owner name says what to match (the trigger), the record data says what to answer instead (the action).</p>
<table>
	<thead>
			<tr>
					<th>Component</th>
					<th>Runs on</th>
					<th>Job</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>BIND resolver</td>
					<td>Your DNS server</td>
					<td>Resolves queries and applies the policy zones</td>
			</tr>
			<tr>
					<td>RPZ zones</td>
					<td>Same server (local file or transferred)</td>
					<td>Hold the rules</td>
			</tr>
			<tr>
					<td>Update script</td>
					<td>Same server (cron)</td>
					<td>Converts external blocklists into an RPZ zone</td>
			</tr>
			<tr>
					<td>Block page (optional)</td>
					<td>A web server</td>
					<td>Explains to users why a site is blocked</td>
			</tr>
	</tbody>
</table>
<p>The flow: client query → BIND checks the RPZ zones → match: rewritten answer and a log line → no match: normal resolution.</p>
<p>The rewritten answer can be:</p>
<table>
	<thead>
			<tr>
					<th>Action</th>
					<th>Client sees</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>NXDOMAIN</td>
					<td>Domain doesn&rsquo;t exist</td>
			</tr>
			<tr>
					<td>NODATA</td>
					<td>Domain exists but has no records of the requested type</td>
			</tr>
			<tr>
					<td>Custom IP</td>
					<td>An address of your choice: walled garden or block page</td>
			</tr>
			<tr>
					<td>CNAME</td>
					<td>Redirect to another domain</td>
			</tr>
			<tr>
					<td>Passthru</td>
					<td>The real answer (overrides more general rules)</td>
			</tr>
			<tr>
					<td>Drop</td>
					<td>No response at all</td>
			</tr>
	</tbody>
</table>
<h2 id="enabling-rpz-in-bind">Enabling RPZ in BIND <a class="anchor" data-pagefind-ignore href="#enabling-rpz-in-bind" aria-label="Link to this section">#</a></h2>
<h3 id="basic-configuration">Basic Configuration <a class="anchor" data-pagefind-ignore href="#basic-configuration" aria-label="Link to this section">#</a></h3>
<p>Two parts: the <code>response-policy</code> statement in <code>options</code> lists the policy zones, and each policy zone is a normal zone definition.</p>
<pre tabindex="0"><code>options {
    directory &#34;/var/named&#34;;
    recursion yes;
    allow-recursion { trusted; };
    
    response-policy {
        zone &#34;rpz.local&#34;;
    } qname-wait-recurse no;
};

zone &#34;rpz.local&#34; {
    type primary;
    file &#34;/var/named/rpz/rpz.local.zone&#34;;
    allow-query { none; };
    allow-transfer { none; };
};
</code></pre><ul>
<li><code>allow-query { none; }</code>: clients cannot query the policy zone directly; it is only used internally.</li>
<li><code>allow-transfer { none; }</code>: nobody can download your rules.</li>
</ul>
<p><code>qname-wait-recurse no</code> lets BIND apply QNAME rules without first resolving the real name. With the default (<code>yes</code>), a blocked domain whose own name servers are broken (common for malware domains) returns SERVFAIL instead of your block-page answer.</p>
<h3 id="creating-the-rpz-zone-file">Creating the RPZ Zone File <a class="anchor" data-pagefind-ignore href="#creating-the-rpz-zone-file" aria-label="Link to this section">#</a></h3>
<p>The zone needs a SOA and NS record like any zone; the NS is never used. The rules follow. Owner names have no trailing dot; BIND reads <code>malicious-site.com</code> as a rule for the domain malicious-site.com.</p>
<pre tabindex="0"><code>; /var/named/rpz/rpz.local.zone
$TTL 300
@   IN  SOA localhost. admin.localhost. (
        2024010101  ; Serial
        3600        ; Refresh
        1800        ; Retry
        604800      ; Expire
        300 )       ; Minimum TTL

    IN  NS  localhost.

; Block malicious-site.com (return NXDOMAIN)
malicious-site.com          CNAME   .
*.malicious-site.com        CNAME   .

; Block tracking domain (return NODATA)
tracker.example.com         CNAME   *.

; Redirect phishing site to block page
phishing-site.com           A       192.168.1.100
*.phishing-site.com         A       192.168.1.100

; Allow specific subdomain (passthru)
legit.blocked-domain.com    CNAME   rpz-passthru.

; Block entire domain but redirect to info page
bad-domain.com              CNAME   blocked.example.com.
</code></pre><h2 id="rpz-policy-actions">RPZ Policy Actions <a class="anchor" data-pagefind-ignore href="#rpz-policy-actions" aria-label="Link to this section">#</a></h2>
<p>The action is encoded in the record data. Pick the one that matches what the client should see:</p>
<table>
	<thead>
			<tr>
					<th>Action</th>
					<th>Record</th>
					<th>Use it for</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>NXDOMAIN</td>
					<td><code>CNAME .</code></td>
					<td>Default blocking</td>
			</tr>
			<tr>
					<td>NODATA</td>
					<td><code>CNAME *.</code></td>
					<td>Block a name without claiming it does not exist</td>
			</tr>
			<tr>
					<td>Local data</td>
					<td><code>A</code>, <code>AAAA</code> or <code>CNAME</code> to your host</td>
					<td>Block page or walled garden</td>
			</tr>
			<tr>
					<td>Passthru</td>
					<td><code>CNAME rpz-passthru.</code></td>
					<td>Exceptions to broader rules</td>
			</tr>
			<tr>
					<td>Drop</td>
					<td><code>CNAME rpz-drop.</code></td>
					<td>Silent discard; the client times out</td>
			</tr>
			<tr>
					<td>TCP-only</td>
					<td><code>CNAME rpz-tcp-only.</code></td>
					<td>Force the client to retry over TCP</td>
			</tr>
	</tbody>
</table>
<h3 id="nxdomain-block-domain">NXDOMAIN (Block Domain) <a class="anchor" data-pagefind-ignore href="#nxdomain-block-domain" aria-label="Link to this section">#</a></h3>
<p>Return &ldquo;domain not found&rdquo;. Add the <code>*.</code> wildcard as well, or subdomains still resolve:</p>
<pre tabindex="0"><code>; CNAME to root (.) returns NXDOMAIN
badsite.com         CNAME   .
*.badsite.com       CNAME   .
</code></pre><h3 id="nodata-block-record-type">NODATA (Block Record Type) <a class="anchor" data-pagefind-ignore href="#nodata-block-record-type" aria-label="Link to this section">#</a></h3>
<p>Return &ldquo;no records of requested type&rdquo;:</p>
<pre tabindex="0"><code>; CNAME to wildcard (*.) returns NODATA
tracking.example.com    CNAME   *.
</code></pre><h3 id="custom-response">Custom Response <a class="anchor" data-pagefind-ignore href="#custom-response" aria-label="Link to this section">#</a></h3>
<p>Return specific IP addresses, for example a block page that explains what happened:</p>
<pre tabindex="0"><code>; Redirect to block page
blocked-site.com    A       192.168.1.100
blocked-site.com    AAAA    fd00::100

; Redirect to walled garden
malware.com         CNAME   walled-garden.example.com.
</code></pre><h3 id="passthru-allow">Passthru (Allow) <a class="anchor" data-pagefind-ignore href="#passthru-allow" aria-label="Link to this section">#</a></h3>
<p>Override blocking for specific names. The more specific rule wins over the wildcard:</p>
<pre tabindex="0"><code>; Block entire domain
badsite.com             CNAME   .
*.badsite.com           CNAME   .

; But allow specific subdomain
api.badsite.com         CNAME   rpz-passthru.
</code></pre><h3 id="drop-silent-discard">Drop (Silent Discard) <a class="anchor" data-pagefind-ignore href="#drop-silent-discard" aria-label="Link to this section">#</a></h3>
<p>Silently drop queries (no response sent). The client waits for its timeout, so use this sparingly:</p>
<pre tabindex="0"><code>drop-this.com       CNAME   rpz-drop.
</code></pre><h3 id="tcp-only">TCP-Only <a class="anchor" data-pagefind-ignore href="#tcp-only" aria-label="Link to this section">#</a></h3>
<p>Force TCP retry (rarely used):</p>
<pre tabindex="0"><code>force-tcp.com       CNAME   rpz-tcp-only.
</code></pre><h2 id="trigger-types">Trigger Types <a class="anchor" data-pagefind-ignore href="#trigger-types" aria-label="Link to this section">#</a></h2>
<p>The owner name decides what a rule matches. A suffix marks the trigger type:</p>
<table>
	<thead>
			<tr>
					<th>Trigger</th>
					<th>Owner name</th>
					<th>Matches</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>QNAME</td>
					<td><code>domain</code></td>
					<td>The name the client asked for</td>
			</tr>
			<tr>
					<td>IP</td>
					<td><code>….rpz-ip</code></td>
					<td>Addresses in the answer</td>
			</tr>
			<tr>
					<td>NSIP</td>
					<td><code>….rpz-nsip</code></td>
					<td>IP addresses of the domain&rsquo;s name servers</td>
			</tr>
			<tr>
					<td>NSDNAME</td>
					<td><code>….rpz-nsdname</code></td>
					<td>Names of the domain&rsquo;s name servers</td>
			</tr>
			<tr>
					<td>Client IP</td>
					<td><code>….rpz-client-ip</code></td>
					<td>The address of the client asking</td>
			</tr>
	</tbody>
</table>
<h3 id="qname-triggers">QNAME Triggers <a class="anchor" data-pagefind-ignore href="#qname-triggers" aria-label="Link to this section">#</a></h3>
<p>Match the queried domain name. This is the most common trigger, and what blocklists use:</p>
<pre tabindex="0"><code>; Exact match
badsite.com         CNAME   .

; Wildcard match (all subdomains)
*.badsite.com       CNAME   .
</code></pre><h3 id="ip-triggers">IP Triggers <a class="anchor" data-pagefind-ignore href="#ip-triggers" aria-label="Link to this section">#</a></h3>
<p>Match response IP addresses, to catch any domain that points into a bad network. The owner name is the prefix length followed by the address octets in reverse order:</p>
<pre tabindex="0"><code>; Block any response containing 10.20.30.40
32.40.30.20.10.rpz-ip    CNAME   .

; Block responses in 192.168.1.0/24
24.0.1.168.192.rpz-ip    CNAME   .
</code></pre><h3 id="nsip-triggers">NSIP Triggers <a class="anchor" data-pagefind-ignore href="#nsip-triggers" aria-label="Link to this section">#</a></h3>
<p>Match nameserver IP addresses. Useful when many bad domains share the same name servers:</p>
<pre tabindex="0"><code>; Block domains hosted on nameserver IP 10.20.30.40
32.40.30.20.10.rpz-nsip  CNAME   .
</code></pre><h3 id="nsdname-triggers">NSDNAME Triggers <a class="anchor" data-pagefind-ignore href="#nsdname-triggers" aria-label="Link to this section">#</a></h3>
<p>Match nameserver domain names:</p>
<pre tabindex="0"><code>; Block domains using this nameserver
ns.malicious-hosting.com.rpz-nsdname    CNAME   .
</code></pre><h3 id="client-ip-triggers">Client IP Triggers <a class="anchor" data-pagefind-ignore href="#client-ip-triggers" aria-label="Link to this section">#</a></h3>
<p>Match client IP addresses, to give one client a different policy:</p>
<pre tabindex="0"><code>; Different policy for client 192.168.1.50
32.50.1.168.192.rpz-client-ip  CNAME   rpz-passthru.
</code></pre><h2 id="multiple-rpz-zones">Multiple RPZ Zones <a class="anchor" data-pagefind-ignore href="#multiple-rpz-zones" aria-label="Link to this section">#</a></h2>
<p>Split rules by source: your own overrides, and one zone per feed. Each can be managed and updated separately.</p>
<pre tabindex="0"><code>options {
    response-policy {
        zone &#34;rpz-local&#34; policy given;      # Local overrides
        zone &#34;rpz-malware&#34; policy given;    # Malware blocklist
        zone &#34;rpz-phishing&#34; policy given;   # Phishing blocklist
        zone &#34;rpz-ads&#34; policy given;        # Ad blocking
    };
};

zone &#34;rpz-local&#34; {
    type primary;
    file &#34;/var/named/rpz/local.zone&#34;;
};

zone &#34;rpz-malware&#34; {
    type secondary;
    file &#34;/var/named/rpz/malware.zone&#34;;
    primaries { 192.168.1.10; };
};

zone &#34;rpz-phishing&#34; {
    type secondary;
    file &#34;/var/named/rpz/phishing.zone&#34;;
    primaries { 192.168.1.10; };
};

zone &#34;rpz-ads&#34; {
    type secondary;
    file &#34;/var/named/rpz/ads.zone&#34;;
    primaries { 192.168.1.10; };
};
</code></pre><ul>
<li><code>policy given</code>: use the action from the zone&rsquo;s records (the default).</li>
<li>The feed zones are slave zones, transferred from the master at 192.168.1.10. One server maintains the lists for many resolvers.</li>
</ul>
<p>Zones are evaluated in order - first match wins. Put your own overrides first.</p>
<h2 id="using-external-blocklists">Using External Blocklists <a class="anchor" data-pagefind-ignore href="#using-external-blocklists" aria-label="Link to this section">#</a></h2>
<h3 id="converting-blocklists-to-rpz-format">Converting Blocklists to RPZ Format <a class="anchor" data-pagefind-ignore href="#converting-blocklists-to-rpz-format" aria-label="Link to this section">#</a></h3>
<p>Many blocklists are available in hosts file format. This script writes a SOA, NS and one <code>CNAME .</code> (NXDOMAIN) rule per domain. The serial is based on the current hour, so every run produces a higher serial.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="cp">#!/bin/bash
</span></span></span><span class="line"><span class="cl"><span class="c1"># convert-blocklist.sh</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nv">INPUT</span><span class="o">=</span><span class="s2">&#34;</span><span class="nv">$1</span><span class="s2">&#34;</span>
</span></span><span class="line"><span class="cl"><span class="nv">OUTPUT</span><span class="o">=</span><span class="s2">&#34;</span><span class="nv">$2</span><span class="s2">&#34;</span>
</span></span><span class="line"><span class="cl"><span class="nv">SOA_SERIAL</span><span class="o">=</span><span class="k">$(</span>date +%Y%m%d%H<span class="k">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">cat &gt; <span class="s2">&#34;</span><span class="nv">$OUTPUT</span><span class="s2">&#34;</span> <span class="s">&lt;&lt; EOF
</span></span></span><span class="line"><span class="cl"><span class="s">\$TTL 300
</span></span></span><span class="line"><span class="cl"><span class="s">@   IN  SOA localhost. admin.localhost. (
</span></span></span><span class="line"><span class="cl"><span class="s">        $SOA_SERIAL  ; Serial
</span></span></span><span class="line"><span class="cl"><span class="s">        3600         ; Refresh
</span></span></span><span class="line"><span class="cl"><span class="s">        1800         ; Retry
</span></span></span><span class="line"><span class="cl"><span class="s">        604800       ; Expire
</span></span></span><span class="line"><span class="cl"><span class="s">        300 )        ; Minimum TTL
</span></span></span><span class="line"><span class="cl"><span class="s">
</span></span></span><span class="line"><span class="cl"><span class="s">    IN  NS  localhost.
</span></span></span><span class="line"><span class="cl"><span class="s">
</span></span></span><span class="line"><span class="cl"><span class="s">; Converted from $INPUT
</span></span></span><span class="line"><span class="cl"><span class="s">EOF</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Convert hosts file format (0.0.0.0 domain or 127.0.0.1 domain)</span>
</span></span><span class="line"><span class="cl">grep -E <span class="s2">&#34;^(0\.0\.0\.0|127\.0\.0\.1)&#34;</span> <span class="s2">&#34;</span><span class="nv">$INPUT</span><span class="s2">&#34;</span> <span class="p">|</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">    awk <span class="s1">&#39;{print $2}&#39;</span> <span class="p">|</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">    grep -v localhost <span class="p">|</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">    grep -v <span class="s1">&#39;^0\.0\.0\.0$&#39;</span> <span class="p">|</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">    sort -u <span class="p">|</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">    <span class="k">while</span> <span class="nb">read</span> domain<span class="p">;</span> <span class="k">do</span>
</span></span><span class="line"><span class="cl">        <span class="nb">echo</span> <span class="s2">&#34;</span><span class="nv">$domain</span><span class="s2"> CNAME .&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="k">done</span> &gt;&gt; <span class="s2">&#34;</span><span class="nv">$OUTPUT</span><span class="s2">&#34;</span>
</span></span></code></pre></div><p>Usage:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">./convert-blocklist.sh hosts.txt /var/named/rpz/blocklist.zone
</span></span><span class="line"><span class="cl">rndc reload rpz-blocklist
</span></span></code></pre></div><p>This assumes a zone <code>rpz-blocklist</code> with file <code>/var/named/rpz/blocklist.zone</code> is defined and listed in <code>response-policy</code>, like the zones in the complete example below. BIND applies RPZ changes at most once per <code>min-update-interval</code> (60 seconds by default), so new rules can take up to a minute to take effect.</p>
<h3 id="popular-blocklist-sources">Popular Blocklist Sources <a class="anchor" data-pagefind-ignore href="#popular-blocklist-sources" aria-label="Link to this section">#</a></h3>
<table>
	<thead>
			<tr>
					<th>Source</th>
					<th>Covers</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Steven Black&rsquo;s hosts</td>
					<td>Unified hosts with multiple extensions</td>
			</tr>
			<tr>
					<td>OISD</td>
					<td>Comprehensive ad/tracking blocklist</td>
			</tr>
			<tr>
					<td>URLhaus</td>
					<td>Malware URL blocklist</td>
			</tr>
			<tr>
					<td>PhishTank</td>
					<td>Phishing URL database</td>
			</tr>
			<tr>
					<td>Spamhaus</td>
					<td>Malware and botnet domains</td>
			</tr>
	</tbody>
</table>
<h3 id="automated-updates">Automated Updates <a class="anchor" data-pagefind-ignore href="#automated-updates" aria-label="Link to this section">#</a></h3>
<p>Blocklists change daily. This script downloads the list, converts it, fixes permissions and reloads the zone. <code>curl -f</code> aborts on HTTP errors, so a failed download does not replace the zone with an empty one.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="cp">#!/bin/bash
</span></span></span><span class="line"><span class="cl"><span class="c1"># /usr/local/bin/update-rpz.sh</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nv">RPZ_DIR</span><span class="o">=</span><span class="s2">&#34;/var/named/rpz&#34;</span>
</span></span><span class="line"><span class="cl"><span class="nv">BLOCKLIST_URL</span><span class="o">=</span><span class="s2">&#34;https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Download blocklist (abort on HTTP errors, or a failed download empties the zone)</span>
</span></span><span class="line"><span class="cl">curl -fsS <span class="s2">&#34;</span><span class="nv">$BLOCKLIST_URL</span><span class="s2">&#34;</span> -o /tmp/blocklist.txt <span class="o">||</span> <span class="nb">exit</span> <span class="m">1</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Convert to RPZ format</span>
</span></span><span class="line"><span class="cl">/usr/local/bin/convert-blocklist.sh /tmp/blocklist.txt <span class="s2">&#34;</span><span class="nv">$RPZ_DIR</span><span class="s2">/blocklist.zone&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Fix permissions</span>
</span></span><span class="line"><span class="cl">chown named:named <span class="s2">&#34;</span><span class="nv">$RPZ_DIR</span><span class="s2">/blocklist.zone&#34;</span>
</span></span><span class="line"><span class="cl">chmod <span class="m">640</span> <span class="s2">&#34;</span><span class="nv">$RPZ_DIR</span><span class="s2">/blocklist.zone&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Reload zone</span>
</span></span><span class="line"><span class="cl">rndc reload rpz-blocklist
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Cleanup</span>
</span></span><span class="line"><span class="cl">rm /tmp/blocklist.txt
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="nb">echo</span> <span class="s2">&#34;RPZ blocklist updated: </span><span class="k">$(</span>date<span class="k">)</span><span class="s2">&#34;</span>
</span></span></code></pre></div><p>Schedule with cron:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># Update blocklist daily at 3 AM</span>
</span></span><span class="line"><span class="cl"><span class="m">0</span> <span class="m">3</span> * * * /usr/local/bin/update-rpz.sh &gt;&gt; /var/log/rpz-update.log 2&gt;<span class="p">&amp;</span><span class="m">1</span>
</span></span></code></pre></div><h2 id="creating-a-block-page">Creating a Block Page <a class="anchor" data-pagefind-ignore href="#creating-a-block-page" aria-label="Link to this section">#</a></h2>
<p>Optional. With NXDOMAIN users just see &ldquo;site not found&rdquo;; a block page tells them the site was blocked on purpose and who to contact. It only works for plain HTTP; HTTPS sites show a certificate error instead.</p>
<h3 id="nginx-configuration">Nginx Configuration <a class="anchor" data-pagefind-ignore href="#nginx-configuration" aria-label="Link to this section">#</a></h3>
<p>Serve the same page for every path, whatever URL the user tried:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-nginx" data-lang="nginx"><span class="line"><span class="cl"><span class="k">server</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="kn">listen</span> <span class="mi">80</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="kn">server_name</span> <span class="s">blocked.example.com</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    
</span></span><span class="line"><span class="cl">    <span class="kn">root</span> <span class="s">/var/www/blocked</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    
</span></span><span class="line"><span class="cl">    <span class="kn">location</span> <span class="s">/</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="kn">try_files</span> <span class="nv">$uri</span> <span class="s">/index.html</span><span class="p">;</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><h3 id="block-page-html">Block Page HTML <a class="anchor" data-pagefind-ignore href="#block-page-html" aria-label="Link to this section">#</a></h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-html" data-lang="html"><span class="line"><span class="cl"><span class="cp">&lt;!DOCTYPE html&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="p">&lt;</span><span class="nt">title</span><span class="p">&gt;</span>Access Blocked<span class="p">&lt;/</span><span class="nt">title</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="p">&lt;</span><span class="nt">style</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">        <span class="nt">body</span> <span class="p">{</span> <span class="k">font-family</span><span class="p">:</span> <span class="kc">sans-serif</span><span class="p">;</span> <span class="k">text-align</span><span class="p">:</span> <span class="kc">center</span><span class="p">;</span> <span class="k">padding</span><span class="p">:</span> <span class="mi">50</span><span class="kt">px</span><span class="p">;</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="nt">h1</span> <span class="p">{</span> <span class="k">color</span><span class="p">:</span> <span class="mh">#d32f2f</span><span class="p">;</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="p">.</span><span class="nc">info</span> <span class="p">{</span> <span class="k">color</span><span class="p">:</span> <span class="mh">#666</span><span class="p">;</span> <span class="k">margin-top</span><span class="p">:</span> <span class="mi">20</span><span class="kt">px</span><span class="p">;</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="p">&lt;/</span><span class="nt">style</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span>Access Blocked<span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>This site has been blocked by your network administrator.<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="p">&lt;</span><span class="nt">div</span> <span class="na">class</span><span class="o">=</span><span class="s">&#34;info&#34;</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">        <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>If you believe this is an error, please contact IT support.<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">        <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>Blocked domain: <span class="p">&lt;</span><span class="nt">script</span><span class="p">&gt;</span><span class="nb">document</span><span class="p">.</span><span class="nx">write</span><span class="p">(</span><span class="nx">location</span><span class="p">.</span><span class="nx">hostname</span><span class="p">);&lt;/</span><span class="nt">script</span><span class="p">&gt;&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl">    <span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
</span></span><span class="line"><span class="cl"><span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</span></span></code></pre></div><h3 id="rpz-configuration-for-block-page">RPZ Configuration for Block Page <a class="anchor" data-pagefind-ignore href="#rpz-configuration-for-block-page" aria-label="Link to this section">#</a></h3>
<p>Point blocked domains at the web server, by address or by name:</p>
<pre tabindex="0"><code>; Redirect blocked domains to block page
bad-domain.com          A       192.168.1.100
*.bad-domain.com        A       192.168.1.100

; Or use CNAME
bad-domain.com          CNAME   blocked.example.com.
</code></pre><h2 id="logging-rpz-actions">Logging RPZ Actions <a class="anchor" data-pagefind-ignore href="#logging-rpz-actions" aria-label="Link to this section">#</a></h2>
<p>Send the <code>rpz</code> category to its own file. Every rewrite is logged with the client, the name and the matching zone.</p>
<pre tabindex="0"><code>logging {
    channel rpz_log {
        file &#34;/var/log/named/rpz.log&#34; versions 10 size 50m;
        severity info;
        print-time yes;
        print-category yes;
        print-severity yes;
    };
    
    category rpz { rpz_log; };
};
</code></pre><p>Log format shows:</p>
<ul>
<li>Query that triggered RPZ</li>
<li>Which RPZ zone matched</li>
<li>What action was taken</li>
<li>Client IP address</li>
</ul>
<h3 id="analyzing-rpz-logs">Analyzing RPZ Logs <a class="anchor" data-pagefind-ignore href="#analyzing-rpz-logs" aria-label="Link to this section">#</a></h3>
<p>Two quick reports from today&rsquo;s log: the most blocked domains, and the clients that trigger the most blocks (often an infected machine).</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># Top blocked domains today</span>
</span></span><span class="line"><span class="cl">grep <span class="s2">&#34;</span><span class="k">$(</span>date +%d-%b-%Y<span class="k">)</span><span class="s2">&#34;</span> /var/log/named/rpz.log <span class="p">|</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">    grep -oP <span class="s2">&#34;rpz QNAME \S+ rewrite \K[^/]+&#34;</span> <span class="p">|</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">    sort <span class="p">|</span> uniq -c <span class="p">|</span> sort -rn <span class="p">|</span> head -20
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Clients triggering most blocks</span>
</span></span><span class="line"><span class="cl">grep <span class="s2">&#34;</span><span class="k">$(</span>date +%d-%b-%Y<span class="k">)</span><span class="s2">&#34;</span> /var/log/named/rpz.log <span class="p">|</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">    grep -oP <span class="s2">&#34;client @0x[0-9a-f]+ \K[0-9.]+&#34;</span> <span class="p">|</span> <span class="se">\
</span></span></span><span class="line"><span class="cl">    sort <span class="p">|</span> uniq -c <span class="p">|</span> sort -rn <span class="p">|</span> head -10
</span></span></code></pre></div><h2 id="whitelisting">Whitelisting <a class="anchor" data-pagefind-ignore href="#whitelisting" aria-label="Link to this section">#</a></h2>
<p>Blocklists contain false positives. A whitelist zone with passthru rules lets you fix those locally without editing the feed.</p>
<pre tabindex="0"><code>; /var/named/rpz/whitelist.zone
$TTL 300
@   IN  SOA localhost. admin.localhost. (
        2024010101  ; Serial
        3600        ; Refresh
        1800        ; Retry
        604800      ; Expire
        300 )       ; Minimum TTL

    IN  NS  localhost.

; Whitelist entries (passthru overrides blocking)
legitimate-site.com         CNAME   rpz-passthru.
*.legitimate-site.com       CNAME   rpz-passthru.

required-service.example.com CNAME  rpz-passthru.
</code></pre><p>Place whitelist zone first, because the first matching zone wins:</p>
<pre tabindex="0"><code>response-policy {
    zone &#34;rpz-whitelist&#34;;     # Check whitelist first
    zone &#34;rpz-malware&#34;;
    zone &#34;rpz-ads&#34;;
};
</code></pre><h2 id="performance-considerations">Performance Considerations <a class="anchor" data-pagefind-ignore href="#performance-considerations" aria-label="Link to this section">#</a></h2>
<h3 id="update-interval-and-ttl">Update Interval and TTL <a class="anchor" data-pagefind-ignore href="#update-interval-and-ttl" aria-label="Link to this section">#</a></h3>
<p>Large blocklists cost memory and reload time. Two settings per zone control how often changes are applied and how long rewritten answers are cached:</p>
<pre tabindex="0"><code>options {
    response-policy {
        zone &#34;rpz-blocklist&#34; 
            max-policy-ttl 300
            min-update-interval 60;
    };
};
</code></pre><ul>
<li><code>max-policy-ttl 300</code>: rewritten answers have a TTL of at most 5 minutes, so an unblocked domain works again quickly.</li>
<li><code>min-update-interval 60</code>: apply zone updates at most once a minute; raise it for very large zones that update often.</li>
</ul>
<h3 id="nsipnsdname-performance">NSIP/NSDNAME Performance <a class="anchor" data-pagefind-ignore href="#nsipnsdname-performance" aria-label="Link to this section">#</a></h3>
<p>NSIP and NSDNAME triggers require additional lookups of the name servers. Turn them off for zones that only contain QNAME rules:</p>
<pre tabindex="0"><code>// Disable expensive triggers if not needed
options {
    response-policy {
        zone &#34;rpz-blocklist&#34; nsip-enable no nsdname-enable no;
    };
};
</code></pre><h3 id="recursive-queries">Recursive Queries <a class="anchor" data-pagefind-ignore href="#recursive-queries" aria-label="Link to this section">#</a></h3>
<p>RPZ only affects recursive queries. For authoritative-only servers, RPZ has no effect.</p>
<h2 id="complete-configuration-example">Complete Configuration Example <a class="anchor" data-pagefind-ignore href="#complete-configuration-example" aria-label="Link to this section">#</a></h2>
<p>A validating resolver with a whitelist and three blocklist zones:</p>
<pre tabindex="0"><code>// /etc/named.conf

acl &#34;trusted&#34; {
    localhost;
    localnets;
    192.168.0.0/16;
};

options {
    directory &#34;/var/named&#34;;
    
    recursion yes;
    allow-recursion { trusted; };
    
    dnssec-validation auto;
    
    response-policy {
        zone &#34;rpz-whitelist&#34; policy passthru;
        zone &#34;rpz-malware&#34; policy given;
        zone &#34;rpz-phishing&#34; policy given;
        zone &#34;rpz-ads&#34; policy given;
    } qname-wait-recurse no;
};

logging {
    channel rpz_log {
        file &#34;/var/log/named/rpz.log&#34; versions 10 size 50m;
        severity info;
        print-time yes;
        print-category yes;
    };
    
    category rpz { rpz_log; };
};

zone &#34;rpz-whitelist&#34; {
    type primary;
    file &#34;/var/named/rpz/whitelist.zone&#34;;
    allow-query { none; };
};

zone &#34;rpz-malware&#34; {
    type primary;
    file &#34;/var/named/rpz/malware.zone&#34;;
    allow-query { none; };
};

zone &#34;rpz-phishing&#34; {
    type primary;
    file &#34;/var/named/rpz/phishing.zone&#34;;
    allow-query { none; };
};

zone &#34;rpz-ads&#34; {
    type primary;
    file &#34;/var/named/rpz/ads.zone&#34;;
    allow-query { none; };
};

zone &#34;.&#34; {
    type hint;
    file &#34;named.ca&#34;;
};
</code></pre><ul>
<li><code>policy passthru</code> on <code>rpz-whitelist</code>: every name in that zone resolves normally, whatever its record says.</li>
<li><code>policy given</code> on the blocklists: use the action from each record.</li>
</ul>
<h2 id="testing-rpz">Testing RPZ <a class="anchor" data-pagefind-ignore href="#testing-rpz" aria-label="Link to this section">#</a></h2>
<h3 id="verify-blocking">Verify Blocking <a class="anchor" data-pagefind-ignore href="#verify-blocking" aria-label="Link to this section">#</a></h3>
<p>Query a domain from your blocklist and check the log:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># Query blocked domain</span>
</span></span><span class="line"><span class="cl">dig @localhost blocked-domain.com
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Should return NXDOMAIN or your block page IP</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Check RPZ logs</span>
</span></span><span class="line"><span class="cl">tail -f /var/log/named/rpz.log
</span></span></code></pre></div><h3 id="test-passthru">Test Passthru <a class="anchor" data-pagefind-ignore href="#test-passthru" aria-label="Link to this section">#</a></h3>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># Verify whitelisted domain resolves normally</span>
</span></span><span class="line"><span class="cl">dig @localhost whitelisted-domain.com
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Should return actual IP, not blocked</span>
</span></span></code></pre></div><h3 id="debug-mode">Debug Mode <a class="anchor" data-pagefind-ignore href="#debug-mode" aria-label="Link to this section">#</a></h3>
<p>If a rule does not fire, turn on query logging temporarily to see what clients actually ask:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">rndc querylog on
</span></span><span class="line"><span class="cl"><span class="c1"># Run tests</span>
</span></span><span class="line"><span class="cl">rndc querylog off
</span></span></code></pre></div><h2 id="troubleshooting">Troubleshooting <a class="anchor" data-pagefind-ignore href="#troubleshooting" aria-label="Link to this section">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Symptom</th>
					<th>Likely cause</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Blocked domain still resolves</td>
					<td>Zone not listed in <code>response-policy</code>, missing <code>*.</code> rule for subdomains, or update not yet applied (<code>min-update-interval</code>)</td>
			</tr>
			<tr>
					<td>SERVFAIL instead of block answer</td>
					<td><code>qname-wait-recurse</code> left at <code>yes</code> and the domain&rsquo;s name servers are broken</td>
			</tr>
			<tr>
					<td>Whitelisted domain still blocked</td>
					<td>Whitelist zone is not listed first</td>
			</tr>
			<tr>
					<td>No effect at all</td>
					<td>Client uses another resolver, or the server is authoritative-only</td>
			</tr>
	</tbody>
</table>
<h2 id="automate-it">Automate it <a class="anchor" data-pagefind-ignore href="#automate-it" aria-label="Link to this section">#</a></h2>
<p>The Ansible roles and Terraform code that build this setup are on GitHub: <a href="https://github.com/pderuiter/blog-bind-rpz" rel="noopener">pderuiter/blog-bind-rpz</a>. It creates an Ubuntu 24.04 VM on Proxmox and builds the resolver from this post with the whitelist, local and blocklist RPZ zones, the conversion and daily update scripts and RPZ logging (the block page is optional); run <code>terraform apply</code>, then <code>ansible-playbook site.yml</code>.</p>
<h2 id="conclusion">Conclusion <a class="anchor" data-pagefind-ignore href="#conclusion" aria-label="Link to this section">#</a></h2>
<p>Response Policy Zones provide DNS-level security without client software or network proxies. Combine regularly updated blocklists, a local whitelist and logging for an effective first line of defense against malware, phishing and unwanted content.</p>
<p>The next post will cover DNS over TLS (DoT), adding transport encryption to your DNS infrastructure for privacy and security.</p>
]]></content:encoded></item></channel></rss>