<?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>rndc | A DevOps Blog</title><link>https://blog.bsdserver.nl/tag/rndc/</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/rndc/rss/" rel="self" type="application/rss+xml"/><ttl>60</ttl><item><title>How to Configure BIND RNDC and TSIG Keys for Remote DNS Management</title><link>https://blog.bsdserver.nl/how-to-configure-bind-rndc-and-tsig-keys-for-remote-dns-management/</link><guid isPermaLink="false">693b6bae79eb54000160a54e</guid><dc:creator>Patrick de Ruiter</dc:creator><pubDate>Fri, 12 Dec 2025 01:11:10 +0000</pubDate><description>RNDC (Remote Name Daemon Control) is the administrative tool for managing BIND DNS servers.</description><category>BIND</category><category>DNS</category><category>rndc</category><category>TSIG</category><category>Security</category><category>Linux</category><media:content url="https://blog.bsdserver.nl/content/images/2026/01/bind-rndc-tsig.png" medium="image"/><content:encoded><![CDATA[<p>RNDC (Remote Name Daemon Control) is the administrative tool for managing BIND DNS servers. It reloads zones, flushes caches and shows statistics without restarting the service.</p>
<p>This post sets up RNDC keys for local and remote administration, a read-only channel for monitoring, and TSIG keys that authenticate zone transfers between master and slave.</p>
<h2 id="why-rndc-and-tsig">Why RNDC and TSIG? <a class="anchor" data-pagefind-ignore href="#why-rndc-and-tsig" aria-label="Link to this section">#</a></h2>
<ul>
<li><strong>No restarts</strong>: reload a zone or the configuration while <code>named</code> keeps answering.</li>
<li><strong>Remote control</strong>: manage several DNS servers from one admin workstation.</li>
<li><strong>Authenticated</strong>: every command and every zone transfer is signed with a shared secret.</li>
<li><strong>Least privilege</strong>: separate keys and read-only channels for monitoring.</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 every BIND server: local RNDC is the normal way to reload zones. Add remote access and TSIG when you run more than one server.</li>
<li><strong>Skip</strong> remote RNDC if you manage servers only over SSH; keep the local channel.</li>
</ul>
<h2 id="how-it-works">How It Works <a class="anchor" data-pagefind-ignore href="#how-it-works" aria-label="Link to this section">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Piece</th>
					<th>Protects</th>
					<th>Where</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>RNDC key + <code>controls</code></td>
					<td>Admin commands to <code>named</code></td>
					<td>TCP port 953 (by default)</td>
			</tr>
			<tr>
					<td><code>rndc.conf</code></td>
					<td>Which key and server the <code>rndc</code> client uses</td>
					<td>Admin workstation or the server itself</td>
			</tr>
			<tr>
					<td>TSIG transfer key</td>
					<td>Zone transfers and NOTIFY between master and slave</td>
					<td>Port 53, inside the DNS messages</td>
			</tr>
	</tbody>
</table>
<p>Both use the same mechanism: a shared HMAC secret. <strong>RNDC</strong> signs each command with it; <strong>TSIG</strong> (Transaction Signature) signs DNS messages with it. A message without a valid signature is rejected.</p>
<p>The flow for a remote reload: <code>rndc -s dns1 reload</code> → the client signs the command with the key from <code>rndc.conf</code> → <code>named</code> checks the source IP against <code>allow</code> and the signature against <code>keys</code> → runs the command.</p>
<h2 id="generating-rndc-keys">Generating RNDC Keys <a class="anchor" data-pagefind-ignore href="#generating-rndc-keys" aria-label="Link to this section">#</a></h2>
<table>
	<thead>
			<tr>
					<th>Command</th>
					<th>Use it for</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>rndc-confgen -a</code></td>
					<td>Local administration only; writes a key file <code>named</code> reads automatically</td>
			</tr>
			<tr>
					<td><code>rndc-confgen</code></td>
					<td>Remote administration; prints a full <code>rndc.conf</code> and the matching <code>named.conf</code> snippet</td>
			</tr>
			<tr>
					<td><code>tsig-keygen</code></td>
					<td>Zone transfer and dynamic update keys (see below)</td>
			</tr>
	</tbody>
