Log inSign up

Build a private recursive resolver with Unbound

Install the unbound package, drop a small file with interface, access-control and hardening options into the include directory, and start it with sudo systemctl enable --now unbound. Unbound then walks the DNS tree itself from the root servers and checks DNSSEC signatures, so a forged answer returns SERVFAIL instead of a wrong address. Only localhost, your own IPs and VPN clients may query it.

Topic: VPN and private DNS · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

Why run your own recursive resolver?

A recursive resolver asks the authoritative servers directly instead of trusting a forwarding service, which removes a middleman that sees every name you look up. Unbound also validates DNSSEC: signed zones are checked against the root trust anchor, and tampered answers are rejected. Typical uses on a VPS are an upstream for Pi-hole, the resolver for WireGuard clients, or a fast local cache for mail and monitoring tools on the same machine.

The one rule that never changes: a resolver must not answer the whole internet. Open resolvers are scanned for constantly and used to amplify attacks. This guide allows 127.0.0.1, the tunnel network 10.8.0.0/24 and a single home address 203.0.113.50, and refuses everyone else both in Unbound and in the firewall.

How do you install Unbound on each distribution?

Unbound is in the base repositories everywhere, so a single package command covers it. On Ubuntu and Debian:

sudo apt update
sudo apt install -y unbound dnsutils
apt policy unbound

On Rocky Linux 9 and AlmaLinux 9:

sudo dnf install -y unbound bind-utils
dnf info unbound

Print the build options, which show the version and the crypto library:

unbound -V

Both families already configure a self-updating root trust anchor. Debian and Ubuntu set it in /etc/unbound/unbound.conf.d/root-auto-trust-anchor-file.conf; Rocky and Alma set auto-trust-anchor-file in the main file. Do not add a second anchor line, because duplicate anchors stop the daemon from starting.

Where does your own configuration go?

Keep the shipped file untouched and add one file of your own in the include directory, which survives package upgrades cleanly. The path differs:

  • Ubuntu and Debian: /etc/unbound/unbound.conf.d/private.conf
  • Rocky and Alma: /etc/unbound/conf.d/private.conf

Use this content, adjusting the addresses:

server:
    interface: 127.0.0.1
    interface: ::1
    interface: 198.51.100.24
    interface: 10.8.0.1
    ip-freebind: yes
    port: 53

    access-control: 0.0.0.0/0 refuse
    access-control: ::0/0 refuse
    access-control: 127.0.0.0/8 allow
    access-control: ::1/128 allow
    access-control: 10.8.0.0/24 allow
    access-control: 203.0.113.50/32 allow

    hide-identity: yes
    hide-version: yes
    harden-glue: yes
    harden-dnssec-stripped: yes
    qname-minimisation: yes
    aggressive-nsec: yes
    prefetch: yes
    cache-min-ttl: 60
    so-reuseport: yes

Listing exact addresses instead of 0.0.0.0 avoids a clash with the resolved stub on Ubuntu, and ip-freebind lets Unbound bind 10.8.0.1 even before the WireGuard interface is up.

How do you use Unbound behind Pi-hole instead?

When Pi-hole already owns port 53, run Unbound on loopback only, on a different port, and let Pi-hole forward to it. Replace the interface block above with:

server:
    interface: 127.0.0.1
    port: 5335
    access-control: 127.0.0.0/8 allow
    access-control: 0.0.0.0/0 refuse

Keep the hardening lines from the full example. Then tell Pi-hole to use it as its only upstream:

sudo pihole-FTL --config dns.upstreams '["127.0.0.1#5335"]'

In this layout Unbound never faces the network at all, and Pi-hole keeps doing the filtering and per-client statistics.

How do you validate and start the service?

Check the syntax before every restart, then enable the daemon:

sudo unbound-checkconf
sudo systemctl enable --now unbound
sudo systemctl restart unbound
sudo ss -lunp | grep unbound

The remote control tool talks to the running daemon and is handy for statistics and cache work. Debian and Ubuntu enable it over a local socket; on Rocky and Alma a helper unit creates the control keys on first start.

sudo unbound-control status
sudo unbound-control stats_noreset | grep total.num

If unbound-control complains about missing keys on a Rocky or Alma host, run sudo unbound-control-setup once and restart the service.

Which firewall rules belong with it?

Mirror the access-control list in the firewall, so a mistake in one layer is caught by the other. With ufw on Ubuntu and Debian:

sudo ufw allow from 203.0.113.50 to any port 53 proto udp
sudo ufw allow from 203.0.113.50 to any port 53 proto tcp
sudo ufw allow in on wg0 to any port 53

With firewalld on Rocky and Alma, a rich rule limits the source, and the tunnel interface goes into the trusted zone:

sudo firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=203.0.113.50/32 port port=53 protocol=udp accept"
sudo firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=203.0.113.50/32 port port=53 protocol=tcp accept"
sudo firewall-cmd --permanent --zone=trusted --add-interface=wg0
sudo firewall-cmd --reload

Never add a plain --add-service=dns to the public zone. The firewalld guide covers zones in more depth.

How can you tell DNSSEC validation is working?

Compare a correctly signed name with a deliberately broken one. A validating resolver sets the ad flag on good answers and refuses the bad ones:

dig @127.0.0.1 example.net +dnssec | grep flags
dig @127.0.0.1 dnssec-failed.org | grep status

Expect ad in the flags line of the first query and SERVFAIL in the second. Then confirm the access rules from outside. From your home address the query succeeds; from any other host Unbound returns REFUSED or the firewall lets it time out:

dig @198.51.100.24 example.net +short

Run a name twice and watch the second query time drop to almost zero, which proves the cache works. The dig guide explains the output fields.

How do you maintain and troubleshoot Unbound?

Package updates arrive with normal system upgrades, and the trust anchor updates itself. A few commands cover daily care:

sudo unbound-control flush example.net
sudo unbound-control flush_zone example.net
sudo unbound-control dump_cache | head
sudo journalctl -u unbound -n 50 --no-pager

Common problems and fixes:

  • Address already in use: another daemon holds port 53. Check with ss -lunp and either move Unbound to 5335 or stop the other listener.
  • Every signed name fails: the clock is wrong. DNSSEC signatures have validity windows, so run timedatectl and make sure time sync is active.
  • Clients get REFUSED: their source address is missing from access-control, often because traffic comes through NAT with a different address than expected.

For more verbose logs, add verbosity: 2 temporarily and restart.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-1a personal resolver fits in 1 GB1 vCPU, 1 GB RAM, 25 GB NVMe$3.60/mo$43.20 for 12 months
S1-2extra memory for a larger cache1 vCPU, 2 GB RAM, 55 GB SSD$6.00/mo$72.00 for 12 months

Questions about Unbound validating resolver

Should Unbound forward to a public resolver or recurse itself?

Full recursion is the default and the main reason to run it. Forwarding is possible with a forward-zone block, but then the upstream sees all your queries again.

Can Unbound serve DNS over TLS to my devices?

Yes, with tls-service-key, tls-service-pem and interface: 0.0.0.0@853 plus a certificate from Certbot. Keep the same access-control rules; encryption does not make an open resolver safe.

How much memory does Unbound use?

A few tens of megabytes with default cache sizes. You can raise msg-cache-size and rrset-cache-size on larger plans, but a personal resolver rarely needs it.

Does Unbound also host my own domain?

It can answer a few local names with local-data, which is useful for internal hostnames. For a public domain, run an authoritative server such as BIND 9 instead.

Why does a query from my laptop time out instead of being refused?

The firewall drops it before it reaches Unbound. That is expected for unknown sources; add your address to both the firewall and access-control if you need access.