My DNS Notes, Ep. 1 - DNS Resolution Structure and Caching

networking13 min한국어

#dns#dns-resolver#ttl#negative-caching#networking

DNS (Domain Name System) is a distributed database that divides domain names into a tree, with servers run by different organizations each answering for their own part of the tree.

For example, before a browser can connect to shop.example.com, it needs the IP address 192.0.2.10.
The address record is on the authoritative server that stores and serves the records of example.com directly.

stub resolver In browser, OS recursive resolver Resolves for client root server com server example.com authoritative server ① shop.example.com A? ② Same query referral: com NS ③ Same query example.com NS ④ Same query A 192.0.2.10 Store in cache ⑤ A 192.0.2.10
The recursive resolver follows referrals to query the root, com, and example.com servers in turn, stores the answer in its cache, and returns it.

The steps are as follows.

  1. Through the OS stub resolver, the browser asks a recursive resolver, which performs the lookup on its behalf, for the address of shop.example.com.
  2. The recursive resolver asks a root server and receives the location of the com servers.
  3. The recursive resolver asks a com server and receives the location of the example.com authoritative servers.
  4. The recursive resolver asks the example.com authoritative server and receives the address 192.0.2.10.
  5. The recursive resolver stores the answer in its cache and returns it to the stub resolver.

Once found, an answer stays in the browser, OS, and recursive resolver caches until its TTL expires.
A repeated lookup of the same name is answered by the nearest cache without going all the way to the root servers.

1. What Is DNS?

Before DNS, host names and addresses were kept in a single HOSTS.TXT file maintained by the NIC (Network Information Center), and every host downloaded the file over FTP.
Even to change one of its own host names, an organization had to wait for the NIC to update the file.
DNS divides the namespace into a tree and lets the organization responsible for each part manage it directly.

RFC 1034 records that the total bandwidth needed to distribute a new version grew with the square of the number of hosts.

root Empty label kr org com example shop www ns1 root zone Delegates com, org, kr, etc. com zone Delegates example.com example.com zone Holds shop, www, ns1 records shop.example.com. Labels from shop to root Final dot: empty root label
A domain name is the sequence of labels from a node up to the root, and the tree is divided into zones.

The DNS namespace is a tree that starts at the root.
Each node has a label, and a domain name is the sequence of labels from a node up to the root.
com, org, and kr directly under the root are TLDs (top-level domains), and example.com is a domain one level below com.

The DNS namespace tree is structured as follows.

  • zone: The tree is divided into zones, which are distributed across many servers.
  • NS record: A parent zone holds only the names of the servers for a child zone, as NS records.
  • delegation: A parent zone hands over the management of a child zone. The root zone delegates com, and the com zone delegates example.com.
  • Independent management: Thanks to delegation, the example.com operator can change the address of shop.example.com without going through the com operator.
stub resolver In OS, browser recursive resolver Holds cache authoritative server root server root zone com server com zone ns1.example.com example.com zone RD=1 query, final answer Queries from root down
The stub resolver hands off the query, and the recursive resolver visits the authoritative servers in turn.

The process of finding records such as an IP address from a domain name is called DNS resolution, and three components take part in it.

  • stub resolver: The OS resolver that applications call. It does not walk the tree itself and hands the query to a recursive resolver
  • recursive resolver: Queries from the root down to the authoritative server in turn on behalf of the stub resolver to get the final answer, and stores the answers in its cache
  • authoritative server: A server that holds a zone’s data directly and answers without asking other servers

The format of labels and names is covered in 3.1 Domain Name, delegation in 3.2 Zone and Delegation, and caching in 3.5 TTL.

2. Usage Example

The browser on an example laptop connects to https://shop.example.com for the first time.
The browser, OS, and recursive resolver caches are all empty, and three zones are involved.

ZoneAuthoritative serverRecords needed for resolution
. (root)a.root-servers.net ~ m.root-servers.netNS and glue for com
com.a.gtld-servers.net ~ m.gtld-servers.netNS and glue for example.com
example.com.ns1.example.com, ns2.example.comshop.example.com A 192.0.2.10, TTL 300