</table>
<h3 id="automatic-generation">Automatic Generation <a class="anchor" data-pagefind-ignore href="#automatic-generation" aria-label="Link to this section">#</a></h3>
<p>The simplest way to set up RNDC is using <code>rndc-confgen</code> with the <code>-a</code> flag:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">rndc-confgen -a
</span></span></code></pre></div><p>This creates <code>/etc/rndc.key</code> (RHEL) or <code>/etc/bind/rndc.key</code> (Debian/Ubuntu) with a randomly generated key:</p>
<pre tabindex="0"><code>key &#34;rndc-key&#34; {
    algorithm hmac-sha256;
    secret &#34;base64-encoded-secret&#34;;
};
</code></pre><p>BIND automatically includes this file, so no additional configuration is needed for local administration. However, <code>rndc-confgen -a</code> creates the file mode <code>0600</code> and owned by root, so <code>named</code>, which runs as <code>named</code> (RHEL) or <code>bind</code> (Debian/Ubuntu), cannot read it. The log then shows <code>open: /etc/rndc.key: permission denied</code> and <code>rndc</code> fails with <code>connection to remote host closed</code>. Either pass the daemon user with <code>-u</code>, or fix ownership afterwards and restart <code>named</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">rndc-confgen -a -u named          <span class="c1"># Debian/Ubuntu: -u bind</span>
</span></span><span class="line"><span class="cl"><span class="c1"># or</span>
</span></span><span class="line"><span class="cl">chown root:named /etc/rndc.key <span class="o">&amp;&amp;</span> chmod <span class="m">640</span> /etc/rndc.key
</span></span></code></pre></div><h3 id="manual-generation">Manual Generation <a class="anchor" data-pagefind-ignore href="#manual-generation" aria-label="Link to this section">#</a></h3>
<p>For remote administration you need the key on both sides. Without <code>-a</code>, <code>rndc-confgen</code> prints both halves:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">rndc-confgen
</span></span></code></pre></div><p>This outputs both the <code>rndc.conf</code> content and the corresponding <code>named.conf</code> additions:</p>
<pre tabindex="0"><code># Start of rndc.conf
key &#34;rndc-key&#34; {
    algorithm hmac-sha256;
    secret &#34;wImDGsj5MxtGQl1nL0V2V/eTlpKs3VdS4nKxEhJVyKY=&#34;;
};

options {
    default-key &#34;rndc-key&#34;;
    default-server 127.0.0.1;
    default-port 953;
};
# End of rndc.conf

# Use with the following in named.conf, adjusting the allow list as needed:
# key &#34;rndc-key&#34; {
#     algorithm hmac-sha256;
#     secret &#34;wImDGsj5MxtGQl1nL0V2V/eTlpKs3VdS4nKxEhJVyKY=&#34;;
# };
#
# controls {
#     inet 127.0.0.1 port 953
#         allow { 127.0.0.1; } keys { &#34;rndc-key&#34;; };
# };
# End of named.conf
</code></pre><h3 id="specifying-key-algorithm">Specifying Key Algorithm <a class="anchor" data-pagefind-ignore href="#specifying-key-algorithm" aria-label="Link to this section">#</a></h3>
<p>BIND supports several HMAC algorithms. <code>-A</code> picks the algorithm and <code>-k</code> the key name; both sides must use the same.</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"># SHA-256 (recommended)</span>
</span></span><span class="line"><span class="cl">rndc-confgen -a -A hmac-sha256
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># SHA-512 (strongest)</span>
</span></span><span class="line"><span class="cl">rndc-confgen -a -A hmac-sha512
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Custom key name</span>
</span></span><span class="line"><span class="cl">rndc-confgen -a -k my-admin-key
</span></span></code></pre></div><h2 id="configuring-namedconf">Configuring named.conf <a class="anchor" data-pagefind-ignore href="#configuring-namedconf" aria-label="Link to this section">#</a></h2>
<h3 id="the-controls-statement">The Controls Statement <a class="anchor" data-pagefind-ignore href="#the-controls-statement" aria-label="Link to this section">#</a></h3>
<p>The <code>controls</code> statement decides where <code>named</code> listens for RNDC, who may connect and with which key. Without a <code>controls</code> statement, <code>named</code> listens on localhost and uses <code>rndc.key</code>.</p>
<pre tabindex="0"><code>controls {
    inet 127.0.0.1 port 953
        allow { 127.0.0.1; } keys { &#34;rndc-key&#34;; };
};
</code></pre><ul>
<li><code>inet 127.0.0.1</code>: listen address.</li>
<li><code>port 953</code>: TCP port (953 is the default).</li>
<li><code>allow { 127.0.0.1; }</code>: IP addresses allowed to connect.</li>
<li><code>keys { &quot;rndc-key&quot;; }</code>: keys accepted for authentication. A client needs both an allowed IP and a valid key.</li>
</ul>
<h3 id="enabling-remote-administration">Enabling Remote Administration <a class="anchor" data-pagefind-ignore href="#enabling-remote-administration" aria-label="Link to this section">#</a></h3>
<p>To manage BIND from remote hosts, add a second <code>inet</code> line on the server&rsquo;s LAN address. The <code>admin-hosts</code> ACL limits it to the admin network; the localhost channel stays for local use.</p>
<pre tabindex="0"><code>key &#34;rndc-key&#34; {
    algorithm hmac-sha256;
    secret &#34;wImDGsj5MxtGQl1nL0V2V/eTlpKs3VdS4nKxEhJVyKY=&#34;;
};

