TECH / Servers & Websites 3 min read

How to Set Up the Unbound Caching DNS Server on FreeBSD and Linux

Antonio NEMCD Author
Published Feb 8, 2015 · 3 min

Starting with FreeBSD 10, the heavy classic BIND daemon was removed from the base operating system and replaced with the fast, lightweight caching DNS resolver Unbound. For most servers that do not host authoritative DNS zones, a local caching resolver is a major upgrade: configuration is simpler and local DNS lookups for mail servers, web apps, and scripts drop to sub-millisecond speed.

Unbound caching DNS server logo

Unbound is BSD-licensed, written in C, keeps its entire cache in RAM, and supports cryptographic DNSSEC validation out of the box.

Built-in local_unbound vs the Ports/pkg Unbound on FreeBSD

On FreeBSD (10 through 14), keep one important distinction in mind:

  • Base-system local_unbound ships pre-installed, stores its configuration under /var/unbound/, and is tailored for local caching on the host itself (127.0.0.1).
  • The full unbound package (installed via pkg install unbound) keeps its config in /usr/local/etc/unbound/unbound.conf and is better suited when your server acts as a DNS resolver for an entire LAN or VPN subnet.

To spin up a local caching resolver on the server itself in ten seconds, enable the built-in service:

sysrc local_unbound_enable="YES"
service local_unbound setup
service local_unbound start

Customizing /var/unbound/unbound.conf

To tune listening interfaces, allowed client subnets (access-control), and logging, edit /var/unbound/unbound.conf (or /usr/local/etc/unbound/unbound.conf for the pkg version):

server:
    # Log level: 0 – errors only, 1 – operational stats
    verbosity: 0
    port: 53

    # Interfaces to listen on (localhost + optional LAN IP)
    interface: 127.0.0.1

    # Source IP for outbound queries (if the server has multiple IPs)
    # outgoing-interface: X.X.X.X

    # Allowed client subnets (always block open recursion from the public internet!)
    access-control: 127.0.0.0/8 allow
    # access-control: 10.0.0.0/21 allow
    access-control: 0.0.0.0/0 refuse

    do-ip4: yes
    do-ip6: no
    do-udp: yes
    do-tcp: yes

    username: unbound
    logfile: "unbound.log"
    use-syslog: no
    pidfile: "/var/run/local_unbound.pid"

    # Hide server identity and version from scanners
    hide-identity: yes
    hide-version: yes
Security rule: never expose UDP/TCP port 53 to the public internet without strict access-control rules – bots will find an open recursive DNS resolver within minutes and abuse it for DNS Amplification DDoS attacks.

Restart or reload Unbound on FreeBSD with:

service local_unbound restart
service local_unbound reload

Testing With drill (Replacing Legacy nslookup)

FreeBSD’s base system replaced nslookup with drill (similar to dig):

drill @127.0.0.1 google.com

Check the Query time: line at the bottom of the output: the first lookup takes 20–50 ms, while running the exact same command a second time returns from Unbound’s memory cache in 0 msec.

Quick Unbound Setup on Linux (Ubuntu / Debian)

Unbound runs just as smoothly on Linux servers:

sudo apt update && sudo apt install -y unbound
sudo unbound-checkconf
sudo systemctl enable --now unbound
dig @127.0.0.1 google.com

On busy web servers and mail servers (especially Postfix or Exim querying DNSBLs like Spamhaus), running your own local Unbound resolver both cuts lookup latency to zero and avoids rate limits on public DNS resolvers.

Related posts:

Leave a Comment