Sub topic 7
Configuring Unbound as a Caching Resolver
Assume you can install packages, edit files, manage systemd services, and read IP addresses and firewall rules. This chapter assumes Unbound is installed and that no other service should listen on the server's DNS port, UDP and TCP port 53.
Unbound is a recursive resolver. It follows referrals from the root servers, caches answers for their TTL, and validates DNSSEC signatures when configured with a trust anchor. It does not normally host your authoritative zones.
Create a restricted resolver
Replace 192.0.2.10 and 192.0.2.0/24 with the resolver's real LAN address and client network. The documentation network shown here is safe for examples but is not routable on the public Internet.
server:
interface: 127.0.0.1
interface: 192.0.2.10
access-control: 127.0.0.0/8 allow
access-control: 192.0.2.0/24 allow
access-control: 0.0.0.0/0 refuse
do-ip4: yes
do-ip6: yes
hide-identity: yes
hide-version: yes
qname-minimisation: yes
prefetch: yes
auto-trust-anchor-file: "/var/lib/unbound/root.key"The interface settings determine where Unbound listens. The access-control settings determine which clients may send queries. The final rule prevents accidental open recursion. Open recursion lets arbitrary Internet hosts use your server and can contribute to DNS abuse.
| Setting | Purpose |
|---|---|
| `qname-minimisation` | Sends only the necessary part of a name to each delegation server |
| `prefetch` | Refreshes frequently used records near expiration |
| `auto-trust-anchor-file` | Provides the DNSSEC root trust anchor |
| `hide-version` | Removes the version from some diagnostic responses |
Some distributions create the root key during package installation. Verify that the configured file exists and that the service account can read it. If your distribution uses another path, follow its package documentation.
Validate and test
Check the configuration before restarting the service:
sudo unbound-checkconf
sudo systemctl restart unbound
sudo systemctl status unbound --no-pager
dig @127.0.0.1 example.org A
dig @127.0.0.1 example.org A +dnssecA successful DNSSEC validation normally places ad in the response flags. The ad flag means the resolver authenticated the answer. Its absence can mean that the name is unsigned, validation is disabled, or validation failed. A SERVFAIL response often indicates DNSSEC failure, unreachable upstream servers, or a broken trust-anchor setup.
Use ss to confirm that Unbound listens only on intended addresses:
sudo ss -lntup | grep ':53 'After changing configuration, inspect the service journal:
sudo journalctl -u unbound -b --no-pagerExercise
Why is access-control: 0.0.0.0/0 refuse important when more specific networks already have allow rules?
Show answer
It makes the default policy explicit, so clients outside the listed networks cannot use the resolver for recursive queries.