Handbooks / Computer Networks / Chapter 4
DNS
7 pages · ~5 min✓ Reviewed
Builds on TCP vs UDP. Next up: HTTP and TLS.
DNS Mental Model
1. Names and Data
- DNS maps names to data (mostly IPs)
- A distributed, hierarchical database
- Read a name right to left
www.example.com.= root.→com→example→www
2. Who Asks Whom
- Stub resolveryour OS
- Recursive resolverISP, 8.8.8.8, 1.1.1.1: does the work
- Authoritativeholds the real answer for a zone
3. Tiers, Zones, Transport
| Tier | Knows |
|---|---|
| Root (13 identities a–m, many anycast instances) | the TLD servers |
| TLD (.com, .org) | the domain's NS |
| Authoritative | the records |
- A zone = namespace slice one set of authoritative servers manages
- A delegation (NS record) hands a subtree to another zone
Remember
Stub asks, recursive resolves, authoritative answers.
Resolution Workflow Step by Step
1. Cache Check, Then the Walk
- Browser cachehit: stop
- OS cache + hostshit: stop
- Resolver cachehit: stop
- Walk hierarchyfull miss only
Cold lookup: www.example.com
- 1Resolver asks rootreferral: .com TLD NS
- 2Resolver asks TLDreferral: example.com NS
- 3Resolver asks authoritativereturns the A record
2. Recursive vs Iterative
| Recursive | Iterative | |
|---|---|---|
| Path | stub → resolver | resolver → root/TLD/auth |
| Reply | final answer or error | best answer or referral: 'ask them' |
| Requests | one | many, asker follows each |
| Load | resolver works and caches | each server stays cheap |
Record Types That Matter
1. Address and alias records
- A = name → IPv4
- AAAA = name → IPv6
- Many A/AAAA at one name = round-robin
- CNAME = alias of another name
- A CNAME cannot share its name with any other record
- So no CNAME at the apex: use ALIAS/ANAME or A
2. Mail and zone records
- MX = mail server + priority; lower is tried first
- MX target = hostname, never an IP or CNAME
- NS = the zone's authoritative nameservers; the parent uses it to delegate
- SOA = zone serial + timers
bash
dig example.com MX +short
10 is tried before 20
output
10 mail1.example.com. 20 mail2.example.com.
3. Compared
TTL and Caching
1. What TTL Is
- TTL = seconds a resolver may cache a record
- Set per record by the authoritative server
- Counts down in the resolver's cache
| TTL | Range | Effect |
|---|---|---|
| Low | 60–300 s | fast changes, more queries |
| High | 3600–86400 s | fewer queries, slow changes |
2. Changing Records Safely
- 1Lower TTLone old TTL ahead
- 2Switch record
- 3Raise TTL
- 'Propagation' = old cached answers expiring
- No push: you cannot force other resolvers to refresh
dig and nslookup in Practice
1. dig Queries
| Command | Result |
|---|---|
dig example.com A +short | answer only |
dig example.com MX | also AAAA, TXT, NS |
dig @8.8.8.8 example.com | ask one resolver, compare |
dig +trace example.com | walk from the root |
dig -x 203.0.113.5 | reverse PTR lookup |
2. Reading and Tracing
+trace stops where delegation breaks
- 1Rootrefers to .com
- 2TLDrefers to NS
- 3Authoritativegives answer
- ANSWER section: the records
- TTL column: seconds left in cache
- Status: NOERROR ok, NXDOMAIN no name, SERVFAIL server failure
DNS Cheat Sheet
1. Lookup Flow
- Stubyour OS
- Resolverrecursive query
- Rootreferral
- TLDreferral
- Authoritativeanswer
- Cachedfor TTL
- Stub → resolver is recursive
- Resolver → root/TLD/authoritative is iterative referrals
2. Records & Status Codes
| Record | Meaning |
|---|---|
A | IPv4 |
AAAA | IPv6 |
CNAME | alias, not at apex |
MX | mail, lower priority wins |
NS | delegation |
TXT | SPF/DKIM/verification |
Check yourself
TTL was 86400. At 10:00 you set 300, at 10:05 you changed the IP. Why do some users see the old IP tomorrow?
- Resolvers that cached before 10:00 keep the 86400 s copy
- The new TTL applies only after they refetch
- Lower TTL one old TTL (24 h) before the change
dig @ns1 new.example.com works, but your resolver says NXDOMAIN right after you create it. Why?
- It cached the earlier NXDOMAIN
- Negative TTL comes from the SOA
- Wait it out, or flush your own cache
Spot the bug: example.com has CNAME lb.host.net. and MX 10 mail.example.com.
- A CNAME cannot coexist with other records at its name
- The apex also holds SOA and NS
- Use A records or ALIAS/ANAME instead