acl &#34;admin-hosts&#34; {
    127.0.0.1;
    192.168.1.10;        # Admin workstation
    192.168.1.0/24;      # Admin network
};

controls {
    inet 127.0.0.1 port 953
        allow { 127.0.0.1; } keys { &#34;rndc-key&#34;; };
    inet 192.168.1.1 port 953
        allow { admin-hosts; } keys { &#34;rndc-key&#34;; };
};
</code></pre><h3 id="multiple-keys-for-different-access-levels">Multiple Keys for Different Access Levels <a class="anchor" data-pagefind-ignore href="#multiple-keys-for-different-access-levels" aria-label="Link to this section">#</a></h3>
<p>Separate keys let you revoke one system without touching the others. Every key listed on a control channel gets full control (including <code>rndc stop</code>) unless that channel is marked <code>read-only yes</code>. One <code>inet</code> address/port has only one read-only setting, so give the monitoring key its own port:</p>
<table>
	<thead>
			<tr>
					<th>Channel</th>
					<th>Key</th>
					<th>Access</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>127.0.0.1:953</code></td>
					<td><code>admin-key</code></td>
					<td>Full, local</td>
			</tr>
			<tr>
					<td><code>192.168.1.1:953</code></td>
					<td><code>admin-key</code></td>
					<td>Full, from the admin network</td>
			</tr>
			<tr>
					<td><code>192.168.1.1:954</code></td>
					<td><code>monitoring-key</code></td>
					<td>Read-only (status, stats)</td>
			</tr>
	</tbody>
</table>
<pre tabindex="0"><code>key &#34;admin-key&#34; {
    algorithm hmac-sha256;
    secret &#34;first-secret-here&#34;;
};

key &#34;monitoring-key&#34; {
    algorithm hmac-sha256;
    secret &#34;second-secret-here&#34;;
};

key &#34;secondary-ns-key&#34; {
    algorithm hmac-sha256;
    secret &#34;third-secret-here&#34;;
};

