22.2. Running a Recursive DNS Resolver

The resolver is the service every client touches first, so the chapter builds it before the zones it will eventually serve.

Unbound is not the only candidate, and the choice is worth one table before the work starts:

Criterion Unbound BIND (recursive role) systemd-resolved dnsmasq
Intended role dedicated validating resolver general DNS toolkit: recursive, authoritative, or both per-host stub resolver with a local cache combined DNS+DHCP for small networks
DNSSEC validation built in, on by default with the root anchor built in, dnssec-validation auto validates upstream when the upstream does forwards; validation depends on upstream
Local overrides local-zone/local-data, forwarding per zone full authoritative zones inside the resolver limited per-link configuration /etc/hosts integration, small address records
Configuration one flat file named.conf and zone files link files and resolvectl one small file
Footprint and dependencies one process, no database one process, more moving parts part of systemd one process, minimal
Best fit the site's recursive tier, as here sites already running BIND operationally the client side, not the site tier branch offices where one box does everything

A validating recursive tier serving many hosts is Unbound's exact design point, and the rest of the section follows it. dnsmasq returns in small-network contexts - Chapter 21 used one for a lab subnet, and it is a fine choice when DNS and DHCP belong in one process on one small machine.

22.2.1. Installing and Configuring Unbound for a Trusted Network

On resolver, install the server and the query tools - as root:

# apt install unbound bind9-dnsutils

The unbound package ships a minimal /etc/unbound/unbound.conf plus a drop-in directory, /etc/unbound/unbound.conf.d/, whose root-auto-trust-anchor-file.conf enables the public root's trust anchor. The package's systemd unit runs a helper before start that creates and refreshes /var/lib/unbound/root.key - the RFC 5011 automated trust anchor. The chapter replaces the main file with a complete configuration, so the anchor line is written explicitly to keep that behavior. With the editor of your choice, write /etc/unbound/unbound.conf on resolver:

# /etc/unbound/unbound.conf - validating resolver for the trusted LANs
server:
    verbosity: 1
    interface: 127.0.0.1
    interface: 192.168.232.53
    access-control: 127.0.0.0/8 allow
    access-control: 192.168.232.0/24 allow
    access-control: 192.168.233.0/24 allow
    access-control: 0.0.0.0/0 refuse
    auto-trust-anchor-file: "/var/lib/unbound/root.key"
    trust-anchor: "test. DS 36795 13 2 A4E2D6923F5055EB1FED5174FB1474AC990E428E6CD68585A638CB1827B7063A"
    local-zone: "test." nodefault
    local-zone: "home.arpa." static
    local-data: "nas.home.arpa. 300 IN A 192.168.232.50"
    local-data-ptr: "192.168.232.50 nas.home.arpa."
    harden-dnssec-stripped: yes
    qname-minimisation: yes
    hide-identity: yes
    hide-version: yes
    do-not-query-localhost: no
remote-control:
    control-enable: yes
    control-interface: 127.0.0.1
    control-use-cert: no
forward-zone:
    name: "test."
    forward-addr: 192.168.232.10

The lines group by intent:

  • interface: names the addresses Unbound listens on - loopback plus the LAN address. Anything not listed is not served.
  • The access-control: block is the recursion policy: the three trusted networks are allowed, and the final 0.0.0.0/0 refuse catches everything else, evaluated in order. Unbound answers only for the networks named here.
  • auto-trust-anchor-file anchors validation of the public DNS at the root key.
  • The trust-anchor: line makes the practice network's local TLD test. verifiable. A real deployment with a registered domain does not need it - the chain from the public root through the registrar's delegation already reaches the domain - and the line exists here because test. is deliberately not under the public root. Section 22.4 generates this record from the zone's own key.
  • The local-zone/local-data pair serves names that have no zone file anywhere: home.arpa. is held as a static local zone with one member, nas, and a matching reverse entry.
  • The hardening lines strip anything unsigned from a signed zone (harden-dnssec-stripped), send only the minimum of each query name upward (qname-minimisation), and hide the server's identity and version from strangers.
  • remote-control enables unbound-control on loopback without certificate setup - passwordless because it is reachable only from the resolver's own root shell.
  • The forward-zone sends every query under test. to ns1 instead of the public root - the local TLD's home. A production equivalent forwards an internal domain to internal authoritative servers.

