Sub topic 5
Authoritative name servers
This chapter assumes you know what a zone and a delegation are, and that you can read the common record types (A, AAAA, CNAME, MX, NS, SOA). It also assumes you can run dig and read its output. Here you will see how the servers that hold a zone's data work, how they stay in sync, and what usually goes wrong with them.
What "authoritative" means
An authoritative name server holds the original data for one or more zones and answers questions about them from that data. It is the end of the lookup chain. A recursive resolver asks it, and it replies from its own zone data. It does not ask anyone else.
This is different from a recursive resolver, which answers from caches and from what it learns by querying other servers. The two roles are separate, and a server should normally do only one of them.
- An authoritative server answers only for zones it is configured to serve. For any other name it returns a referral or
REFUSED. - An authoritative server does not cache answers for other zones, and it does not follow referrals on a client's behalf.
- A recursive resolver does not own any zone data. It only passes along what authoritative servers told it.
Running both roles on one open server is a known source of abuse. Open recursion lets attackers use your server in amplification attacks, which is why the roles are usually split.
Recognizing an authoritative answer
An authoritative server sets the aa (authoritative answer) flag in its replies. You can see it by querying a server directly and turning off the recursion-desired bit with +norec.
dig +norec @ns1.example.com example.com AFor the zone from the earlier chapter, the interesting lines of the output look like this:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41873
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; ANSWER SECTION:
example.com. 3600 IN A 192.0.2.10The aa flag is set, and the TTL is the full zone value (3600). A cached answer from a resolver would have aa unset and a TTL that counts down. A server can give four kinds of reply for a name in its zone or one below it.
| Situation | Status | Answer section | What else to look for |
|---|---|---|---|
| Name and type exist | `NOERROR` | The records | `aa` set |
| Name exists, type does not (NODATA) | `NOERROR` | Empty | SOA in the authority section |
| Name does not exist | `NXDOMAIN` | Empty | SOA in the authority section |
| Name is below a delegation cut | `NOERROR` | Empty, no `aa` | NS records of the child zone in the authority section |
The last row is a referral. The server is saying "I am not authoritative for that name, ask these servers." The SOA in the negative replies matters because its last field (300 in our zone) sets how long resolvers may cache the "does not exist" result.
Primary and secondary servers
The NS set for a zone should list at least two servers, on different networks if possible. Only one place holds the master copy of the data. The other servers fetch it.
- The primary (or master) loads the zone from a file or database that you edit.
- Each secondary (or replica) copies the zone from the primary and answers queries identically.
- To resolvers, all servers in the NS set are equal. They cannot tell which is primary.
Copying happens through a zone transfer. A full transfer is called AXFR, and an incremental one is IXFR. Both run over TCP. The SOA record controls the schedule, and the serial number drives everything.
The SOA fields from our zone control this behavior:
- serial (
2026112701): the version number. A secondary transfers only when the primary's serial is higher. A common convention isYYYYMMDDnn. - refresh (7200): how often the secondary polls the primary's SOA if no NOTIFY arrives.
- retry (3600): how long to wait before trying again after a failed poll.
- expire (1209600): if the secondary cannot reach the primary for this long, it stops answering for the zone and returns
SERVFAIL. Two weeks is a common value. - minimum (300): the negative caching TTL.
NOTIFY only speeds things up. If it is lost, the refresh timer still catches the change.
Many providers use a hidden primary. It is not listed in the NS set, and only the public secondaries are. That keeps the master copy off the public internet and limits the attack surface.
Delegation, glue and where the NS data lives
NS records for a zone exist in two places. The parent zone holds the delegation, which is what resolvers follow. The child zone holds its own NS set, which is what the child's servers answer with. The two should match.
If the name server's own name lies inside the zone it serves (ns1.example.com for example.com), a resolver faces a loop. It needs the address of ns1.example.com to look up example.com. To break it, the parent also stores glue, an A or AAAA record for the name server, and returns it in the additional section of the referral. You supply glue through your registrar when you register the name servers. You can see what a parent serves with:
dig +norec @a.gtld-servers.net example.com NSNames outside the zone (for example ns1.dnsprovider.net) need no glue, because the resolver can find them through a separate lookup.
Checking every server
Because each server answers independently, a good habit is to ask all of them directly and compare. This script prints the serial from each authoritative server for a domain.
domain=example.com
for ns in $(dig +short NS "$domain"); do
printf '%s ' "$ns"
dig +short SOA "$domain" @"$ns" | awk '{print $3}'
doneThe SOA data is mname rname serial refresh retry expire minimum, so the serial is the third field. If the numbers differ, the secondaries are behind, or the transfer is failing. A server that gives no output at all may be down, may be refusing queries, or may not be serving the zone.
Common errors
| Symptom | Likely cause | How to check |
|---|---|---|
| `status: REFUSED` from a name server in the NS set | Lame delegation: the server is listed but not configured for the zone | `dig +norec @server example.com SOA` has no `aa` |
| Some users get old data | Secondary serial is behind | Compare SOA serials on all servers |
| `SERVFAIL` after weeks of primary outage | Secondary passed the expire time | Check zone transfer logs |
| Name server name looks like `ns1.example.com.example.com.` | Missing trailing dot in zone file | Read the file for names without a final `.` |
| Referral works, then resolution loops | Missing glue for an in-zone name server | Query the parent for the NS set and check the additional section |
| Large answers or transfers fail | TCP port 53 blocked by a firewall | `dig +tcp @server example.com SOA` |
| Lookups for `example.com` break after adding a CNAME | CNAME at the apex | Apex already has SOA and NS, and a CNAME cannot share a name with other records |
The trailing dot error is easy to make. In a zone file, a name without a final dot is relative to $ORIGIN, so the following line is wrong:
IN NS ns1.example.comIt becomes ns1.example.com.example.com.. Write ns1.example.com. with the final dot, or just ns1.
Operational notes
- Allow zone transfers only to your own secondaries (by IP address, or with TSIG keys). An open AXFR gives anyone a complete list of your hostnames.
- Put name servers in different networks and, ideally, with different providers. Two servers on one subnet share one failure.
- Many large providers answer from the same IP address at many sites using anycast. The servers still behave as plain authoritative servers, but you cannot tell from the address which machine replied.
- Authoritative servers must accept both UDP and TCP on port 53. TCP is required for transfers, and resolvers also fall back to it for replies that are truncated.
Exercise
You change the A record for www.example.com on your primary server and reload it. Querying the primary shows the new address, but about half of your users still get the old one, and dig +norec @ns2.example.com example.com SOA shows a lower serial than the primary. Give the most likely cause and the fix.
Show answer
You did not increase the SOA serial before reloading, or the zone transfer to ns2 is failing. ns2 only copies the zone when the primary's serial is higher than its own, so it keeps answering authoritatively with old data. Increase the serial, reload the primary, and confirm that NOTIFY reaches ns2 and that TCP port 53 is open between the two servers. Then compare the serials again on every server.