controls {
    inet 127.0.0.1 port 953
        allow { 127.0.0.1; } keys { &#34;admin-key&#34;; };
    inet 192.168.1.1 port 953
        allow { 192.168.1.0/24; } keys { &#34;admin-key&#34;; };
    // Monitoring: status/stats only, write commands are rejected
    inet 192.168.1.1 port 954
        allow { 192.168.1.0/24; } keys { &#34;monitoring-key&#34;; } read-only yes;
};
</code></pre><p>The monitoring system then connects with <code>rndc -p 954 ... status</code>.</p>
<h2 id="configuring-rndcconf">Configuring rndc.conf <a class="anchor" data-pagefind-ignore href="#configuring-rndcconf" aria-label="Link to this section">#</a></h2>
<p><code>rndc.conf</code> is the client side: which key to sign with and which server to talk to. It lives in <code>/etc/rndc.conf</code> (RHEL) or <code>/etc/bind/rndc.conf</code> (Debian/Ubuntu; <code>rndc</code> ignores <code>/etc/rndc.conf</code> there). When it exists it takes precedence over <code>rndc.key</code>.</p>
<ul>
<li><code>options</code>: the defaults when you run <code>rndc</code> without <code>-s</code>.</li>
<li><code>server</code> blocks: per-server key and port, selected with <code>rndc -s &lt;name&gt;</code>.</li>
</ul>
<pre tabindex="0"><code>key &#34;rndc-key&#34; {
    algorithm hmac-sha256;
    secret &#34;wImDGsj5MxtGQl1nL0V2V/eTlpKs3VdS4nKxEhJVyKY=&#34;;
};

options {
    default-key &#34;rndc-key&#34;;
    default-server 127.0.0.1;
    default-port 953;
};

# Define additional servers
server dns1.example.com {
    key &#34;rndc-key&#34;;
    port 953;
};

server dns2.example.com {
    key &#34;rndc-key&#34;;
    port 953;
};
</code></pre><p>With multiple servers defined, specify which to manage:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">rndc -s dns1.example.com reload
</span></span><span class="line"><span class="cl">rndc -s dns2.example.com reload
</span></span></code></pre></div><h2 id="tsig-keys-for-zone-transfers">TSIG Keys for Zone Transfers <a class="anchor" data-pagefind-ignore href="#tsig-keys-for-zone-transfers" aria-label="Link to this section">#</a></h2>
<p>Without TSIG, a zone transfer is only protected by the IP in <code>allow-transfer</code>. A TSIG key proves that the slave is who it says it is, and that the zone data was not altered on the way.</p>
<table>
	<thead>
			<tr>
					<th>Server</th>
					<th>IP</th>
					<th>Role</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Master</td>
					<td><code>192.168.1.2</code></td>
					<td>Holds the zone file, allows transfers signed with <code>transfer-key</code></td>
			</tr>
			<tr>
					<td>Slave</td>
					<td><code>192.168.1.3</code></td>
					<td>Transfers the zone, signing its requests with <code>transfer-key</code></td>
			</tr>
	</tbody>
</table>
<h3 id="generating-a-transfer-key">Generating a Transfer Key <a class="anchor" data-pagefind-ignore href="#generating-a-transfer-key" aria-label="Link to this section">#</a></h3>
<p><code>tsig-keygen</code> prints a ready-to-include <code>key</code> block. Generate it once and copy the same block to both servers.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">tsig-keygen -a hmac-sha256 transfer-key
</span></span></code></pre></div><p>Output:</p>
<pre tabindex="0"><code>key &#34;transfer-key&#34; {
    algorithm hmac-sha256;
    secret &#34;generated-secret&#34;;
};
</code></pre><h3 id="master-server-configuration">Master Server Configuration <a class="anchor" data-pagefind-ignore href="#master-server-configuration" aria-label="Link to this section">#</a></h3>
<ul>
<li><code>server 192.168.1.3 { keys ... }</code>: sign everything sent to the slave, such as NOTIFY messages, with the key.</li>
<li><code>allow-transfer { key &quot;transfer-key&quot;; }</code>: only requests signed with this key may transfer the zone.</li>
<li><code>also-notify</code>: tell the slave about changes straight away.</li>
</ul>
<pre tabindex="0"><code>key &#34;transfer-key&#34; {
    algorithm hmac-sha256;
    secret &#34;generated-secret&#34;;
};

