Sub topic 8
Serving Local Names from Unbound
This chapter assumes that you can edit Linux configuration files, manage services with systemd, and use dig. It also assumes that Unbound is installed and that you understand IP addresses, DNS names, and access control lists.
Unbound can answer local DNS records without contacting an upstream resolver. This is useful for names such as nas.lab.example or internal service records. Local data is configured in the server section. A matching query is answered locally, while other queries continue through normal recursive resolution or a configured forwarder.
Defining local names
The following configuration creates an internal zone and an address record:
server:
interface: 127.0.0.1
interface: 192.0.2.10
access-control: 127.0.0.0/8 allow
access-control: 192.0.2.0/24 allow
access-control: 0.0.0.0/0 refuse
local-zone: "lab.example." static
local-data: "nas.lab.example. IN A 192.0.2.20"
local-data: "printer.lab.example. IN A 192.0.2.30"A fully qualified domain name ends with a dot. The final dot prevents Unbound from treating the name as relative to another domain.
The static local-zone policy makes Unbound authoritative for the zone. It returns configured records and normally returns NXDOMAIN for names in that zone that are not configured. NXDOMAIN means that the requested name does not exist. This prevents accidental queries for unknown internal names from escaping to the Internet.
A local record does not automatically create reverse DNS. Add a PTR record when clients need to resolve an address back to a name:
server:
local-zone: "lab.example." static
local-data: "nas.lab.example. IN A 192.0.2.20"
local-data-ptr: "192.0.2.20 nas.lab.example."The address in local-data-ptr is written in normal dotted-decimal form. Unbound creates the corresponding name under 20.2.0.192.in-addr.arpa.
| Record | Purpose | Example |
|---|---|---|
| A | Name to IPv4 address | `nas.lab.example. -> 192.0.2.20` |
| PTR | IPv4 address to name | `192.0.2.20 -> nas.lab.example.` |
Forwarding selected internal domains
Use a forward-zone when another DNS server owns a domain:
forward-zone:
name: "corp.example."
forward-addr: 192.0.2.53Queries under corp.example. go to 192.0.2.53. Keep local zones and forward zones separate. A local zone answers from Unbound’s own data; a forward zone delegates resolution to another server.
Validate and reload
Check the configuration before reloading:
sudo unbound-checkconf
sudo unbound-control reload
dig @127.0.0.1 nas.lab.example. A +short
dig @127.0.0.1 -x 192.0.2.20 +short
dig @127.0.0.1 unknown.lab.example. AThe first command should print 192.0.2.20. The reverse query should print nas.lab.example.. The unknown name should return an NXDOMAIN status when the zone uses the static policy.
Exercise
Why might dig @127.0.0.1 -x 192.0.2.20 fail even though the A record for nas.lab.example. works?
Show answer
An A record provides forward resolution only. Add a matching local-data-ptr record and reload Unbound.