A fresh Ubuntu box destined to serve authoritative DNS or act as a recursive resolver. This article is the install procedure we follow in production: get bind9 on, decide between authoritative and recursive (or both, carefully), wire up the ACLs, confirm the listener, and leave the daemon in a documented state. The goal is not “named is running” — it is “named is running, observable, and answering the queries we intend and refusing the ones we don’t.”
How to verify
Before touching the package manager, check what is already on port 53. UFW may be in the way, systemd-resolved may be holding the stub listener, and the host may already have a DNS daemon installed by a base image.
ss -lunp | grep ':53\b'
ss -ltnp | grep ':53\b'
systemctl status systemd-resolved
resolvectl status | head -20
dpkg -l | grep -E 'bind9|unbound|dnsmasq|knot|nsd'
If systemd-resolved is binding 127.0.0.53:53 that is fine — it is on the loopback stub address. If it is also publishing on the host’s main IP (rare, but happens with DNSStubListenerExtra set), disable that before continuing.
What’s happening
BIND9 ships on Ubuntu as the bind9 package from the main archive. Installing it pulls in bind9-utils, bind9-libs, bind9-host, and bind9-dnsutils (which gives you dig, nslookup, and delv). The post-install script creates /etc/bind/, drops the seed config (named.conf, named.conf.options, named.conf.local, named.conf.default-zones), registers the named systemd unit, and starts the service listening on 127.0.0.1:53 and ::1:53.
The directory layout matters because Debian-derived distros split the config into includes:
/etc/bind/named.conf— the entry point. Includes the other files. Do not edit it./etc/bind/named.conf.options— global options:directory,listen-on,allow-recursion,forwarders, etc./etc/bind/named.conf.local— your zones and views. This is where you put production config./etc/bind/named.conf.default-zones— the root hints,localhost, and0.0.127.in-addr.arpazones. Keep it./var/cache/bind/— working directory. Zone journals, managed zones, and the dynamic state live here.
The systemd unit runs as bind:bind. AppArmor is enabled by default for named on Ubuntu — if you store zone files outside /etc/bind/ or /var/cache/bind/, you need to update the AppArmor profile or move the files.
The procedure
-
Refresh the package index and install. Pin to the Ubuntu archive unless you have a documented reason to add an ISC PPA:
sudo apt update sudo apt install -y bind9 bind9utils bind9-dnsutils systemctl status named -
Decide the role. A single
namedinstance can be authoritative for some zones and recursive for some clients, but mixing roles on a public-facing IP is the classic open-resolver mistake. In production we run authoritative and recursive on separate instances (different hosts, or at minimum different listener IPs). -
Lock down recursion in
named.conf.options. This is the file most installs get wrong:acl "internal" { 10.0.0.0/8; 192.168.0.0/16; localhost; localnets; }; options { directory "/var/cache/bind"; listen-on { 127.0.0.1; 10.0.5.12; }; listen-on-v6 { ::1; 2001:db8::5:12; }; allow-query { any; }; // authoritative — anyone can query our zones allow-recursion { internal; }; // recursion only for our network recursion no; // flip to "yes" only if this is the resolver role dnssec-validation auto; version "DNS"; // do not leak the BIND version }; -
Define a zone (if authoritative) in
named.conf.local. Keep zone files in/etc/bind/zones/for clarity:zone "example.com" { type primary; file "/etc/bind/zones/db.example.com"; allow-transfer { key "tsig-secondary"; }; notify yes; };The
allow-transferclause is non-negotiable — without it, anyone on the internet can AXFR your zone. See TSIG keys for secure transfer for the key setup. -
Validate before reload.
named-checkconfandnamed-checkzonecatch syntax errors. Reloading a broken config leaves the previous process running but logs cryptic errors — always check first:sudo named-checkconf -z sudo named-checkzone example.com /etc/bind/zones/db.example.com sudo systemctl reload named -
Open the firewall narrowly. UFW does not have a
bind9profile — open 53 explicitly for the source ranges that need it. If the box is authoritative-only, open 53 from anywhere. If it is recursive-only, open 53 only from the internal ranges:sudo ufw allow proto udp from any to any port 53 comment 'DNS auth' sudo ufw allow proto tcp from any to any port 53 comment 'DNS AXFR/IXFR + large responses' -
Test from outside the host. A passing local
digis not enough — port 53 may be blocked at the cloud provider security group:dig @203.0.113.5 example.com SOA +norec dig @203.0.113.5 example.com NS +norec
Common pitfalls
- systemd-resolved collision. If you want
namedto listen on 127.0.0.1:53, you must disable the resolved stub listener (DNSStubListener=noin/etc/systemd/resolved.conf) and restart resolved — otherwise you get anaddress already in useerror on start. - Forgetting
dnssec-validation auto. Without it, a recursive resolver will not validate signed zones — silent failure mode. - Open recursion. A public IP with
recursion yesand noallow-recursionACL is an amplification reflector. Cloud abuse desks will notice within hours. - AppArmor and custom zone paths. Moving zone files to
/srv/dns/and getting “permission denied” in the logs even though the file is readable — that is AppArmor, not Unix permissions. Runaa-statusto confirm. - Logging defaults. The default channel only logs to syslog. For production add a dedicated
logging { channel default_log { file "/var/log/named/named.log" versions 7 size 50m; .... Theversionsandsizeclauses give you rotation without logrotate.
In the engagements we run, BIND is rarely the showy part of the stack — it is the quiet substrate the rest of the platform sits on. Get the install boring and reproducible, and the operational work shifts to the interesting questions: zone signing rollovers, hidden primaries, TSIG rotation, NOTIFY topologies. We codify the install in configuration management, run it identically across primaries and secondaries, and lift the operational burden of zone management off the client. See our managed operations service for how this fits into the broader operating model we provide.