Sub topic 4
Name servers and zones
This chapter assumes you know the DNS hierarchy of root, TLD, and authoritative servers. You should also be comfortable running commands in a terminal. Here you will learn what an authoritative name server actually holds, how DNS divides the namespace into zones, and how a zone's data is kept in sync across servers.
Name servers and what they do
A name server is a program that answers DNS queries. Two roles matter, and people often mix them up.
- An authoritative name server holds the official records for one or more zones. It answers from its own data and does not ask anyone else.
- A recursive resolver looks up answers on behalf of clients by querying other servers, and it caches what it learns.
This chapter is about the first role. The next chapter covers how recursive resolvers use authoritative servers.
An authoritative server marks its answers with the aa (authoritative answer) flag. You can see this in the flags line of dig output. A recursive resolver answering from its cache will not set aa. That makes the flag a quick way to tell whether you are reading the source of truth or a cached copy.
What a zone is
A zone is a contiguous portion of the DNS namespace that is managed as one unit, with one set of records. A zone is not the same thing as a domain. A domain is a name and everything beneath it in the tree. A zone is the part of that tree that one administrator has not handed to someone else.
Take example.com. It may contain www.example.com, mail.example.com, and dev.example.com. If you keep all of them in one zone file, the zone and the domain cover the same names. If you delegate dev.example.com to a different set of name servers, that subtree becomes its own zone. The domain example.com still includes it, but the example.com zone no longer does.
The point where one zone hands authority to another is called a zone cut. The parent zone marks a zone cut by publishing NS records for the child name. Those NS records are the delegation.
Why split a zone
Splitting a zone is useful for a few reasons.
- Different teams can manage different subtrees without sharing edit access.
- A busy subdomain can be served by separate infrastructure.
- A cloud platform can own a subdomain's records while your main zone stays under your control.
Splitting also has costs. Each extra zone is one more set of name servers to keep correct. If you do not need the separation, keep one zone.
Anatomy of a zone file
A zone file is a text file of resource records (RRs). Most name server software can read this format, although many hosted DNS services store the same data in a database and show it in a web form. This example uses addresses reserved for documentation.
$ORIGIN example.com.
$TTL 3600
@ IN SOA ns1.example.com. hostmaster.example.com. (
2025010101 ; serial
7200 ; refresh
3600 ; retry
1209600 ; expire
3600 ) ; negative-caching TTL
@ IN NS ns1.example.com.
@ IN NS ns2.example.com.
@ IN A 192.0.2.10
@ IN AAAA 2001:db8::10
www IN CNAME example.com.
@ IN MX 10 mail.example.com.
mail IN A 192.0.2.25
@ IN TXT "v=spf1 mx -all"
ns1 IN A 192.0.2.53
ns2 IN A 192.0.2.54Read the file from the top.
$ORIGIN example.com.is the name that@stands for. Any name written without a trailing dot has the origin appended.$TTL 3600is the default time to live, in seconds, for records that do not state their own.- The SOA record is required and must be the first record. It describes the zone itself.
- The NS records at
@list the servers that are authoritative for this zone. - The remaining lines are ordinary data. This chapter does not explain them in detail, because the record types chapter does.
The trailing dot
Look at ns1.example.com. in the SOA line. The final dot marks the name as fully qualified, so the server will not append $ORIGIN. If you write ns1.example.com with no dot, the server reads it as ns1.example.com.example.com.. This is one of the most common zone file mistakes. The zone loads without complaint, and the names simply point nowhere useful.
The SOA record in detail
The Start of Authority record carries the settings that control how the zone is replicated and cached. Its fields are:
| Field | Example | Meaning |
|---|---|---|
| MNAME | `ns1.example.com.` | The primary name server for the zone |
| RNAME | `hostmaster.example.com.` | The contact mailbox, with the first `.` standing in for `@` |
| serial | `2025010101` | A version number for the zone |
| refresh | `7200` | How often a secondary checks the primary for changes, in seconds |
| retry | `3600` | How long a secondary waits before retrying a failed check |
| expire | `1209600` | How long a secondary keeps serving the zone if it cannot reach the primary |
| minimum | `3600` | The negative-caching TTL, meaning how long resolvers may cache a "no such name" answer |
A common serial convention is YYYYMMDDnn, a date followed by a two-digit counter. The serial only needs to increase. Servers compare it using serial number arithmetic, and it is a 32-bit value.
You can read a zone's SOA with dig:
dig example.com SOA +shortPrimary and secondary servers
A zone should be served by at least two name servers, listed in separate NS records and ideally on separate networks. If one fails, the other still answers.
Keeping two servers in agreement uses a primary/secondary arrangement. The older terms are master and slave, which you will still see in some configuration files.
- The primary holds the editable copy of the zone.
- Each secondary holds a read-only copy that it fetches from the primary.
Both kinds of server are authoritative. A resolver cannot tell them apart and may query either one.
The process works like this:
- You edit the zone on the primary and increase the serial.
- The primary sends a NOTIFY message to its secondaries. If a NOTIFY is lost, the secondary still checks on its own every
refreshseconds. - The secondary queries the SOA and compares serials.
- If the primary's serial is higher, the secondary requests a transfer. A full transfer is called AXFR. An incremental transfer, IXFR, sends only the changes.
The key rule is that if you do not increase the serial, secondaries will not update. They will keep serving the old data and the primary will look correct. Many hosted DNS providers manage the serial for you. If you run your own servers, it is your job.
Zone transfers and access control
An AXFR hands over every record in the zone, which can reveal internal host names. Restrict transfers to your secondaries' addresses, or require authentication such as TSIG keys. A server that allows anyone to run AXFR is a common finding in security reviews.
You can test whether a server permits it, against a server you operate:
dig @ns1.example.com example.com AXFRA properly configured server replies with Transfer failed or REFUSED for an unauthorized client.
Delegation: how a parent points to a child
The NS records in a parent zone are what make the hierarchy work. When com lists ns1.example.com and ns2.example.com as the servers for example.com, that is the delegation resolvers follow.
Two copies of the NS set exist, and they should match:
- The copy in the parent zone, which you set through your registrar. This is what resolvers follow first.
- The copy inside your own zone, shown above at
@. This is what your servers say about themselves.
If they differ, behavior becomes inconsistent. Some resolvers use the parent's list and others prefer the child's list once they have seen it. Keep them identical.
Glue records
The servers named ns1.example.com and ns2.example.com sit inside the zone they serve. To find example.com, a resolver must first ask for the address of ns1.example.com, which it can only learn from example.com. That is a loop.
Glue records break it. The parent zone also stores the A and AAAA records for in-zone name servers, and sends them along with the delegation. You set glue at your registrar. Name servers outside the zone, such as ns1.dnshost.net, need no glue.
Lame delegation
A lame delegation happens when the parent lists a server that is not actually authoritative for the zone. The server may be down, may not have loaded the zone, or may answer without the aa flag. Resolvers skip it and try another, so lookups slow down or fail intermittently. To check a delegation, ask each listed server directly:
dig example.com NS +short
dig @ns1.example.com example.com SOA +norecurse
dig @ns2.example.com example.com SOA +norecurseBoth servers should answer with aa set and the same serial. A different serial means the secondary is behind.
Common errors
| Symptom | Likely cause |
|---|---|
| Names resolve to `host.example.com.example.com` | Missing trailing dot in the zone file |
| Edits on the primary never reach the secondary | The serial was not increased, or transfers are blocked |
| Some users see old data and others see new data | Secondaries disagree, or parent and child NS sets differ |
| Lookups sometimes time out | One listed name server is down or lame |
| The zone fails to load | A CNAME shares a name with other records, or the SOA is missing or not first |
The CNAME rule deserves its own note. A name that has a CNAME record cannot have any other record type at the same name. This is why a CNAME cannot sit at the zone apex: the apex must carry SOA and NS records.
Check your understanding
Exercise
You add a new A record on your primary name server, but the secondary keeps returning the old data even after the refresh interval has passed. The primary answers correctly. What is the most likely cause, and how would you confirm it?
Show answer
The SOA serial was not increased, so the secondary sees no change and skips the transfer. Confirm by running dig @ns1.example.com example.com SOA +short and dig @ns2.example.com example.com SOA +short. If the serials are equal while the data differs, increase the serial on the primary and reload the zone. If the serials differ but the secondary still has not updated, check that zone transfers from the secondary's address are allowed.
Exercise
A zone for example.com delegates dev.example.com to other name servers. Which zone holds the A record for app.dev.example.com, and what lets resolvers find it?
Show answer
The dev.example.com zone holds it. The example.com zone publishes NS records for dev.example.com, which form a zone cut. Resolvers follow those NS records to the name servers for the child zone and ask them for app.dev.example.com.