server 192.168.1.3 {
    keys { &#34;transfer-key&#34;; };
};

zone &#34;example.com&#34; {
    type primary;
    file &#34;/var/named/zones/example.com.zone&#34;;
    allow-transfer { key &#34;transfer-key&#34;; };
    also-notify { 192.168.1.3; };
};
</code></pre><p>The zone and key paths in this section and in <a href="#avoid-storing-keys-in-main-config">Avoid Storing Keys in Main Config</a> are the RHEL ones. On Debian/Ubuntu, AppArmor only lets <code>named</code> read <code>/etc/bind</code> and write <code>/var/lib/bind</code> and <code>/var/cache/bind</code>, so use <code>/var/lib/bind/zones/</code> instead of <code>/var/named/zones/</code> and <code>/etc/bind/keys/</code> instead of <code>/etc/named/keys/</code> (or add a local AppArmor override in <code>/etc/apparmor.d/local/usr.sbin.named</code>).</p>
<h3 id="slave-server-configuration">Slave Server Configuration <a class="anchor" data-pagefind-ignore href="#slave-server-configuration" aria-label="Link to this section">#</a></h3>
<p>The mirror image: the <code>server</code> block makes the slave sign its transfer requests to the master with the same key.</p>
<pre tabindex="0"><code>key &#34;transfer-key&#34; {
    algorithm hmac-sha256;
    secret &#34;generated-secret&#34;;
};

server 192.168.1.2 {
    keys { &#34;transfer-key&#34;; };
};

zone &#34;example.com&#34; {
    type secondary;
    file &#34;/var/named/zones/example.com.zone&#34;;
    primaries { 192.168.1.2; };
};
</code></pre><h2 id="essential-rndc-commands">Essential RNDC Commands <a class="anchor" data-pagefind-ignore href="#essential-rndc-commands" aria-label="Link to this section">#</a></h2>
<p>The commands you will use most, grouped by job.</p>
<h3 id="zone-management">Zone Management <a class="anchor" data-pagefind-ignore href="#zone-management" aria-label="Link to this section">#</a></h3>
<ul>
<li><code>reload</code>: re-read zone files on the master after an edit.</li>
<li><code>refresh</code> / <code>retransfer</code>: on a slave; check the serial now, or force a full transfer regardless of the serial.</li>
<li><code>freeze</code> / <code>thaw</code>: pause dynamic updates so you can edit a dynamic zone&rsquo;s file by hand.</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># Reload all zones</span>
</span></span><span class="line"><span class="cl">rndc reload
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Reload specific zone</span>
</span></span><span class="line"><span class="cl">rndc reload example.com
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Reload zone in specific view</span>
</span></span><span class="line"><span class="cl">rndc reload example.com IN internal
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Force zone refresh (secondary)</span>
</span></span><span class="line"><span class="cl">rndc refresh example.com
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Re-transfer zone (secondary)</span>
</span></span><span class="line"><span class="cl">rndc retransfer example.com
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Sign zone with DNSSEC keys (zones with a dnssec-policy only)</span>
</span></span><span class="line"><span class="cl">rndc sign example.com
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Freeze zone for manual editing (dynamic zones only)</span>
</span></span><span class="line"><span class="cl">rndc freeze example.com
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Thaw zone after editing</span>
</span></span><span class="line"><span class="cl">rndc thaw example.com
</span></span></code></pre></div><h3 id="cache-management">Cache Management <a class="anchor" data-pagefind-ignore href="#cache-management" aria-label="Link to this section">#</a></h3>
<p>On a resolver, flush a name after a record changed upstream and clients keep getting the old answer. <code>flushtree</code> also removes everything below the name.</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"># Flush entire cache</span>
</span></span><span class="line"><span class="cl">rndc flush
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Flush specific name from cache</span>
</span></span><span class="line"><span class="cl">rndc flushname example.com
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Flush entire domain tree</span>
</span></span><span class="line"><span class="cl">rndc flushtree example.com
</span></span></code></pre></div><h3 id="server-control">Server Control <a class="anchor" data-pagefind-ignore href="#server-control" aria-label="Link to this section">#</a></h3>
<p><code>reconfig</code> only picks up configuration changes and new zones; use it when you have not edited existing zone files. <code>stop</code> saves pending changes first, <code>halt</code> does not.</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"># Reload configuration (not zones)</span>
</span></span><span class="line"><span class="cl">rndc reconfig
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Check server status</span>
</span></span><span class="line"><span class="cl">rndc status
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Stop the server</span>
</span></span><span class="line"><span class="cl">rndc stop
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Halt immediately</span>
</span></span><span class="line"><span class="cl">rndc halt
</span></span></code></pre></div><h3 id="logging-and-debugging">Logging and Debugging <a class="anchor" data-pagefind-ignore href="#logging-and-debugging" aria-label="Link to this section">#</a></h3>
<p><code>dumpdb</code> and <code>stats</code> write to files in the server&rsquo;s working directory. <code>trace</code> raises the debug level by one per call.</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"># Dump cache to file</span>
</span></span><span class="line"><span class="cl">rndc dumpdb -cache
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Dump zones to file</span>
</span></span><span class="line"><span class="cl">rndc dumpdb -zones
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Write server statistics</span>
</span></span><span class="line"><span class="cl">rndc stats
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Increment debug level</span>
</span></span><span class="line"><span class="cl">rndc trace
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Disable debugging</span>
</span></span><span class="line"><span class="cl">rndc notrace
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Toggle query logging</span>
</span></span><span class="line"><span class="cl">rndc querylog
</span></span></code></pre></div><h2 id="security-best-practices">Security Best Practices <a class="anchor" data-pagefind-ignore href="#security-best-practices" aria-label="Link to this section">#</a></h2>
<h3 id="key-file-permissions">Key File Permissions <a class="anchor" data-pagefind-ignore href="#key-file-permissions" aria-label="Link to this section">#</a></h3>
<p>The key files hold the secrets: readable by root and the BIND group only.</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"># Restrict key file access</span>
</span></span><span class="line"><span class="cl">chmod <span class="m">640</span> /etc/rndc.key
</span></span><span class="line"><span class="cl">chown root:named /etc/rndc.key
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">chmod <span class="m">640</span> /etc/rndc.conf
</span></span><span class="line"><span class="cl">chown root:named /etc/rndc.conf
</span></span></code></pre></div><p>On Debian/Ubuntu the files are <code>/etc/bind/rndc.key</code> and <code>/etc/bind/rndc.conf</code>, and the group is <code>bind</code> (there is no <code>named</code> group).</p>
<h3 id="separate-keys-per-purpose">Separate Keys per Purpose <a class="anchor" data-pagefind-ignore href="#separate-keys-per-purpose" aria-label="Link to this section">#</a></h3>
<p>A leaked transfer key should not let anyone stop your server. Use different keys for different functions:</p>
<pre tabindex="0"><code># Administrative key - full access
key &#34;admin-key&#34; {
    algorithm hmac-sha512;
    secret &#34;admin-secret&#34;;
};