2.1 First Lookup

stub resolver recursive resolver root server com server ns1.example.com 1. shop.example.com A 2. query 3. referral: com NS 4. query 5. referral: example.com NS 6. query 7. A 192.0.2.10 8. A 192.0.2.10
For a single query from the stub resolver, the recursive resolver visits three authoritative servers in turn.
  1. The browser checks its own host cache and, on a miss, calls the OS stub resolver (getaddrinfo())
  2. The stub resolver checks the hosts file and the OS cache, then sends a shop.example.com A query to the configured recursive resolver
    • The RD (Recursion Desired) bit in the header is 1
  3. The recursive resolver sends the query to one of the root servers listed in its root hints
  4. The root server returns a referral instead of an answer
    • authority section: 13 NS records for com
    • additional section: A and AAAA records for a.gtld-servers.net and the others (glue)
  5. The recursive resolver asks a.gtld-servers.net, and the com server returns a referral with the NS of example.com, ns1.example.com and ns2.example.com, plus glue
  6. The recursive resolver asks ns1.example.com and receives an authoritative answer
    • The AA (Authoritative Answer) bit in the header is 1
    • answer section: shop.example.com. 300 IN A 192.0.2.10
  7. The recursive resolver stores all the NS, glue, and A records it received in its cache and returns the A record to the stub resolver
  8. The browser connects to port 443 on 192.0.2.10

From start to finish, the stub resolver talks to only one recursive resolver.
For that single query from the stub resolver, the recursive resolver sent queries to three authoritative servers.

2.2 Looking Up Again

Sixty seconds later, another user of the same recursive resolver looks up shop.example.com and then api.example.com.

LookupRecursive resolver cacheQueries sent out
shop.example.com A (first)EmptyOne each to the root, com, and example.com servers
shop.example.com A (60 s later)A record, 240 s of TTL leftNone
api.example.com ANS and glue for example.comOne to ns1.example.com

The A record taken from the cache is returned with the remaining 240, not the original TTL of 300.
The A record for api.example.com is not in the cache, but the NS of example.com is, so the recursive resolver skips the root and com and asks ns1.example.com.

2.3 Looking Up a Nonexistent Name

If the user mistypes shopp.example.com, ns1.example.com returns RCODE NXDOMAIN with the SOA record of example.com in the authority section.
The recursive resolver also caches the “name does not exist” answer for a time set by the SOA, and answers the next query for the same name with NXDOMAIN without asking the authoritative server.
The rules for caching nonexistence answers are covered in 3.7 Negative Caching.

3. Core Structure

3.1 Domain Name

A label is 0 to 63 octets, and the root is the only label of length 0.
A full domain name, including the root’s length octet, is at most 255 octets in wire format.
In a message, a name is written without dots as a sequence of labels, each preceded by a length octet, and ends with the zero-length root label.

shop.example.com. 4 shop 7 example 3 com 0 4-octet label 7-octet label 3-octet label length octet root label 18 octets total = 4 length octets + 14 label octets label max 63 octets, full name max 255 octets
Each label is preceded by a length octet, and the name ends with the zero-length root label.

Label comparison is case-insensitive for ASCII, so Shop.Example.COM and shop.example.com are the same name.
RFC 1034 classifies a name ending in a dot as absolute and one without as relative, and an absolute name is commonly called an FQDN (fully qualified domain name).
Local software completes a relative name by appending a search list entry or the origin.

In a zone file, the trailing dot changes the name.
In the example.com zone file, shop gets the origin appended and becomes shop.example.com., while shop.example.com written without a dot becomes shop.example.com.example.com..

3.2 Zone and Delegation

A domain refers to everything under one node of the tree, and a zone is the part of it for which one organization’s servers hold the data.
A zone ends at a zone cut, and what lies below the zone cut is a child zone.
Delegation is adding an NS RRset for the child zone’s name to the parent zone.

