Skip to content

Unbound as a recursive resolver — install and harden

Installing Unbound on Ubuntu for recursive DNS — ACLs, cache tuning, DNSSEC validation, DoT/DoH, and the operational checks that catch problems before they spread.

A network needs a small, fast, validating recursive resolver. Unbound fits the brief: tiny memory footprint, secure defaults, native DNSSEC validation, and trivial to operate compared to BIND-in-recursive-mode. This article is the install and harden procedure on Ubuntu — ACL, DNSSEC, DNS-over-TLS upstream, and the runtime knobs that matter. The deliverable is a resolver other infrastructure can rely on.

How to verify

Before installing, confirm what is on port 53 and whether systemd-resolved is in the way:

ss -lunp | grep ':53\b'
resolvectl status | head -20
dpkg -l | grep -E 'unbound|bind9|pdns-recursor'
which unbound-control
journalctl -u unbound -n 30 --no-pager 2>/dev/null || true

If Unbound is already installed, the journal will tell you why it is (or is not) running. If not, the steps below build a working setup.

What’s happening

Unbound is a recursive-only resolver written in C, with a focus on security and a tiny footprint. It uses a single binary (unbound), a control socket (unbound-control), and a config file (/etc/unbound/unbound.conf plus drop-ins in /etc/unbound/unbound.conf.d/). On Ubuntu the package wires it to systemd as unbound.service.

Architecturally, Unbound holds an in-memory cache (per-RR and per-message), validates DNSSEC against the root trust anchor (auto-updated via RFC 5011), and resolves queries by walking the hierarchy. It can also act as a forwarder, sending queries upstream to another resolver — useful when the box sits behind a firewall that blocks outbound port 53 to most of the internet.

Two features worth highlighting:

  • DNS-over-TLS upstream. Unbound speaks DoT to upstream resolvers (Cloudflare, Quad9). Combined with tls-cert-bundle: /etc/ssl/certs/ca-certificates.crt, it gets you an encrypted resolver path without a separate proxy.
  • Aggressive NSEC caching. Unbound caches NSEC/NSEC3 records and can answer NXDOMAIN for unsigned children from cache — useful at scale because most query traffic is for nonexistent names.

The procedure

  1. Install the package. On Ubuntu it is one apt invocation:

    sudo apt update
    sudo apt install -y unbound dns-root-data
    sudo systemctl status unbound

    dns-root-data ships /usr/share/dns/root.hints and /usr/share/dns/root.key — Unbound reads these for the root NS set and the DNSSEC root trust anchor.

  2. Disable systemd-resolved stub. Otherwise port 53 collides:

    sudo sed -i 's/^#\?DNSStubListener=.*/DNSStubListener=no/' /etc/systemd/resolved.conf
    sudo systemctl restart systemd-resolved

    Then point /etc/resolv.conf at Unbound:

    sudo rm /etc/resolv.conf
    echo "nameserver 127.0.0.1" | sudo tee /etc/resolv.conf
  3. Configure ACLs and listeners. Drop a file in /etc/unbound/unbound.conf.d/:

    # /etc/unbound/unbound.conf.d/local.conf
    server:
        verbosity: 1
        interface: 127.0.0.1
        interface: ::1
        interface: 10.0.5.10
        port: 53
        do-ip4: yes
        do-ip6: yes
        do-udp: yes
        do-tcp: yes
        access-control: 127.0.0.0/8 allow
        access-control: ::1/128 allow
        access-control: 10.0.0.0/8 allow
        access-control: 192.168.0.0/16 allow
        hide-identity: yes
        hide-version: yes
        harden-glue: yes
        harden-dnssec-stripped: yes
        use-caps-for-id: no
        prefetch: yes
        num-threads: 4
        msg-cache-size: 256m
        rrset-cache-size: 512m
        cache-min-ttl: 300
        cache-max-ttl: 86400
        auto-trust-anchor-file: "/var/lib/unbound/root.key"
        root-hints: "/usr/share/dns/root.hints"

    access-control defaults to refuse for unlisted networks — a safe posture. If you forget it, Unbound on a public IP becomes an open resolver.

  4. Wire DoT upstream (optional). If you want Unbound to forward to Cloudflare or Quad9 over DoT instead of resolving recursively from root:

    forward-zone:
        name: "."
        forward-tls-upstream: yes
        forward-addr: 1.1.1.1@853#cloudflare-dns.com
        forward-addr: 1.0.0.1@853#cloudflare-dns.com
        forward-addr: 9.9.9.9@853#dns.quad9.net
    server:
        tls-cert-bundle: /etc/ssl/certs/ca-certificates.crt

    Note: using forward-zone for the root turns Unbound into a forwarder, not a recursor. Pick one model; do not mix.

  5. Validate and reload. Unbound has a built-in checker:

    sudo unbound-checkconf
    sudo systemctl restart unbound
    sudo unbound-control status
  6. Verify resolution and DNSSEC. From the host:

    dig @127.0.0.1 cloudflare.com +short
    dig @127.0.0.1 dnssec-failed.org +dnssec     # should SERVFAIL
    dig @127.0.0.1 internetsociety.org +dnssec   # should have AD flag
    unbound-control dump_cache | head
    unbound-control stats_noreset | grep -E 'total|hits'

    The AD flag in the response header is your confirmation that DNSSEC validation worked.

  7. Set up unbound-control for runtime ops. First time only:

    sudo unbound-control-setup
    sudo systemctl restart unbound
    sudo unbound-control flush_zone internal.example.com   # operator command

Common pitfalls

  • /etc/resolv.conf flapping. NetworkManager and cloud-init rewrite /etc/resolv.conf on reboot. Use resolvconf integration or mark the file immutable (chattr +i) — or better, use systemd-resolved’s dns= setting to point at Unbound.
  • Stale root trust anchor after a long offline period. RFC 5011 rolls require the resolver to see the new key before the old one is retired. A box offline for months may miss the roll — unbound-anchor -a /var/lib/unbound/root.key re-bootstraps.
  • Aggressive caching of negative responses. A short outage at an authoritative server can cache as NXDOMAIN for cache-max-ttl seconds. Use unbound-control flush_zone <name> after upstream outages.
  • CPU pegged on a single thread. Default num-threads: 1 is the wrong choice on multi-core hosts. Set it to the number of physical cores and split the cache across threads (msg-cache-slabs, rrset-cache-slabs).
  • Forwarder with broken upstream. If you forward to 1.1.1.1 and Cloudflare has an outage, your resolver dies with it. Either keep a recursive fallback or use two unrelated DoT upstreams in the same forward-zone.

In the engagements we run, Unbound is the default recursive resolver — it fits in a tiny container, has secure defaults, and integrates cleanly with metrics. We deploy it in pairs, monitor cache hit ratio and tail latency, and treat the resolver pair as part of the platform’s blast radius. See our managed operations service for the broader operating model.