# Transfer key - zone transfers only
key &#34;xfr-key&#34; {
    algorithm hmac-sha256;
    secret &#34;transfer-secret&#34;;
};

# Update key - dynamic updates only
key &#34;update-key&#34; {
    algorithm hmac-sha256;
    secret &#34;update-secret&#34;;
};
</code></pre><h3 id="firewall-rules">Firewall Rules <a class="anchor" data-pagefind-ignore href="#firewall-rules" aria-label="Link to this section">#</a></h3>
<p>Restrict the RNDC port to the admin network, as a second layer behind <code>allow</code>:</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"># Allow RNDC only from admin network</span>
</span></span><span class="line"><span class="cl">iptables -A INPUT -p tcp --dport <span class="m">953</span> -s 192.168.1.0/24 -j ACCEPT
</span></span><span class="line"><span class="cl">iptables -A INPUT -p tcp --dport <span class="m">953</span> -j DROP
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Or with firewalld</span>
</span></span><span class="line"><span class="cl">firewall-cmd --permanent --add-rich-rule<span class="o">=</span><span class="s1">&#39;rule family=ipv4 source address=192.168.1.0/24 port port=953 protocol=tcp accept&#39;</span>
</span></span></code></pre></div><h3 id="avoid-storing-keys-in-main-config">Avoid Storing Keys in Main Config <a class="anchor" data-pagefind-ignore href="#avoid-storing-keys-in-main-config" aria-label="Link to this section">#</a></h3>
<p>Keep secrets in separate files and include them, so you can share <code>named.conf</code> without leaking keys:</p>
<pre tabindex="0"><code>include &#34;/etc/named/keys/rndc.key&#34;;
include &#34;/etc/named/keys/transfer.key&#34;;
</code></pre><p>This keeps sensitive data separate and simplifies key rotation.</p>
<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><code>connection refused</code></td>
					<td><code>named</code> not running, or no <code>controls</code> channel on that address/port</td>
			</tr>
			<tr>
					<td><code>connection to remote host closed</code></td>
					<td>Wrong key, wrong source IP, or <code>named</code> cannot read <code>rndc.key</code></td>
			</tr>
			<tr>
					<td><code>decode base64 secret</code></td>
					<td>Secret in <code>rndc.conf</code> is not valid base64</td>
			</tr>
			<tr>
					<td>Permission errors</td>
					<td>File ownership, SELinux or AppArmor</td>
			</tr>
	</tbody>