com zone delegation: child zone NS example.com. NS ns1.example.com. example.com. NS ns2.example.com. glue: addresses of NS names ns1.example.com. A 192.0.2.53 ns2.example.com. A 198.51.100.53 example.com zone authoritative data example.com. SOA ns1.example.com. … example.com. NS ns1.example.com. example.com. NS ns2.example.com. ns1.example.com. A 192.0.2.53 shop.example.com. A 192.0.2.10 com server: AA=0 referral ns1.example.com: AA=1 answer
The parent zone holds only NS and glue; the records themselves originate in the child zone.

The com zone holds the NS records for example.com, but the com server is not authoritative for example.com data.
So the com server’s response is a referral with the AA bit set to 0, and ns1.example.com answers the same question with the AA bit set to 1.
Even for NS records, the authoritative copy is in the child zone.

The value of an NS record is a server name, not an IP address.
To learn the address of ns1.example.com you have to ask the example.com zone, but to reach the example.com zone you need the address of ns1.example.com.
A glue record is a server address record placed in the parent zone along with the NS records, and it is needed only when the NS name is below the zone cut.
Glue is not authoritative data of the parent zone and appears only in referrals.

RFC 1034 requires the organization responsible for a zone to provide redundant name servers and explains that the more widely the servers are distributed, the more accessible the zone is.
The example example.com also places its two servers, ns1 and ns2, on different networks (192.0.2.53, 198.51.100.53).

3.3 Root Server

The root zone is the zone whose apex is the zero-length label, and the root servers are the authoritative servers for the root zone.
The root servers are defined by 13 names, a.root-servers.net through m.root-servers.net, and operated by 12 organizations (Verisign runs A and J).
Behind the 13 names are not 13 machines but 2,046 instances (root-servers.org, as of 2026-11-24).

a.root-servers.net: 198.41.0.4 instance A 198.41.0.4 resolver Region A query instance B 198.41.0.4 resolver Region B query instance C 198.41.0.4 resolver Region C query 13 names, 12 operators, 2,046 instances (root-servers.org, 2026-11-24)
Behind each root server name are multiple instances sharing the same address.

Despite the many instances, each name has one IPv4 address and one IPv6 address.
Anycast serves the same service address from multiple independent locations, and routing delivers each packet sent to that address to one of those locations.
Each server sharing the address is called an instance.

At startup, a recursive resolver gets the names and addresses of the root servers from its root hints (priming).
Root hints are built into most resolver software, and IANA also publishes the same list.
The root zone of November 2026 (serial 2026112302) contains delegations for 1,435 TLDs, and the TTL of the NS records for com is 172800 seconds (2 days).
Once a recursive resolver receives the NS of com, it does not ask a root server again for 2 days.

3.4 Recursive Query and Referral

A query with the RD bit set to 1 in the header is a recursive query.
A server that offers recursive service contacts other servers itself when it receives a recursive query, and returns only an answer or an error.
For a non-recursive query with the RD bit set to 0, the server uses only the information it has and returns an answer, an error, or a referral to servers closer to the answer.

recursive query (RD=1): only an answer or error stub resolver recursive resolver Others answer queries non-recursive query (RD=0): an answer, error, or referral recursive resolver com server ns1.example.com referral points
A recursive query gets only an answer or an error; a non-recursive query can also get a referral.

The recursive resolver follows referrals by repeatedly sending non-recursive queries to authoritative servers.
RFC 1034 calls resolution that follows referrals iterative resolution.
A referral has the AA bit set to 0 and carries the child zone’s NS in the authority section and glue in the additional section.

Besides a referral, a response with an empty answer section can also be NODATA, described in 3.7 Negative Caching.
If the authority section has an SOA, the response is NODATA; if it has only the child zone’s NS, it is a referral.

The recursive resolver in 2.1 First Lookup traditionally sent the full shop.example.com to the root server and the com server as well.
QNAME minimisation in RFC 9156 sends only com to the root server and only example.com to the com server.
The same RFC explains that sending the full name was a convention rather than a protocol requirement, and many resolver implementations already support QNAME minimisation.