Validate the file before trusting it - still as root on resolver:

# unbound-checkconf
unbound-checkconf: no errors in /etc/unbound/unbound.conf

unbound-checkconf parses the whole configuration, resolves file paths, and reports the first syntax or semantic error it finds. With no errors reported, restart the service:

# systemctl restart unbound

The restart prints nothing; the unit's own start succeeded silently. Confirm the state explicitly:

# systemctl is-active unbound
active

The same configuration goes to ns2 with its listener changed: drop the interface: 127.0.0.1 line and use interface: 192.168.232.54 in place of the .53 line (install the same unbound and bind9-dnsutils packages there first). Section 22.2.4 uses that second resolver as its redundancy check; start ns2's copy before reaching it, since nothing earlier queries the address.

22.2.2. Recursion Access Controls and Listener Selection

The access list deserves a deliberate test, because its whole job is to answer some sources and refuse others. The resolver itself provides the test: give loopback a second, unknown address, and query through it - on resolver, as john:

$ sudo ip addr add 192.168.234.10/24 dev lo

The command prints nothing; the address exists on lo until removed. Now bind the query's source to the new address:

$ dig -b 192.168.234.10 @127.0.0.1 www.handbook.test A | grep -E "status:|communications"
;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 10969

dig -b sets the query's source address; the packet leaves through loopback carrying 192.168.234.10 as its origin, and Unbound evaluates exactly that address against its policy. The address is not in any allow line, so the final refuse rule matched, and the resolver answered REFUSED without doing any recursion. An open resolver would have answered - this is the configuration difference between a private resolver and the amplification source every public blacklist hunts. Remove the test address:

$ sudo ip addr del 192.168.234.10/24 dev lo

Again silent; the next query from a permitted source works again.

What Unbound actually opened follows from the interface: lines. In a root shell on resolver:

# ss -lunpt 'sport = :53'
Netid State  Recv-Q Send-Q  Local Address:Port Peer Address:PortProcess                            
udp   UNCONN 0      0      192.168.232.53:53        0.0.0.0:*    users:(("unbound",pid=12688,fd=5))
udp   UNCONN 0      0           127.0.0.1:53        0.0.0.0:*    users:(("unbound",pid=12688,fd=3))
tcp   LISTEN 0      256         127.0.0.1:53        0.0.0.0:*    users:(("unbound",pid=12688,fd=4))
tcp   LISTEN 0      256    192.168.232.53:53        0.0.0.0:*    users:(("unbound",pid=12688,fd=6))

Four sockets, two interfaces times two protocols. DNS runs over UDP for ordinary queries and falls back to TCP for large answers and zone-sized responses, so a resolver that only opened UDP would fail mysteriously on the biggest records - both rows must be present. The filter expression 'sport = :53' selects listening (and unconnected UDP) sockets whose source port is 53; Chapter 8 introduced ss and its filter syntax.

22.2.3. DNSSEC Validation, Forwarding, and Local Overrides

With validation configured, a local query shows the full machinery working. On lanclient, as john:

$ dig @192.168.232.53 www.handbook.test A +dnssec

; <<>> DiG 9.20.30-1~deb13u1-Debian <<>> @192.168.232.53 www.handbook.test A +dnssec
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55234
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags: do; udp: 1232
;; QUESTION SECTION:
;www.handbook.test.     IN  A

;; ANSWER SECTION:
www.handbook.test.  237 IN  A   192.168.232.10
www.handbook.test.  237 IN  RRSIG   A 13 3 300 20261206043016 20261122101226 14632 handbook.test. 5EQ1yF6cOSOn+8DmwVUxl+pH4zDqQtarTfmaiyS4LtmRoJRK7i5AhI3K usiUmyU0tc3H5E6FECHTShZiX/eKvQ==

