Operating System BSD

How to Run NSD and Unbound on OpenBSD 8.0: Authoritative DNS and a Local Resolver

Run Unbound as a caching, validating resolver on localhost and NSD as the authoritative server for your domain on OpenBSD 8.0, both from the base system.

OpenBSD includes two DNS servers in the base system: Unbound, a validating, caching resolver, and NSD, an authoritative server for your own zones. Nothing has to be installed. At the end of this guide your server resolves names through its own Unbound instance on the loopback address and answers the world for example.com with NSD on its public address. The steps are written for OpenBSD 8.0 (released October 20, 2026), which ships NSD 4.15 and Unbound 1.26; they apply unchanged to other recent releases.

The two daemons do different jobs and both want port 53, so the layout matters: Unbound listens on 127.0.0.1 and ::1 only, NSD listens on the public address only. BIND is no longer part of the base system.

Requirements

  • A server running OpenBSD 8.0 with a static public IPv4 address. The examples use 203.0.113.10.
  • A user allowed to run commands through doas, or a root shell.
  • For the authoritative part: a domain you control, and access to your registrar so you can point the domain at your name servers.

Step 1: Start Unbound as a local resolver

The configuration shipped in /var/unbound/etc/unbound.conf is already a working, safe default: it listens on the loopback addresses, refuses queries from anywhere else, hides its identity and version, validates DNSSEC and enables unbound-control over a local socket. The relevant part looks like this:

server:
	interface: 127.0.0.1
	interface: ::1

	access-control: 0.0.0.0/0 refuse
	access-control: 127.0.0.0/8 allow
	access-control: ::0/0 refuse
	access-control: ::1 allow

	hide-identity: yes
	hide-version: yes

	auto-trust-anchor-file: "/var/unbound/db/root.key"

remote-control:
	control-enable: yes
	control-interface: /var/run/unbound.sock

Enable and start the daemon. On first start the rc script fetches the DNSSEC root trust anchor if it is missing and checks the configuration before launching:

doas rcctl enable unbound
doas rcctl start unbound

Query it directly. dig is part of the base system:

dig @127.0.0.1 openbsd.org

Look at the footer of the answer. The first query goes out to the authoritative servers; run the same command again and the query time drops to about zero because the answer now comes from the cache:

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)

The ad flag in the header of a signed domain's answer shows that DNSSEC validation succeeded.

Step 2: Make the system use Unbound

On current OpenBSD, /etc/resolv.conf is managed by resolvd. It writes name servers learned from DHCP (through dhcpleased) and other sources first, then re-appends the lines you added by hand. How you switch to the local resolver depends on how the interface is configured.

Static address

Edit /etc/resolv.conf so that the only name server is the local one:

nameserver 127.0.0.1
lookup file bind

Address from DHCP

Tell dhcpleased to ignore the name servers offered in the lease, otherwise they are placed ahead of yours. Create /etc/dhcpleased.conf with the name of your interface (vio0 on most virtual servers; check with ifconfig):

interface vio0 {
	ignore dns
}

Restart the daemon, then add nameserver 127.0.0.1 to /etc/resolv.conf and remove any remaining provider entries:

doas rcctl restart dhcpleased

Check the result with a query that does not name a server. The SERVER line must show 127.0.0.1:

dig example.org | grep SERVER

Step 3: Configure NSD

NSD reads /var/nsd/etc/nsd.conf and looks for zone files under /var/nsd/zones. Without an ip-address line it binds to the wildcard address, which collides with Unbound on the loopback interface, so bind it explicitly. Replace the file with:

server:
	hide-version: yes
	hide-identity: yes
	verbosity: 1
	ip-address: 203.0.113.10

remote-control:
	control-enable: yes
	control-interface: /var/run/nsd.sock

zone:
	name: "example.com"
	zonefile: "master/example.com.zone"

Add a second ip-address line with the server's IPv6 address if it has one. Relative zonefile paths are resolved from /var/nsd/zones.

Step 4: Write the zone file

Make sure the directory exists and create /var/nsd/zones/master/example.com.zone:

doas mkdir -p /var/nsd/zones/master
$ORIGIN example.com.
$TTL 86400

@	IN	SOA	ns1.example.com. hostmaster.example.com. (
			2026111501	; serial (YYYYMMDDnn)
			3600		; refresh
			900		; retry
			1209600		; expire
			3600 )		; negative caching TTL

	IN	NS	ns1.example.com.
	IN	NS	ns2.example.com.
	IN	MX	10 mail.example.com.
	IN	A	203.0.113.10

