Sub topic 3
Authoritative servers, recursive resolvers and forwarders
This chapter assumes you know how a DNS query walks from the root to an answer, and that you can read basic record types such as NS, A and SOA. You should also be comfortable with UDP and TCP on port 53 and with managing services under systemd. The chapter covers the three roles a DNS server can play, how each behaves on the wire, and the errors that come from mixing them up.
Why roles matter
"DNS server" names at least three different jobs. Software such as BIND can do several of them, but each job answers a different question and carries a different risk.
- An authoritative server answers questions about zones it holds. It is the source of truth for those names.
- A recursive resolver answers questions on behalf of clients. It finds answers by asking other servers and caches what it learns.
- A forwarder is a resolver that hands queries to another resolver instead of walking the tree itself.
Most operational mistakes come from confusing these jobs. Examples are a public authoritative server that also recurses, or a resolver that is told to forward to a server that cannot answer.
Authoritative servers
An authoritative server loads one or more zones and answers queries for names inside them. It does not need to contact any other server to answer, unless it is a secondary that refreshes from a primary.
Key properties:
- It sets the
aa(authoritative answer) flag in responses for names in its zones. - For a name outside its zones, it returns a referral or
REFUSED. It does not search for the answer. - It reads from zone data, either a zone file or data replicated from a primary.
- It is usually reachable from the whole internet if it serves a public domain.
A zone normally has at least two authoritative servers, listed in its NS records. One is the primary, which holds the editable copy. The others are secondaries, which copy the zone. Clients cannot tell them apart, and both set the aa flag.
You can see the difference with dig. Ask an authoritative server for a name it serves, with recursion switched off:
dig @192.0.2.10 www.example.com A +norecurseThe status should be NOERROR, the flags should include aa, and the answer section should hold the record. Ask the same server for a name in a zone it does not hold:
dig @192.0.2.10 www.example.org A +norecurseA correctly configured authoritative-only server returns REFUSED, or a referral toward the parent zone's servers. It does not return an answer.
Recursive resolvers
A recursive resolver takes a question from a client and returns a final answer. The client sends one query with the rd (recursion desired) flag set. The resolver does the work of following the delegation chain: root, then top-level domain, then the domain's own servers.
Key properties:
- It keeps a cache. A name looked up once is served from memory until its TTL runs out.
- It sets the
ra(recursion available) flag. - It does not set
aafor answers it took from elsewhere, except for the first response after fetching. - It should only serve clients you intend to serve.
The cache is the reason resolvers exist. A busy network repeats the same lookups constantly. Caching cuts latency for users and reduces load on upstream servers. Negative answers are cached as well. The negative caching TTL in the SOA record controls how long an NXDOMAIN result is remembered.
The diagram shows how the two roles divide the work when a client looks up a name.
Open resolvers are a hazard
A resolver that answers anyone on the internet is an open resolver. Attackers use open resolvers for reflection and amplification attacks. They send small queries with a forged source address, and the resolver sends much larger responses to the victim. A resolver also exposes its cache to probing from outside.
Restrict recursion to your own networks. In Unbound this is done with access-control. In BIND it is done with allow-recursion or allow-query-cache. The later chapters on configuration and hardening show the details.
Forwarders
A forwarder is a resolver configured to pass some or all queries to another resolver. The forwarder does not walk the tree from the root. It treats the upstream resolver as its source of answers.
Typical reasons to forward:
- A small office server sends everything to the ISP's resolver or a shared internal resolver.
- A company resolver sends queries for an internal domain, such as
corp.example, to the servers that hold it, and resolves everything else normally. - A network blocks direct outbound port 53, so only a designated resolver can reach the internet.
Forwarding has costs. Your server depends on the upstream for correctness and availability. If the upstream is slow, you are slow. If it lies or filters, you inherit that behaviour. DNSSEC validation also needs thought. If the upstream does not return DNSSEC data, your own validator cannot check the answers.
There are two common forwarding patterns:
| Pattern | What it does | Typical use |
|---|---|---|
| Global forwarding | Every query that is not answered locally goes to the upstream. | Small networks that rely on one trusted resolver. |
| Per-zone forwarding | Only queries for named domains go to a chosen upstream. Everything else is resolved by recursion. | Reaching internal zones while keeping normal resolution. |
In Unbound, a forward-zone with name: "." is global forwarding, and any other name is per-zone. The example below forwards one internal domain and leaves everything else to normal recursion:
forward-zone:
name: "corp.example."
forward-addr: 192.0.2.53BIND offers a forwarders list in options and a forward only or forward first setting. With forward first, BIND tries the forwarders and then falls back to its own recursion if they fail. With forward only, it gives up and returns SERVFAIL. Pick only when policy requires that queries never leave through another path.
Comparing the three roles
| Property | Authoritative | Recursive resolver | Forwarder |
|---|---|---|---|
| Answers for | Zones it holds | Any name, for permitted clients | Any name, for permitted clients |
| Asks other servers | Only to refresh a secondary | Yes, walking from the root | Yes, but only the configured upstream |
| Has a cache of other zones | No | Yes | Yes |
| Sets `aa` | Yes, for its zones | No, for cached or fetched data | No |
| Sets `ra` | No | Yes | Yes |
| Exposure | Usually public | Restricted to your clients | Restricted to your clients |
| Main failure risk | Stale or wrong zone data | Open recursion, cache poisoning | Dependence on the upstream |
Combining roles on one machine
A single host can run more than one role, but combining them needs care.
- A BIND instance can be authoritative for your zones and recursive for your LAN. This works on a small internal network. Use
allow-recursionto limit who may recurse, and keep that list away from the public. - A public authoritative server should have
recursion no;. An answer to a name outside your zones should not be possible. - A common clean design runs Unbound for clients and BIND for zones. Unbound then forwards queries for your own zones to BIND, which listens on another address or port.
The last design keeps each daemon small and makes the roles visible. It also lets you expose BIND to the internet while keeping Unbound internal.
Common errors
- Recursion left on for the internet. Symptom: unexpected traffic, and
dig +recursefrom outside returns answers. Fix: restrict by ACL, or turn recursion off. - A resolver that cannot reach the root. Symptom:
SERVFAILfor every name not cached. Cause: a firewall blocks outbound UDP or TCP 53. Fix: allow the traffic, or configure a forwarder. - Lame delegation. Symptom: a domain's NS records point to a server that does not serve the zone, so it is not authoritative. Fix: load the zone on that server, or correct the NS records at the parent.
- Forwarding to a server that refuses you. Symptom:
REFUSEDthrough the forwarder, while direct queries work. Cause: the upstream's ACL does not include your address. - Expecting a resolver to see new data at once. Symptom: old answers after a change. Cause: caching up to the TTL. Fix: lower the TTL before a planned change, and wait for the old TTL to pass.
- Querying the wrong role with
dig. A resolver's reply to+norecursefor an uncached name is an empty answer. This is not a fault.
Reading the flags
The flags in a dig header tell you which role answered.
| Flag | Meaning | Where you expect it |
|---|---|---|
| `qr` | This message is a response. | All responses |
| `aa` | The answer is authoritative. | Authoritative servers, for their own zones |
| `rd` | Recursion was requested by the client. | Client queries to resolvers |
| `ra` | The server offers recursion. | Resolvers and forwarders |
| `ad` | The data was validated with DNSSEC. | Validating resolvers |
If you ask a server you believe is authoritative and see ra, it is also recursing. If you ask a resolver and see aa on a cached name, something is wrong with your assumptions about what it serves.
Exercise
You run an authoritative server for example.com at 192.0.2.10. A query from the internet for www.example.org returns an answer with the ra flag set. What does this show, and what should you change?
Show answer
The server is also acting as a recursive resolver and is open to the internet, which allows reflection attacks and cache probing. Set recursion off (recursion no; in BIND) or restrict recursion to trusted networks with allow-recursion. Afterwards, query again from outside. The server should return REFUSED for names outside its zones.
Exercise
A resolver forwards all queries to 192.0.2.53 with forward only. The upstream goes down. What do clients see, and how would forward first change this?
Show answer
With forward only, the resolver does not fall back to its own recursion, so clients receive SERVFAIL for names not in the cache. With forward first, the resolver tries the forwarder and then walks the tree from the root itself, so lookups keep working as long as it can reach the internet.