3.5 TTL

TTL (time to live) is the maximum time, in seconds, that a resource record may be cached.
Per RFC 2181 it is an unsigned value from 0 to 2147483647 (2^31 - 1), and all records in the same RRset must have the same TTL.
A TTL of 0 means the record is used only for the transaction in progress and is not cached.

Remaining TTL 300 0 0 60 300 400 Elapsed time (s) 1. miss: query, store with TTL 300 2. hit: return with TTL 240 left 3. expired, query again
The cached TTL decreases over time, and once it reaches 0 the next query goes back to the authoritative server.

The TTL in the zone is fixed; only the TTL of a cached record decreases.
RFC 1035 recommends storing the cached TTL as an absolute time and converting it to the remaining time when placing it in a response.
When the TTL reaches 0, the record expires, and the next query goes back to the authoritative server.

The zone operator sets the TTL for each record.
If shop.example.com has a TTL of 300, the old address can still be returned for up to 5 minutes after the address changes; with 86400, for up to a day.
A shorter TTL spreads changes faster but increases the number of queries the authoritative server receives.

3.6 Cache Location

The response in 2.1 First Lookup is stored in the caches of the recursive resolver, the OS, and the browser.
The next lookup checks the caches from the front and moves to the next layer only on a miss.

Browser host cache OS stub resolver OS cache, hosts file recursive resolver Shared by hosts authoritative Zone data source query: moves right only on a miss response: cached at each layer for the TTL
A query moves to the next layer only on a miss, and the response is cached at each layer it passes through.
LocationBasisScope
BrowserChromium net::HostCacheRequests within the browser
OS stub resolverRFC 1123: a stub resolver may keep a cache and, if it does, must honor expiry. Example: systemd-resolved Cache= (default yes)One host
Recursive resolverRFC 1123: a full-service resolver must keep a cache and expire its entriesAll hosts using the resolver

RFC 1123 recommends a setup in which multiple workstations share the cache of a recursive server to reduce outgoing queries.
If the old address still appears after a record change, first check which of the three cache layers still has TTL left.

3.7 Negative Caching

Negative caching is caching the answer that “the name does not exist” or “no record of the requested type exists” (RFC 2308).
A nonexistence answer has no record in the answer section to carry a TTL, so the authoritative server puts the zone’s SOA in the authority section to convey the TTL.

NXDOMAINNODATA
MeaningThe name itself does not existThe name exists but has no record of the requested type
RCODENXDOMAIN(3)NOERROR(0)
answer sectionEmptyEmpty
authority sectionZone SOAZone SOA
cache key<QNAME, QCLASS><QNAME, QTYPE, QCLASS>
Exampleshopp.example.com AAAAA for shop.example.com, which has only A
recursive resolver Holds cache ns1.example.com example.com zone shopp.example.com A NXDOMAIN, authority: SOA negative cache entry shopp.example.com. IN NXDOMAIN TTL = min(SOA TTL 3600, MINIMUM 300) = 300 s cache key: <QNAME, QCLASS> For 300 s, same-name queries skip the authoritative server
A nonexistence answer also stays in the cache for the time set by the SOA.

The TTL of a negative response is the smaller of the SOA record’s own TTL and its MINIMUM field.
If the example.com SOA has a TTL of 3600 and a MINIMUM of 300, the NXDOMAIN for shopp.example.com stays in the cache for 300 seconds.
SOA MINIMUM was originally also read as the minimum TTL and the default TTL for zone records, but RFC 2308 defined it as the TTL of negative responses.

A negative response without an SOA should not be cached (SHOULD NOT).
RFC 2308 recommends that resolvers cap the negative cache time, suggesting 1 to 3 hours as reasonable and noting that values over a day cause problems.
If a name was looked up before a record was added for it, NXDOMAIN keeps being returned for the negative TTL even after the record is added.

References