ns1	IN	A	203.0.113.10
ns2	IN	A	198.51.100.10
mail	IN	A	203.0.113.10
www	IN	A	203.0.113.10

The syntax is the standard zone file format that BIND also uses. Every fully qualified name ends with a dot; names without one are relative to $ORIGIN. The hostmaster.example.com. field is the contact address hostmaster@example.com with the @ written as a dot.

Step 5: Check, enable and start NSD

Validate the configuration and the zone before starting. Both tools print nothing alarming and exit with status 0 when the input is correct:

doas nsd-checkconf /var/nsd/etc/nsd.conf
doas nsd-checkzone example.com /var/nsd/zones/master/example.com.zone
doas rcctl enable nsd
doas rcctl start nsd

Ask the server for the zone's SOA record without recursion:

dig @203.0.113.10 example.com SOA +norecurse

A correct answer carries the aa (authoritative answer) flag in the header and your SOA record in the answer section. A query for a name outside your zones, such as dig @203.0.113.10 openbsd.org, is answered with REFUSED: NSD never resolves on behalf of clients.

OpenBSD's default pf.conf lets this traffic in. If you run your own ruleset, allow DNS on both protocols, because large answers and zone transfers use TCP:

pass in on egress proto { tcp udp } to port 53

Step 6: Change records later

After every edit, increase the serial number in the SOA record, check the file and reload the zone:

doas nsd-checkzone example.com /var/nsd/zones/master/example.com.zone
doas nsd-control reload example.com
doas nsd-control zonestatus example.com

When you add or remove zone: blocks in nsd.conf, run doas rcctl reload nsd, which re-reads the configuration and then the zones. Changing ip-address needs a full doas rcctl restart nsd.

Step 7: Add a secondary server

A domain needs at least two name servers, ideally on different networks. On the primary, create a shared TSIG key and allow the secondary (here 198.51.100.10) to be notified and to transfer the zone. Generate the secret with openssl rand -base64 32:

key:
	name: "tsig1.example.com."
	algorithm: hmac-sha256
	secret: "PASTE-THE-BASE64-SECRET-HERE"

zone:
	name: "example.com"
	zonefile: "master/example.com.zone"
	notify: 198.51.100.10 tsig1.example.com.
	provide-xfr: 198.51.100.10 tsig1.example.com.

On the second OpenBSD server, use the same server:, remote-control: and key: sections (with its own ip-address) and declare the zone as a secondary:

zone:
	name: "example.com"
	zonefile: "slave/example.com.zone"
	allow-notify: 203.0.113.10 tsig1.example.com.
	request-xfr: 203.0.113.10 tsig1.example.com.

Because the file now contains a secret, keep it readable only by root and the _nsd group. Start NSD on the secondary and confirm the transfer with doas nsd-control zonestatus example.com.

Step 8: Delegate the domain

Your servers only receive queries once the parent zone points to them. At your registrar, register ns1.example.com and ns2.example.com as name servers (glue records) with their IP addresses and set them as the name servers for the domain. When the change has propagated, this shows the full delegation path ending at your server:

dig +trace example.com

The manual pages nsd.conf(5) and unbound.conf(5) document every option used here.

Frequently asked questions

Can other machines use my Unbound instance as their resolver?

Not with the default configuration, and that is intentional: an open resolver on a public address is abused for amplification attacks. To serve a private network, add an interface: line for the internal address and an access-control: line that allows only that network, then run doas rcctl restart unbound.

Should I use unwind instead of Unbound?

unwind is OpenBSD's resolver for laptops and single hosts that move between networks; resolvd detects it and points resolv.conf at it automatically. For a server with a fixed address, or when other hosts must query the resolver, Unbound is the usual choice. Do not run both on the same loopback address.

Why does the server itself not see changes to my zone immediately?

The local Unbound resolves example.com through the public DNS tree like any other client and caches the answers for their TTL. Clear a cached name with doas unbound-control flush_zone example.com, or query NSD directly with dig @203.0.113.10 while testing.

Does NSD sign zones with DNSSEC?

NSD serves signed zones but does not sign them itself. Sign the zone file with a separate tool, point zonefile at the signed file and publish the DS record through your registrar.

Share story:

Continue reading other guides on How VPS.