Sub topic 8
Serving local names from Unbound
This chapter assumes you have Unbound running as a caching resolver, as set up in the previous chapter. It also assumes you can read A and PTR records and know what a TTL is. By the end you will publish a few internal names from Unbound, forward one internal domain to another server, and avoid the usual surprises.
When local data is the right tool
Unbound is a resolver, not an authoritative server. It has no zone files, no SOA serial, and no zone transfers. It can still answer for names you define in its configuration, which is useful for a lab or a small office where you need nas.lab.example to resolve and nothing more.
If you need many records, a secondary server, or dynamic updates, use BIND as the authoritative server instead. Unbound local data fits roughly a few dozen hand-maintained names.
Defining a static zone
Local data goes inside the server: clause. Create a file such as /etc/unbound/unbound.conf.d/local.conf. On Debian and Ubuntu the packaged unbound.conf includes that directory.
server:
local-zone: "lab.example." static
local-data: "nas.lab.example. IN A 192.0.2.20"
local-data: "printer.lab.example. 300 IN A 192.0.2.30"
local-data-ptr: "192.0.2.20 nas.lab.example."local-zonedeclares that Unbound is responsible forlab.example.and sets how it behaves for names you did not define.local-dataadds one resource record. The TTL is optional and defaults to 3600 seconds, so the printer record above uses 300.local-data-ptris shorthand that creates the matching PTR record in the reverse zone. You write the address first, then the name.
Quote each record as one string, and end every name with a dot.
Choosing a zone type
The type decides what happens when a query falls inside the zone but matches no record.
| Type | Behaviour for names without local data |
|---|---|
| `static` | Answers NODATA or NXDOMAIN. Unbound never asks upstream. |
| `transparent` | Answers from local data if it exists, otherwise resolves normally. |
| `typetransparent` | Like `transparent`, but also resolves normally when the name exists locally with a different record type. |
| `redirect` | Answers every name in the zone with the zone apex data. |
| `refuse` | Replies REFUSED to everything in the zone. |
| `always_nxdomain` | Replies NXDOMAIN to everything in the zone. |
Use static for a private domain that exists only on your network, because a typo then fails fast instead of leaking to the public DNS. Use transparent when you only want to override a few names inside a real domain. For example, you could point www.example.com at an internal address while leaving the rest of example.com alone.
How Unbound orders its answers
Local data is checked before the cache and before any forwarding rule. The diagram shows the order.
Reverse records
local-data-ptr writes a PTR record under in-addr.arpa. Unbound ships built-in empty zones for private and documentation ranges such as 10.in-addr.arpa and 2.0.192.in-addr.arpa. These answer NXDOMAIN by default. Your own local-data-ptr entries take precedence over them. If you want to control the whole reverse zone explicitly, declare it:
server:
local-zone: "2.0.192.in-addr.arpa." static
local-data-ptr: "192.0.2.20 nas.lab.example."With static, every address in that /24 without a PTR returns NXDOMAIN. Use transparent instead if you want unlisted addresses resolved normally.
Forwarding one internal domain
Sometimes another server already owns a private domain, such as a corporate DNS server for corp.example.. A forward-zone clause sends only that domain there. It is a top-level clause, not part of server:.
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."
forward-zone:
name: "corp.example."
forward-addr: 192.0.2.53Add forward-first: yes if Unbound should fall back to normal recursion when the forward server fails. Without it, a dead forwarder means SERVFAIL for the whole domain.
A related clause, stub-zone, points Unbound at the authoritative servers for a zone. It sends iterative queries without the recursion-desired flag. Use forward-zone when the target is a resolver and stub-zone when it is an authoritative server.
Two edge cases with private answers
Many resolvers drop answers that carry private addresses, to defend against DNS rebinding. If you set private-address: 192.0.2.0/24 in server:, Unbound removes such addresses from answers it fetches from outside. Your own local-data is not affected, but forwarded private-domain answers are. Exempt the domain explicitly:
server:
private-address: 192.0.2.0/24
private-domain: "corp.example."DNSSEC is the other one. If corp.example. is an internal-only name that the public tree cannot prove insecure, validation fails and clients get SERVFAIL. Add domain-insecure: "corp.example." to the server: clause to skip validation for that name. Use it only for domains you control.
Apply and test
Check the syntax before every reload. A bad file stops a restart but is rejected harmlessly by the checker.
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 missing.lab.example AThe first two commands should print 192.0.2.20 and nas.lab.example.. The third should show status: NXDOMAIN in the header, because the zone is static. For quick experiments you can add records at runtime:
sudo unbound-control local_data "test.lab.example. 60 IN A 192.0.2.99"
sudo unbound-control local_data_remove test.lab.example.Runtime changes are lost on restart and reload, so move anything you want to keep into the configuration file.
Common errors
- A missing trailing dot, as in
nas.lab.example, gets the record rejected byunbound-checkconfor attached to the wrong name. - Records defined outside any
local-zonestill work, because Unbound creates an implicit transparent zone. Names near them then resolve normally, which can mask a typo you expected to fail. - A
staticzone placed over a real public domain hides every other name in it from your clients. - Clients receive REFUSED for local names when their network is missing from
access-control. The access check runs before local data. - A CNAME in
local-datamust be the only record at that name, as in any DNS zone.
Exercise
You add local-zone: "home.example." static and one A record for router.home.example.. A client asks for tv.home.example. and gets NXDOMAIN, even though a public home.example zone does have a tv host. How do you make tv resolve publicly while keeping the router override?
Show answer
Change the zone type from static to transparent. A static zone never asks upstream for names missing from local data, so NXDOMAIN is the expected answer. A transparent zone serves router.home.example. from local data and resolves every other name normally. Run unbound-checkconf, then unbound-control reload. Verify with dig @127.0.0.1 tv.home.example A.