</table>
<h3 id="connection-refused">Connection Refused <a class="anchor" data-pagefind-ignore href="#connection-refused" 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">rndc status
</span></span><span class="line"><span class="cl"><span class="c1"># rndc: connect failed: 127.0.0.1#953: connection refused</span>
</span></span></code></pre></div><p>Check that <code>named</code> is running and the controls statement is configured:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">systemctl status named
</span></span><span class="line"><span class="cl">named-checkconf /etc/named.conf
</span></span><span class="line"><span class="cl">ss -tlnp <span class="p">|</span> grep <span class="m">953</span>
</span></span></code></pre></div><h3 id="authentication-failure">Authentication Failure <a class="anchor" data-pagefind-ignore href="#authentication-failure" 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">rndc status
</span></span><span class="line"><span class="cl"><span class="c1"># rndc: connection to remote host closed.</span>
</span></span><span class="line"><span class="cl"><span class="c1"># * This may indicate that the</span>
</span></span><span class="line"><span class="cl"><span class="c1"># * remote server is using an older</span>
</span></span><span class="line"><span class="cl"><span class="c1"># * version of the command protocol,</span>
</span></span><span class="line"><span class="cl"><span class="c1"># * this host is not authorized to connect,</span>
</span></span><span class="line"><span class="cl"><span class="c1"># * the clocks are not synchronized,</span>
</span></span><span class="line"><span class="cl"><span class="c1"># * the key signing algorithm is incorrect</span>
</span></span><span class="line"><span class="cl"><span class="c1"># * or the key is invalid.</span>
</span></span></code></pre></div><p>On the server, <code>named</code> logs <code>invalid command from 127.0.0.1#...: bad auth</code>. A secret that is not valid base64 fails earlier, on the client: <code>rndc: decode base64 secret: bad base64 encoding</code>.</p>
<p>Verify keys match between <code>rndc.conf</code> and the key <code>named</code> uses (<code>named.conf</code>, or <code>rndc.key</code> when there is no <code>controls</code> statement):</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"># Compare secrets</span>
</span></span><span class="line"><span class="cl">grep secret /etc/rndc.conf
</span></span><span class="line"><span class="cl">grep -A2 <span class="s1">&#39;key &#34;rndc-key&#34;&#39;</span> /etc/named.conf
</span></span><span class="line"><span class="cl">grep secret /etc/rndc.key
</span></span></code></pre></div><h3 id="permission-denied">Permission Denied <a class="anchor" data-pagefind-ignore href="#permission-denied" aria-label="Link to this section">#</a></h3>
<p>Check file permissions and SELinux:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">ls -la /etc/rndc.key
</span></span><span class="line"><span class="cl">getenforce
</span></span><span class="line"><span class="cl">ausearch -m AVC -ts recent <span class="p">|</span> grep named
</span></span></code></pre></div><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-rndc-tsig" rel="noopener">pderuiter/blog-bind-rndc-tsig</a>. It creates a master, a slave and an admin workstation, sets up the admin and read-only monitoring control channels, the TSIG-signed zone transfer and the workstation&rsquo;s <code>rndc.conf</code>; put your keys in an ansible-vault file, then run <code>terraform apply</code> and <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>RNDC and TSIG keys make DNS administration safe to do remotely. Use HMAC-SHA256 or HMAC-SHA512, separate keys per purpose, a read-only channel for monitoring, and restrict network access to the RNDC port.</p>
<p>The next post in this series will cover zone security, including views, ACLs, and query restrictions to protect your DNS infrastructure from abuse.</p>
]]></content:encoded></item></channel></rss>