;; Query time: 0 msec
;; SERVER: 192.168.232.53#53(192.168.232.53) (UDP)
;; WHEN: Sun Nov 22 11:13:59 UTC 2026
;; MSG SIZE  rcvd: 171

Read the header flags left to right: qr (a response), rd (recursion desired, echoed), ra (recursion available - this server resolves), and ad - authentic data: Unbound validated the answer's signatures all the way to its trust anchor before serving it. The do flag in the EDNS section is why the answer includes the second record: an RRSIG, the signature over the A record made with the zone's signing key. That key is tag 14632, and Section 22.4 shows where it came from. The answer's TTL of 237 is the zone's 300 second TTL counting down in the resolver's cache - this answer came from cache, not from the authoritative server, which is exactly what a resolver is for.

Public names validate through the same machinery anchored at the public root - as john on lanclient:

$ dig @192.168.232.53 isc.org A +dnssec | grep -E "status:|flags:"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 17661
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1
; EDNS: version: 0, flags: do; udp: 1232

The same ad flag, earned through the root anchor rather than the test. anchor. Both anchors are in force simultaneously; every answer is validated against whichever chain it belongs to.

The forward-zone directs only test. traffic to the local authoritative server; everything else recurses from the root. The forwarder list can carry more than one address - adding ns2's 192.168.232.11 would make the local-zone path survive a primary failure, and the chapter's single-address form is a lab economy, not a recommendation. The same forward-zone mechanism is how a site steers all traffic through an upstream resolver: a forward-zone for . with the upstream's address makes Unbound a forwarding cache instead of a full resolver.

Local overrides need no forwarder at all. The home.arpa. entries in the server block are served from the resolver's own memory:

$ dig @192.168.232.53 nas.home.arpa A +short
192.168.232.50

The static local zone answers from configuration, not from any server - useful for a handful of infrastructure names in a network that has no authoritative server at all, with the same caution as /etc/hosts: a name that exists only in resolver memory is invisible to every other resolver. The moment a name needs to be served redundantly or delegated, it belongs in a real zone.

22.2.4. Testing Answers, Validation, and Resolver Reachability

A resolver's health has exactly three visible outcomes, and each means something specific:

  • NOERROR with ra and ad - resolving and validating normally.
  • REFUSED - the query's source was rejected by policy; the server is fine, the client's network is not on the list.
  • SERVFAIL - the resolver could not produce a validated answer: either the chain of trust failed, or no upstream could be reached at all. Section 22.4.3 deliberately produces a SERVFAIL and reads it.

unbound-control exercises the running daemon through the remote-control channel. Its useful subcommands:

Subcommand Description
unbound-control flush name drop one name's cached records
unbound-control flush_zone zone drop every cached record under a zone, including its validation state
unbound-control status show version, uptime, and configuration summary

Both flush forms print a one-line confirmation of what was removed. They matter because a resolver's cache is also where stale answers live: Section 22.8.3 uses flush after an authoritative change to show the difference between "the zone is wrong" and "the cache is old".

Redundancy is part of reachability. The second resolver is running on ns2 at 192.168.232.54; from lanclient, verify it independently - as john:

$ dig @192.168.232.54 www.handbook.test A +dnssec | grep -E "status:|flags:"
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41819
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
; EDNS: version: 0, flags: do; udp: 1232

The same validated answer from the second resolver. Now fail the first one - on resolver, in a root shell:

# systemctl stop unbound

Nothing prints; the service stops. A client pointed only at 192.168.232.53 would now be without DNS - but every client of this network holds both addresses, and the second answers immediately:

$ dig @192.168.232.54 www.handbook.test A +short
192.168.232.10

Bring the resolver back:

# systemctl start unbound

Silent again, and the next query to .53 succeeds. This is the whole redundancy argument in three commands: publish two resolvers, fail either one, verify the other answers, restore. The failure drill in Section 22.6.4 rehearses the same pattern for DHCP.