17. DNS: How a Name Becomes an Address
How the laptop's 29-byte question about example.com travels from R1 to the root, .com and example.com's own servers, and how caches, compression pointers, EDNS, DNS64 and DNSSEC fit around it
Imagine you need to phone someone, and all you have is a name: Dr Okafor, at the Royal Infirmary, in Edinburgh. You ring directory enquiries. The operator doesn't have every number in the country in front of them, but they know how to find it. A national index tells them who keeps the listings for Edinburgh. Edinburgh's listings give them the infirmary's switchboard. The switchboard knows Dr Okafor's extension. The operator reads you the number, and jots it on a pad by the phone, because someone else will probably ask for Dr Okafor before the day is out.
That's the Domain Name System almost exactly. Nobody holds the whole directory. The
operator is a recursive resolver, which does the legwork. The national index is the
root, Edinburgh's listings are a top-level domain like .com, and the switchboard is
the authoritative server for one organisation's names. The pad is a cache, and every
entry on it has a "good until" time written next to it.
The UDP article followed one small datagram from the laptop to R1: a 29-byte DNS
query for example.com, from 192.168.10.10:41853 to 192.168.10.1:53, ID 9f3c. It
promised to decode that query field by field and to explain how R1 found the answer. The
NAT article noted that the answer is where 203.0.113.80 came from in the first
place. This page keeps both promises. It follows the question from R1 to a resolver at the ISP,
then to the root, to .com, and to example.com's own servers. It decodes the query and the
answer byte by byte, compression pointer and checksums included. Then it covers the record
types, caching, the move from UDP to TCP and encrypted transports, the names R1 makes up for
the house, IPv6 and DNS64, and how DNS is attacked and defended.
From One Text File to a Distributed Database
In the 1970s the ARPANET had a few hundred hosts, and every one of them knew every other by
name thanks to a single file, HOSTS.TXT. The Network Information Center at SRI in Menlo
Park, SRI-NIC, maintained it. Administrators emailed their changes to the NIC, and every
site downloaded a fresh copy every so often. The idea survives on every computer today as
/etc/hosts.
It couldn't last. As the network grew into the early 1980s, the file did too, and so did the traffic to SRI as every site fetched it. Every name had to be unique across the whole network and approved by one office. And the file was never quite right: by the time a copy arrived, some of it was already out of date.
In November 1983, Paul Mockapetris at USC's Information Sciences Institute published RFC 882 and RFC 883, describing a replacement. It had three big ideas:
- Hierarchical names. Names are paths in a tree, like
www.example.com. Uniqueness only has to hold among siblings, so whoever runsexample.comcan createwwwwithout asking anyone. - Delegated authority. Each part of the tree can be handed to a different organisation, which runs its own servers for it. No central office edits everyone's entries.
- Caching. Every answer carries a lifetime, and anyone may keep a copy until it runs out. That's what makes the system fast, and what keeps the top of the tree from melting.
RFC 1034 and RFC 1035 replaced the first pair in November 1987, and they're still the
core specification, amended by dozens of later RFCs. RFC 920 (1984) had already set out the
first top-level domains, and on 15 March 1985 symbolics.com became the first .com name
ever registered. At Berkeley, a group of graduate students wrote BIND, the Berkeley
Internet Name Domain server, which became the reference implementation and is still widely run.
The Namespace: a Tree of Labels
DNS names form one tree. Each node has a label, and a name is the list of labels from a node up to the top, written left to right with dots between them. The top of the tree is the root, whose label is empty.
Labels and names
A few rules govern what a name can look like:
- A label is at most 63 bytes, and a whole name at most 255, counted in the form it takes on the wire (we'll see why the limits are those odd numbers below).
- Comparisons ignore ASCII case.
Example.COMandexample.comare the same name. Servers should still echo the question back exactly as it was asked, which turns out to be useful for security. - Hostnames stick to letters, digits and hyphens, the "LDH" rule, but DNS itself will carry
any byte. Names in other scripts are encoded into that alphabet with
Punycode (RFC 3492), which turns
bücherintoxn--bcher-kva; browsers show the Unicode form.
A name written all the way to the root ends with a dot: example.com., where the final, empty
label is the root. That's a fully qualified domain name, or FQDN. Most of the time the dot is
left off and implied, but it matters in two places. Zone files treat a name without the dot as
relative to the zone, so ns1 means ns1.example.com.. And stub resolvers may try a name
without the dot against a search list first: the DHCP article gave the laptop
the domain home.arpa, so typing nas gets it nas.home.arpa. A trailing dot switches the
search off.
Top-level domains
The labels just below the root are the top-level domains, or TLDs. The root zone holds well over a thousand of them, in a few broad kinds:
- Generic TLDs (gTLDs), like
com,organdnet: the originals from the 1980s, plus hundreds more, likeapp, added since ICANN's 2012 application round. - Country-code TLDs (ccTLDs), like
uk,deandjp: two letters, taken from the ISO 3166-1 list of country codes. - Restricted TLDs, like
edu,govandmil, kept for particular kinds of organisation. arpa, for infrastructure: reverse lookups and protocol plumbing, likehome.arpa.
Domains, zones and delegation
A domain is a node and everything below it. A zone is the part of the tree that one set of servers actually answers for. They're not the same thing, because the owner of a domain can delegate a part of it: carve off a subtree, hand it to someone else's servers, and record in its own zone only where those servers are.
The root zone doesn't contain www.example.com. It contains a delegation for com: a set of
NS ("name server") records naming the .com servers. The com zone, run by its registry,
doesn't contain www.example.com either. It holds a delegation for example.com, naming that
domain's own servers, ns1.example.com and ns2.example.com. Only the example.com zone, on
those two servers, says what www actually is. The boundary between a parent zone and a child
zone is called a zone cut, and a referral across one is how every lookup finds its way down
the tree.
Each zone is served by several authoritative servers holding identical data, so that one can fail without taking the names with it. RFC 1034 asks for at least two, and we'll see in the security section what happens when every one of them becomes unreachable at once.
Who Does What
Four kinds of program take part in a lookup from our house. Each one is a DNS server, a DNS client, or both:
| Role, and who plays it here | What it does |
|---|---|
| Stub resolver: the laptop | Asks one server, "please recurse", and takes the answer |
| Forwarder: dnsmasq on R1 | Caches, answers local names, passes the rest upstream |
| Recursive resolver: the ISP's | Walks the tree from the root, follows referrals, caches |
Authoritative: root, .com, ns1, ns2 |
Answers only for its own zones, never asks anyone |
The stub resolver on the laptop is tiny. On Linux it's part of the C library, and it reads
/etc/resolv.conf to find out whom to ask. The DHCP article set that up: option 6
named 192.168.10.1 as the DNS server. (R1's Router Advertisements also carry an RDNSS option
naming R1, as the IPv6 article showed. On VLAN 10 that's
2001:, where the UDP article's
IPv6 version of the query went.) The plain C-library stub keeps no cache at
all; a system running systemd-resolved has a caching stub at 127.0.0.53, and browsers keep
a short cache of their own.
The forwarder on R1 is dnsmasq, the same program that hands out DHCP leases. It keeps a
cache, answers for home.arpa itself, and sends everything else to the resolver R1 was told
about when it got its WAN address: the ISP's DHCP server named 198.51.100.53 in its own
option 6. Almost every home router works like this.
The recursive resolver at the ISP is where the walking happens. Instead of the ISP's, the
laptop or R1 could use one of the big public resolvers, such as Google Public DNS, Cloudflare's
or Quad9, which work the same way. (Throughout this page, the resolver, the root, the .com
server and example.com's servers all have documentation addresses. They're stand-ins: the
real ones have other addresses.)
The authoritative servers are the ones that actually hold zones. Here are the stand-ins:
| Server | Zone | Stand-in |
|---|---|---|
a. |
root | 192. |
a. |
com |
192. |
ns1. |
example. |
203. |
ns2. |
example. |
192. |
ns1 sits with the web server at the hosting company, AS65536, from the
BGP article. ns2 is run by a different provider on a different network, for
reasons the Facebook story will make obvious. Each also has an IPv6 address:
2001:, 2001:,
2001: and 2001:.
The root servers
The root zone is served by 13 named servers, a.root-servers.net to m.root-servers.net,
run by 12 independent organisations (Verisign runs two letters). Thirteen was what fitted: in the
1980s the list of their names and IPv4 addresses had to fit in one 512-byte UDP answer.
Thirteen names doesn't mean thirteen machines. Each letter is anycast: the same address is announced over BGP from many sites around the world, and each query goes to whichever copy is nearest by BGP's reckoning. Across all 13 letters there are around 2,000 instances, in nearly every country.
How does a freshly started resolver find the root in the first place? It ships with a short
file of root hints, the names and addresses of the 13 letters. On start-up it sends one
priming query, "what are the NS records for .?", to one of them, and uses the current
answer from then on (RFC 9609, 2024, which replaced RFC 8109). The hints only need to be right
enough to reach one root server, once.
Resolving example.com, Step by Step
Here's the whole lookup the first time anyone in the house asks, with every cache empty except the resolver's priming data. Timings are illustrative: about 50 ms end to end.
-
① The laptop asks R1
The 29-byte query from the UDP article: ID
9f3c, "what is the A record forexample.com?", with the RD (recursion desired) bit set. RD means "don't send me a referral, find the answer". It leaves from port 41853 to R1's port 53. -
② R1 forwards it
dnsmasq looks in its cache and finds nothing. It sends the same question to
198.51.100.53, with RD set, but with a new random ID and from a random source port of its own, and remembers which client asked. R1 sends this from its own WAN address,198.51.100.23, so no NAT is involved. -
③ ④ The resolver asks the root
The resolver has nothing cached for
example.comorcom, so it starts at the top. It sends the question to a root server without RD: it wants to be told whom to ask, not have the root do the work. The root doesn't knowexample.com, but it knows who runscom, and says so in a referral: no answer, an authority section listing the 13comservers' names as NS records, and an additional section with their addresses. -
⑤ ⑥ The resolver asks .com
Same question, to
a.gtld-servers.netat192.0.2.60. Another referral:example.comis served byns1.example.comandns2.example.com, which are at203.0.113.10and192.0.2.70. -
⑦ ⑧ The resolver asks example.com's own server
Same question again, to
203.0.113.10. This time it's an answer:example.comA203.0.113.80, with the AA (authoritative answer) bit set, because this server is the source of the data. The record carries a TTL of 3600 seconds: anyone may cache it for an hour. -
⑨ ⑩ Back down the chain
The resolver caches everything it learnt and answers R1, setting RA (recursion available) and leaving AA clear, since it isn't the source. R1 caches the answer, puts the laptop's ID
9f3cback, and replies to192.168.10.10:41853. The laptop now knows where to send its TCP SYN.
Referrals and glue
Look at step ⑥ again. The .com server says "ask ns1.example.com". But to find
ns1.example.com, the resolver would have to ask… the servers for example.com, which is
exactly what it's trying to find. That circle is broken by glue: alongside the NS records,
the parent zone keeps copies of the servers' addresses and hands them out in the referral's
additional section. Glue is only needed when a server's name is inside the zone it serves, and
the parent zone is where it lives; it isn't authoritative data, just a pointer to help the
resolver on its way.
A careful resolver only accepts records in a referral that are in bailiwick: data about the
zone being delegated or below it. The .com server may tell it about ns1.example.com, but not
about bank.example.net. Older resolvers were looser, and the security section
shows why that mattered.
Recursive and iterative queries
There are two kinds of question in the diagram. The laptop and R1 ask recursive queries: RD set, "give me the final answer". The resolver asks iterative ones: RD clear, "give me the answer or the best referral you have". Authoritative servers never recurse, and most refuse to; that's what keeps them fast and cheap to run. A server that's willing to recurse says so by setting RA in its replies.
There's also a privacy detail here. The resolver sent the whole name, example.com, to the
root, which only needed to hear com. Modern resolvers use QNAME minimisation
(RFC 9156, 2021, after RFC 7816 in 2016): ask the root only about com, ask .com only about
example.com, and so on, so that each server learns no more of the name than it needs. The
major open-source resolvers do this by default now; this page shows the classic full-name
form because it's what dig +trace shows, too.
Every cache, after one lookup
When it's all over, here's what's been remembered, and for how long:
| Who | Record | TTL left (s) |
|---|---|---|
| R1 | example. A |
3600 |
| ISP resolver | . NS + addresses |
518400, from priming |
| ISP resolver | com NS + glue |
172800 |
| ISP resolver | example. NS + glue |
172800 |
| ISP resolver | example. A |
3600 |
| Laptop | nothing | – |
That's an hour for the address, two days for the delegations and six days for the root's own NS records. The laptop has nothing: the C library's stub doesn't cache.
Every TTL counts down from the moment the record was received. A cache never extends one: when it hands out a cached record, it gives the remaining time, so the record expires at the same moment everywhere. Watch what happens next:
Ten minutes later
-
The desktop asks for
example.com. R1 answers straight from its cache, in well under a millisecond, with TTL 3000: the 3600 it received, less 600 seconds spent in the cache. -
The laptop asks for
www.example.com. R1 has nothing for that name, so it forwards. The resolver doesn't need the root or.com: it still hasexample.com's NS records and glue, so it asks203.0.113.10directly. One round trip instead of three. -
An hour after the first lookup, the
example.comA record expires at R1 and at the resolver, a few milliseconds apart. The next query goes all the way tons1again, but only that far, until the NS records expire two days later.
That's why DNS scales. The root servers see a tiny fraction of the world's lookups: most
questions about .com names never get past a resolver's cache of the com NS records.
Each button sends one question from the laptop at the current moment. Step through the messages, then move the clock on and ask again: R1's and the resolver's caches count down underneath. The run starts cold, with only the resolver's priming data, and the first lookup is already played out. Timings are illustrative: about 50 ms for a cold lookup.
Ask from the laptop
Move the clock
The latest lookup
Caches at this moment
The laptop has no cache: the C library's stub asks R1 every time.
Settings
Cold: only the resolver's priming data. Warm: other customers of the ISP have been busy, so the resolver already holds com, example.com's delegation and its A record, with 2400 s left.
Every message so far
The Message Format
Every DNS message, query or response, over UDP, TCP or HTTPS, has the same layout: a fixed 12-byte header, then four sections.
- Question: what's being asked. Almost always exactly one.
- Answer: records that answer the question.
- Authority: records pointing at the authoritative servers (the NS records of a referral), or an SOA record explaining a negative answer.
- Additional: records that might help, like glue addresses, plus the EDNS pseudo-record.
A query is just a message with a question and three empty sections. A response normally copies the question back and fills in the rest.
The header
| Field | Bits | Meaning |
|---|---|---|
| ID | 16 | Chosen by the asker, copied into the reply, so replies can be matched to questions |
| QR | 1 | 0 = query, 1 = response |
| Opcode | 4 | 0 = standard query. (4 = NOTIFY and 5 = UPDATE are used between servers.) |
| AA | 1 | Authoritative answer: the responder is a source for this zone |
| TC | 1 | Truncated: the answer didn't fit, ask again over TCP |
| RD | 1 | Recursion desired: set by the asker, copied into the reply |
| RA | 1 | Recursion available: the responder will recurse |
| Z | 1 | Reserved, must be zero |
| AD | 1 | Authentic data: a validating resolver checked this with DNSSEC |
| CD | 1 | Checking disabled: "don't validate for me, I'll do it myself" |
| RCODE | 4 | 0 NOERROR, 1 FORMERR, 2 SERVFAIL, 3 NXDOMAIN, 4 NOTIMP, 5 REFUSED |
RFC 1035 had three reserved Z bits. DNSSEC later took two of them for AD and CD, which is why the last two flags look like an afterthought: they are.
The laptop's query, field by field
Here are the 29 bytes again, exactly as they sat after the UDP header at offset 0x1c of the
packet. Offsets below count from the start of the DNS message, because that's what compression
pointers will count from.
The query: 29 bytes
0000 9f 3c 01 00 00 01 00 00 00 00 00 00 07 65 78 61 .<...........exa
0010 6d 70 6c 65 03 63 6f 6d 00 00 01 00 01 mple.com.....
header bytes 0–11 · name bytes 12–24 · type and class bytes 25–28
-
Offset 0: ID
9f 3cA random number the laptop picked. Any 16-bit value will do; the UDP article noticed that if the laptop had picked
f727, the UDP checksum would have come out as zero and been sent asff ff. DNS wouldn't have minded. What matters is that the ID is unpredictable, for reasons we'll come to. -
Offset 2: flags
01 00In binary,
0000 0001 0000 0000. QR = 0, a query. Opcode = 0, a standard query. AA, TC = 0. RD = 1: please recurse. The whole second byte is zero, including RA, AD, CD and RCODE, which only mean something in replies (AD and CD aside, which the laptop could set to ask for DNSSEC information; it didn't). -
Offset 4: four counts
00 01 00 00 00 00 00 00One question, no answer, authority or additional records.
-
Offset 12: the name
07 65 78 61 6d 70 6c 65 03 63 6f 6d 00Not dots: length-prefixed labels.
07says seven bytes follow,example.03, thencom.00is a label of length zero: the root, which ends every name. Thirteen bytes for the eleven characters ofexample.com. -
Offset 25: type
00 01, class00 01Type 1 is A, an IPv4 address. Class 1 is IN, the Internet. (Other classes, like CH for the MIT Chaosnet, are museum pieces; one survives as a trick for asking a server its version.)
Names on the wire, and the 63-byte limit
A length byte could count up to 255, so why are labels limited to 63? Because the top two bits of that byte are taken. They say what kind of thing comes next:
| Top two bits | Meaning | Remaining bits |
|---|---|---|
00 |
A normal label | Its length, 0–63 |
11 |
A compression pointer | With the next byte: an offset, 0–16383 |
01, 10 |
Reserved for other label types | Effectively unused |
Six bits make 63 the largest possible label. The 255-byte limit on whole names was a design
choice that keeps names easy to hold in fixed buffers; it counts every length byte and the final
00, so the longest name you can type is 253 characters.
Compression pointers
A response repeats names a lot: the question, then each answer about the same name, then NS
records full of names under the same zone. RFC 1035 lets any name, or the tail end of a name,
be replaced by a two-byte pointer to an earlier copy anywhere in the same message. The
pointer is the top two bits 11, then a 14-bit offset from the start of the DNS message.
Here's R1's 45-byte reply to the laptop. It starts as a copy of the query with the flags changed, then adds a 16-byte answer record. The answer's name is just two bytes:
Reading the answer record from offset 0x1d:
| Bytes | Field | Value |
|---|---|---|
c0 0c |
NAME | Pointer to offset 12: example. |
00 01 |
TYPE | 1, A |
00 01 |
CLASS | 1, IN |
00 00 0e 10 |
TTL | 3600 seconds |
00 04 |
RDLENGTH | 4 bytes of data follow |
cb 00 71 50 |
RDATA | 203. |
Every resource record, or RR, in the answer, authority and additional sections has this shape: name, type, class, a 32-bit TTL, a 16-bit length, and that many bytes of data whose meaning depends on the type. The question section is the same minus the last three fields.
Decoders have to be careful with pointers. RFC 1035 says a pointer refers to a prior occurrence, but nothing physically stops a malicious message from containing a pointer that points at itself, or two that point at each other. A decoder that follows them blindly loops forever, so real ones only follow pointers that go backwards, or give up after a fixed number of jumps. Bugs in exactly this code have been a steady source of vulnerabilities.
The reply on the wire, checksums and all
As R1 sends it, in a 73-byte IPv4 packet from port 53 back to port 41853:
Hex dump: R1's reply, a 73-byte IPv4 packet
0000 45 00 00 49 00 00 40 00 40 11 a5 48 c0 a8 0a 01 E..I..@[email protected]....
0010 c0 a8 0a 0a 00 35 a3 7d 00 35 63 3f 9f 3c 81 80 .....5.}.5c?.<..
0020 00 01 00 01 00 00 00 00 07 65 78 61 6d 70 6c 65 .........example
0030 03 63 6f 6d 00 00 01 00 01 c0 0c 00 01 00 01 00 .com............
0040 00 0e 10 00 04 cb 00 71 50 .......qP
IPv4 bytes 0–19 · UDP bytes 20–27 · DNS reply bytes 28–72
The IPv4 header has total length 00 49 = 73, TTL 64, protocol 17, and runs from
192.168.10.1 to 192.168.10.10. Its identification field is 00 00: Linux leaves it at zero
on a Don't Fragment packet sent from an unconnected socket, like dnsmasq's listening socket on
port 53, because a packet that can't be fragmented never needs reassembling. The UDP header is
source port 53, destination 41853, and a length of 00 35 = 53, the 45 bytes of DNS plus 8: as
the UDP article predicted, and by coincidence the same number as the port.
Both checksums, the same way the UDP article worked the query's:
The six pseudo-header words:
The four UDP header words, with the checksum as zero:
The 23 words of DNS data. The answer starts at an odd offset, so its bytes pair up across fields, and the last byte gets a zero pad:
Add, fold and flip:
The UDP checksum is 63 3f. Notice the pseudo-header sum: the query's was 19591. Swapping
source and destination doesn't change a ones'-complement sum, so the only difference is the
length, 16 bytes longer, 0x10 more. The IPv4 header checksum covers just its own ten words:
The laptop's kernel checks both, finds its connected socket on port 41853 (which only accepts
datagrams from 192.168.10.1:53), and hands the 45 bytes to the resolver library. The library
checks that the ID is 9f3c and that the question matches what it asked, and only then believes
the answer.
Compression in a referral
A referral shows off compression better, because pointers can point into other records and
even at names that themselves end in a pointer. Here's step ⑥ of the walkthrough, the .com
server's 164-byte reply to the resolver (whose query, ID 5ab2, had RD clear and an EDNS record
offering 1232 bytes; more on that later):
Hex dump: the referral from .com
0000 5a b2 80 00 00 01 00 00 00 02 00 05 07 65 78 61 Z............exa
0010 6d 70 6c 65 03 63 6f 6d 00 00 01 00 01 c0 0c 00 mple.com........
0020 02 00 01 00 02 a3 00 00 06 03 6e 73 31 c0 0c c0 ..........ns1...
0030 0c 00 02 00 01 00 02 a3 00 00 06 03 6e 73 32 c0 ............ns2.
0040 0c c0 29 00 01 00 01 00 02 a3 00 00 04 cb 00 71 ..)............q
0050 0a c0 29 00 1c 00 01 00 02 a3 00 00 10 20 01 0d ..).......... ..
0060 b8 01 13 00 00 00 00 00 00 00 00 00 10 c0 3b 00 ..............;.
0070 01 00 01 00 02 a3 00 00 04 c0 00 02 46 c0 3b 00 ............F.;.
0080 1c 00 01 00 02 a3 00 00 10 20 01 0d b8 00 0d 00 ......... ......
0090 00 00 00 00 00 00 00 00 70 00 00 29 04 d0 00 00 ........p..)....
00a0 00 00 00 00 ....
-
Header:
5a b2 80 00 00 01 00 00 00 02 00 05Flags
80 00: a response, and nothing else. Not authoritative (the.comserver isn't the source forexample.com), no recursion offered. One question, no answers, two authority records, five additional. An empty answer with NS records in the authority section is what makes it a referral. -
First NS record, offset 0x1d
c0 0c(example.com), type00 02(NS), class IN, TTL00 02 a3 00= 172800, two days. RDLENGTH 6, and the data is a name:03 6e 73 31(ns1) thenc0 0c. A label, then a pointer for the rest:ns1.example.comin six bytes. Those six bytes start at offset0x29. -
Second NS record, offset 0x2f
The same again with
ns2, whose name starts at offset0x3b. -
Glue, offset 0x41
c0 29: a pointer to offset0x29, which readsns1and then hits another pointer,c0 0c, and carries on withexample.com. So the owner isns1.example.com, in two bytes. Type A, addresscb 00 71 0a=203.0.113.10. Then the same owner with type00 1c(AAAA) and2001:, anddb8: 113::10 c0 3bforns2's two addresses,192.0.2.70and2001:.db8: d::70 -
The OPT record, offset 0x99
The last eleven bytes,
00 00 29 04 d0 00 00 00 00 00 00, are the EDNS pseudo-record, which we'll take apart in the transport section.
Spelled out in full, those eight names would have taken 104 more bytes: 268 instead of 164. In
a real .com referral for a domain with four name servers, or the root's referral listing
thirteen, compression is the difference between fitting in a small UDP datagram and not.
Examples from the article
The question
The message
Field by field
Compression pointers
On the wire
Record Types
The TYPE field says what an RR's data means. Here's the whole example.com zone as its
operator might write it, in the zone file format from RFC 1035 that BIND and most other
servers read. Names without a trailing dot are relative to $ORIGIN, @ means the origin
itself, and a line that starts with a space belongs to the previous name:
$ORIGIN example.com.
$TTL 3600
@ SOA ns1 hostmaster (
2026103001 ; serial
7200 ; refresh
3600 ; retry
1209600 ; expire
300 ) ; negative-caching TTL
NS ns1
NS ns2
A 203.0.113.80
AAAA 2001:db8:113::80
MX 10 mail
TXT "v=spf1 mx -all"
CAA 0 issue "ca.example.net"
HTTPS 1 . ( alpn="h3,h2"
ipv4hint=203.0.113.80
ipv6hint=2001:db8:113::80 )
www CNAME @
ns1 A 203.0.113.10
AAAA 2001:db8:113::10
ns2 A 192.0.2.70
AAAA 2001:db8:d::70
mail A 203.0.113.25
_imaps._tcp SRV 0 1 993 mail
| Type | Holds | Here |
|---|---|---|
| A (1) | An IPv4 address | 203. |
| AAAA (28) | An IPv6 address | 2001: |
| NS (2) | A name server for this zone | ns1, ns2 |
| CNAME (5) | An alias for another name | www → @ |
| SOA (6) | Zone metadata, negative TTL | serial 2026 |
| MX (15) | A mail server, with a preference | mail, preference 10 |
| TXT (16) | Free text, used by many protocols | an SPF policy |
| PTR (12) | A name, for reverse lookups | see below |
| SRV (33) | Host and port for a service | IMAP over TLS on 993 |
| CAA (257) | Which certificate authorities may issue | one CA |
| HTTPS (65) | How to connect to a web origin | HTTP/3, address hints |
SOA: the zone's own record
Every zone starts with exactly one SOA, "start of authority". Its first two fields are
names: the primary server, ns1.example.com, and the administrator's mailbox written as a name,
hostmaster.example.com for [email protected]. Then five numbers:
- Serial, 2026103001. Secondary servers copy the zone from the primary, and they only bother when the serial goes up. A date plus a two-digit counter is the usual convention.
- Refresh (7200 s) and retry (3600 s): how often a secondary checks the serial, and how soon it tries again if the primary didn't answer.
- Expire (1209600 s, 14 days): how long a secondary keeps serving the zone if it can't reach the primary at all, before it gives up and stops answering for it.
- Minimum (300 s). Originally a default TTL, but since RFC 2308 it's the TTL for negative answers, which we'll meet in Caching.
Nowadays the primary also sends a NOTIFY (opcode 4) the moment the zone changes, and the secondaries fetch it with a zone transfer, AXFR for the whole zone or IXFR for just the changes, so the refresh timer is only a backstop.
CNAME: aliases, with rules
A CNAME says "this name is really that one; ask about that instead". Asked for
www.example.com, ns1 answers with the CNAME and, since it also serves the target, the
target's A record, in one 63-byte reply:
The answer section for www.example.com
0021 c0 0c 00 05 00 01 00 00 0e 10 00 02 c0 10 www CNAME, TTL 3600
002f c0 10 00 01 00 01 00 00 0e 10 00 04 cb 00 71 50 example.com A
The question name, 03 www 07 example 03 com 00, starts at offset 12, so
example.com on its own starts at 16 (0x10). The CNAME's whole
two-byte RDATA is c0 10: a pointer into the middle of the question. The A
record's owner is the same pointer.
Because a CNAME redirects every type of question about a name, a name with a CNAME can't
have any other records. That's why example.com itself can't be a CNAME: the top of a zone
must have SOA and NS records. Many DNS hosts offer a made-up "ALIAS" or "flattening" type to get
around it; the HTTPS record below is the standard way.
MX and TXT: mail and policy
MX records name the servers that accept mail for a domain, each with a preference number:
senders try the lowest first. A domain that never receives mail can say so with a "null MX",
preference 0 and a target of . (RFC 7505).
TXT records hold arbitrary strings, and a whole layer of email security lives in them.
v=spf1 mx -all is an SPF policy (RFC 7208): "only the hosts in my MX records send mail
for me; reject everything else". DKIM public keys and DMARC policies are TXT records too, at
special names like _dmarc.example.com, and so are the tokens services ask you to publish to
prove you control a domain.
PTR and reverse DNS
Going the other way, from an address to a name, uses the same tree. IPv4 addresses live under
in-addr.arpa, written backwards, one label per byte, because DNS names get more specific
to the left and addresses get more specific to the right:
Reverse names for the web server
203.0.113.80 → 80.113.0.203.
2001: → one label per hex digit, all 32 of them, reversed,
under ip6.arpa:
0.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.
0.0.0.0.3.1.1.0.8.b.d.0.1.0.0.2.ip6.arpa
The hosting company was delegated 113.0.203.in-addr.arpa along with its addresses, so it
can publish 80.113.0.203.in-addr.arpa PTR example.com. there. Reversing makes delegation
follow the address hierarchy: whoever holds a block can be handed the matching branch. Nothing
forces the forward and reverse names to agree, so careful software checks both ways. The
ARP article's arp -a output had a ? where a reverse lookup found no name.
SRV, CAA and HTTPS
SRV (RFC 2782) generalises MX to any service: _imaps._tcp.example.com gives a priority,
a weight for load sharing, a port and a host, so clients can find a service without hard-coding
where it lives. XMPP, SIP, LDAP and Kerberos all use it.
CAA (RFC 8659, originally RFC 6844) lists the certificate authorities allowed to issue certificates for the domain. Since September 2017, every publicly trusted CA must check it before issuing.
HTTPS and its general form SVCB (RFC 9460, November 2023) tell a client how to
connect before it connects: which protocols the server speaks (alpn="h3,h2" says
HTTP/3 over QUIC works, so there's no need to try TCP first), which addresses to use,
and the keys for Encrypted Client Hello. Priority 0 makes it an alias, which is the standard
answer to "CNAME at the top of a zone". Browsers now ask for HTTPS records alongside A and AAAA.
Caching and TTLs
The TTL is the zone owner's trade-off between speed and agility. A long TTL means fewer queries, faster answers and resilience if the authoritative servers have a bad hour. A short TTL means changes take effect quickly. Operators planning to move a service typically lower the TTL a day or two before the move, so that by moving day nobody has the old address cached for long, and raise it again afterwards.
Resolvers enforce limits of their own: most cap TTLs at a day or a week, and some raise very small ones. When a resolver can't reach any authoritative server for a name whose records have just expired, it may serve the stale data for a while rather than fail (RFC 8767, "serve-stale").
Negative caching: NXDOMAIN and NODATA
"There's nothing here" is an answer too, and it's worth caching just as much. There are two different kinds:
- NXDOMAIN (RCODE 3): the name doesn't exist at all, with any type.
- NODATA: the name exists, but has no records of the type asked for. There's no RCODE for it: it's a NOERROR reply with an empty answer section.
Both carry the zone's SOA record in the authority section, and RFC 2308 (1998) says the
negative answer may be cached for the smaller of the SOA record's TTL and its minimum field.
For example.com, that's min(3600, 300) = 300 seconds. Here's the NXDOMAIN for a name that
doesn't exist:
Hex dump: NXDOMAIN for nosuch.example.com, 87 bytes
0000 7d 05 81 83 00 01 00 00 00 01 00 00 06 6e 6f 73 }............nos
0010 75 63 68 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 uch.example.com.
0020 00 01 00 01 c0 13 00 06 00 01 00 00 01 2c 00 27 .............,.'
0030 03 6e 73 31 c0 13 0a 68 6f 73 74 6d 61 73 74 65 .ns1...hostmaste
0040 72 c0 13 78 c3 e0 d9 00 00 1c 20 00 00 0e 10 00 r..x...... .....
0050 12 75 00 00 00 01 2c .u....,
Flags 81 83: the usual 81 80 with RCODE 3. Counts: one question,
no answers, one authority record. The SOA's owner is c0 13,
offset 19, which lands in the middle of the question name, on 07 example, so it
reads example.com. Its TTL is 00 00 01 2c = 300. The RDATA,
00 27 = 39 bytes, is ns1 + pointer, hostmaster +
pointer, then the five numbers: 78 c3 e0 d9 = 2026103001, 7200, 3600, 1209600
and 300.
The difference between the two kinds matters. An NXDOMAIN for nosuch.example.com means no
type exists there, so a resolver can answer an AAAA query for it from the same cache entry. A
NODATA for example.com AAAA says nothing about A. Modern resolvers go further: an NXDOMAIN
means nothing exists below that name either (RFC 8020), and with DNSSEC, the signed proof of
a gap between two names lets a resolver answer for other names in the gap without asking
(RFC 8198).
Failures are cached too, briefly. A SERVFAIL, "I couldn't get an answer", may be remembered for a few seconds up to a few minutes, so that a broken zone doesn't get hammered by every resolver retrying at once.
UDP, TCP and Bigger Answers
512 bytes, TC, and TCP
RFC 1035 limited DNS over UDP to 512 bytes of message. If an answer didn't fit, the server sent what it could with the TC (truncated) bit set, and the client asked again over TCP, also on port 53. Because TCP is a byte stream with no message boundaries, every DNS message over TCP is preceded by a two-byte length. The laptop's query over TCP would be:
00 1d 9f 3c 01 00 00 01 00 00 00 00 00 00 07 65
78 61 6d 70 6c 65 03 63 6f 6d 00 00 01 00 01
00 1d = 29, then the identical 29 bytes. A TCP connection can carry many queries one after
another, and the replies may come back in any order, matched by ID. TCP was long treated as
optional for anything but zone transfers, which have always used it; RFC 7766 (2016) made
it mandatory for every implementation. It's the fallback that makes big answers possible at all,
and with DNSSEC signatures, answers got big.
EDNS(0): a bigger envelope
The header had no room left for new flags or sizes, so EDNS(0) (RFC 2671 in 1999, now RFC 6891) smuggles them into a fake record, the OPT pseudo-RR, in the additional section. It's never cached or forwarded as data; it just describes the message it's in. The UDP article mentioned that a real resolver library adds one. Here's the laptop's query with it, 40 bytes instead of 29:
The query with EDNS(0)
0000 9f 3c 01 00 00 01 00 00 00 00 00 01 07 65 78 61 .<...........exa
0010 6d 70 6c 65 03 63 6f 6d 00 00 01 00 01 00 00 29 mple.com.......)
0020 04 d0 00 00 00 00 00 00 ........
ARCOUNT becomes 1. The OPT record reuses the RR fields for other purposes:
00: NAME, the root.00 29: TYPE 41, OPT.04 d0: CLASS, here the largest UDP reply the sender can take: 1232 bytes.00 00 00 00: TTL, here an extended RCODE (8 bits), the EDNS version, 0, and 16 flag bits. The top flag is DO, "DNSSEC OK, send me signatures".00 00: RDLENGTH, then that many bytes of options. None here.
Options carry everything else that's been added since: cookies (RFC 7873), a lightweight way for client and server to recognise each other that makes forged replies and spoofed queries harder; Client Subnet (RFC 7871), which lets a resolver tell a CDN roughly where the user is, at some cost to privacy; padding (RFC 7830) for encrypted transports; and Extended DNS Errors (RFC 8914), which explain a SERVFAIL in words.
Why 1232
EDNS let clients advertise 4096 bytes, and many did. But a 4096-byte UDP reply doesn't fit in a
1500-byte Ethernet frame, so it gets
fragmented, and fragments get dropped by firewalls, mishandled by NATs, and
can be forged more easily than whole datagrams. On 1 October 2020, DNS Flag Day saw
the major resolver and server vendors switch to a default of 1232 bytes: the IPv6 minimum
MTU of 1280, less 40 bytes of IPv6 header and 8 of UDP, so a reply fits on any path
unfragmented. Anything bigger is truncated and retried over TCP. dnsmasq's default,
edns-packet-max, has been 1232 too since version 2.90; older versions offered 4096.
Encrypted DNS
Classic DNS is plain text. Anyone on the path, the café Wi-Fi or the ISP, can read every name a device looks up, and an on-path attacker can change the answers. Three standards wrap DNS in encryption, all carrying the same messages inside:
| Protocol | Transport | Port |
|---|---|---|
| DNS over TLS (DoT), RFC 7858, 2016 | TLS over TCP | 853 |
| DNS over HTTPS (DoH), RFC 8484, 2018 | HTTP/2 or HTTP/3 | 443 |
| DNS over QUIC (DoQ), RFC 9250, 2022 | QUIC | UDP 853 |
DoH messages are exactly the bytes we've been decoding, sent as the body of an HTTP request with
the type application/dns-message. Because it uses port 443, DoH looks like any other web
traffic, which makes it hard to block. That's the point, and also the controversy.
Encryption protects the path, not the destination. The resolver still sees every query, so
choosing an encrypted resolver means choosing whom to trust with your browsing history. And
when a browser sends DoH straight to a public resolver, it bypasses R1 entirely: names like
laptop.home.arpa, split-DNS setups like the one the NAT article suggested for the
NAS, and any filtering the network applies all stop working. Firefox, which began enabling DoH
by default for US users in 2020, checks a "canary" name, use-application-dns.net, and
backs off if the local resolver says it doesn't exist. Encrypting DNS also doesn't hide the
server name from the TLS handshake, unless the client uses Encrypted Client Hello,
whose keys come from, of course, an HTTPS record.
Names Inside the House
The DHCP article left two loose ends: what the laptop does with the DNS server it
was given, which we've now seen, and how laptop.home.arpa ended up in R1's answers. That's
dnsmasq doing both jobs at once. When it grants a lease, it takes the host name the client sent
in DHCP option 12, laptop, adds its configured domain, home.arpa, and starts answering for
the result. Ask R1 for laptop.home.arpa:
Hex dump: R1's answer for laptop.home.arpa, 50 bytes
0000 51 d2 85 80 00 01 00 01 00 00 00 00 06 6c 61 70 Q............lap
0010 74 6f 70 04 68 6f 6d 65 04 61 72 70 61 00 00 01 top.home.arpa...
0020 00 01 c0 0c 00 01 00 01 00 00 00 00 00 04 c0 a8 ................
0030 0a 0a ..
Two differences from the example.com reply. The flags are 85 80:
the AA bit is set, because R1 is the source of this data, and dnsmasq marks
answers from its DHCP leases and /etc/hosts as authoritative. And the TTL is
0: don't cache this at all. A lease can change hands at any moment, so by
default dnsmasq gives local names no lifetime (its local-ttl option changes that).
The reverse works too: a PTR query for 10.10.168.192.in-addr.arpa gets laptop.home.arpa
from the same lease. And the search domain from DHCP option 15 means the laptop can just ask
for nas and get nas.home.arpa, 192.168.10.30, the reserved address from the DHCP article.
Why home.arpa
Home routers used to invent domains like .lan or .home, or worse, .local, and every so
often a real TLD would be created with the same name. RFC 8375 (2018) reserved
home.arpa for exactly this: names that only mean something inside one home network. Since
.arpa is infrastructure, it will never be sold. R1 is configured never to send queries for
home.arpa upstream, and to answer NXDOMAIN for any name there it doesn't know, so the house's
names don't leak to the ISP's resolver. Likewise, dnsmasq's bogus-priv option answers reverse
queries for private addresses locally rather than asking the Internet about 192.168.x.x.
.local and multicast DNS
There's a second way to find names on a LAN, with no server at all. Multicast DNS
(RFC 6762, 2013) sends ordinary DNS messages, the same header and records, to the multicast
group 224.0.0.251 or ff02::fb on UDP port 5353, the socket the
UDP article found listening on the laptop. Every device answers for its own
name, which always ends in .local. The Pi at 192.168.10.11 answers for pi.local itself;
nobody configured R1 to know about it. The top bit of the class field gets reused: in a
question it asks for a unicast reply, and in an answer it means "flush your older cache entries
for this name".
On top of it, DNS-SD (RFC 6763) uses PTR, SRV and TXT records to advertise services, like
_ipp._tcp.local for printers, which is how the laptop finds the printer at 192.168.20.20,
provided something forwards mDNS between the VLANs, as the VLANs article noted.
Apple calls the combination Bonjour; on Linux it's Avahi or systemd-resolved. Because .local
belongs to mDNS, a unicast DNS zone should never use it, which is one more reason
home.arpa exists.
Two Kinds of Address
The IPv6 article left DNS to explain how one name maps to both kinds of address. The answer is simply two record types. A holds four bytes; AAAA ("quad-A", type 28, RFC 3596) holds sixteen. A name can have either, both or several of each, and they're independent: asking for AAAA over IPv4 works fine, and so does asking for A over IPv6.
When the browser looks up example.com with no preference, the laptop's resolver library sends
two queries back to back, on the same socket: the A query we've decoded, and an AAAA query with
its own ID, 3a71. The reply to the second is 57 bytes:
Hex dump: the AAAA reply
0000 3a 71 81 80 00 01 00 01 00 00 00 00 07 65 78 61 :q...........exa
0010 6d 70 6c 65 03 63 6f 6d 00 00 1c 00 01 c0 0c 00 mple.com........
0020 1c 00 01 00 00 0e 10 00 10 20 01 0d b8 01 13 00 ......... ......
0030 00 00 00 00 00 00 00 00 80 .........
Type 00 1c = 28 in the question and the answer, RDLENGTH 00 10 =
16, and sixteen bytes of 2001:.
The UDP checksum works out to 8a ff and the IPv4 header checksum to
a5 3c.
With both answers in hand, the browser runs
Happy Eyeballs (RFC 8305), just as the IPv6 article described: it
starts with 2001:db8:113::80, and if that hasn't connected within about 250 ms, it starts
203.0.113.80 too and keeps whichever wins. The DNS side has one detail of its own: the RFC
asks for the AAAA query to go first, and if the A answer arrives first, to wait up to 50 ms
for the AAAA before starting at all, so a slightly slow AAAA doesn't hand every connection to
IPv4.
DNS64 in detail
The IPv6 article sketched how a phone on an IPv6-only network reaches a
server that only has IPv4. DNS is where the trick happens. Suppose example.com had no AAAA
record, and the phone's network runs a DNS64 resolver (RFC 6147, 2011) next to its NAT64
gateway:
-
The phone asks for AAAA
It's IPv6-only, so it asks the network's resolver for
example.comAAAA, an ordinary query. -
The resolver gets NODATA
The DNS64 resolver asks
ns1.example.comand gets NOERROR with an empty answer section, plus the SOA. That's what triggers synthesis. An NXDOMAIN wouldn't: if the name doesn't exist, it has no A record either, and the NXDOMAIN goes back unchanged. -
The resolver asks for A
It gets
203.0.113.80, TTL 3600. -
It synthesises an AAAA
It puts the four bytes
cb 00 71 50at the end of the NAT64 prefix, the well-known64:ff9b::/96here, and answers the phone withexample.comAAAA64:ff9b::. The TTL is the smaller of the A record's and the SOA record's from the negative answer: min(3600, 300) = 300 seconds. (As the IPv6 article warned, this is an illustration: a real DNS64 won't synthesise from a documentation address with the well-known prefix.)cb00: 7150 -
The phone connects
To the phone it's just an IPv6 address. Its packets are routed to the NAT64 gateway, which translates them to IPv4 for
203.0.113.80, as the IPv6 article described.
Three details make it work in practice:
- When a real AAAA exists, it wins. DNS64 only synthesises when the name has no AAAA. It
also drops AAAA records in excluded ranges, such as IPv4-mapped addresses
(
::ffff:0:0/96), and synthesises instead. - It's a lie, and DNSSEC can tell. A synthesised record has no valid signature. A phone that validates DNSSEC itself would reject it, so if a query sets both DO and CD, "I'll validate myself", the DNS64 must not synthesise; the client gets the real answers and has to do the synthesis on its own.
- Clients can learn the prefix. Apps that use IPv4 literals, and 464XLAT's CLAT, need to
know the network's NAT64 prefix. RFC 7050 finds it by asking for the AAAA of
ipv4only.arpa, a name that deliberately has only A records,192.0.0.170and192.0.0.171. Whatever comes back is synthesised, and the prefix is the part before those known bytes. Networks can also announce it directly in Router Advertisements (RFC 8781).
When DNS Lies, and When It Fails
DNS was designed for a friendlier network. A plain UDP reply is accepted if it comes from the right address and port, carries the right ID and echoes the right question. Nothing proves it came from the real server. This section covers the ways that's been abused and defended, with no attack demo; the defences are the useful part.
Cache poisoning and the Kaminsky attack
If an attacker can get a forged reply into a resolver's cache, every user of that resolver gets the attacker's address until the TTL runs out. To do it, the forgery has to arrive before the real reply and match the query's ID, source port and question.
For years, resolvers sent every query from the same source port, so only the 16-bit ID stood in
the way: one chance in 65,536 per forged packet. Even so, attacks were rare, because the
attacker only got one try per name per TTL. Once the real answer was cached, there was nothing
to race. In 2008, Dan Kaminsky found the way around that. Instead of racing for
www.example.com, ask the resolver about names that don't exist, a different one every time,
so there's always a fresh race; and make each forged reply carry, in its authority and
additional sections, a referral claiming that example.com's name servers are now the
attacker's. That data was in bailiwick, so resolvers accepted it, and with it the whole domain.
With enough races, a single forged reply landing first was a matter of seconds. Vendors released
coordinated patches on 8 July 2008, and Kaminsky presented the details at Black Hat that
August.
The fix, then and now, is entropy:
- Random source ports. As the UDP article explained, picking each query's source port at random multiplies the guess by tens of thousands: 16 bits of ID and about 15 bits of port make odds of more than a billion to one per forged packet. RFC 5452 (2009) made it a requirement. dnsmasq on R1 does it for its upstream queries.
- NATs mustn't undo it. A resolver behind a NAT sends from random ports, but the outside world sees whatever ports the NAT picks. In 2008, some NATs turned a patched resolver's random ports back into sequential ones, quietly removing the defence. That's one reason the NAT article mentioned NATs that allocate ports at random. R1's own upstream queries leave from its WAN address with no NAT in the way.
- Mixed case. Since servers echo the question exactly, a resolver can randomise the case
of the letters it sends,
eXaMPle.cOm, and reject replies that don't match: a few more bits for long names. It's often called "0x20 encoding", after the bit that separates upper and lower case in ASCII. - Stricter acceptance. Modern resolvers are much more careful about which records from a reply they cache, and DNS cookies let a server's replies prove they belong to a particular client.
Implementation bugs undo all of this, of course. In 2021, a set of flaws named DNSpooq let dnsmasq accept replies on one forwarding port that were meant for another, which shrank the odds a long way; dnsmasq 2.83 fixed it, and it's one more reason to keep a home router updated.
DNSSEC: signing the answers
Entropy makes forgery improbable. DNSSEC (RFC 4033 to 4035, 2005) makes it detectable, by signing the data itself:
- DNSKEY records hold a zone's public keys.
- RRSIG records hold signatures over each set of records, made with the zone's private key.
- DS ("delegation signer") records live in the parent zone, next to the NS records, and hold a hash of the child's key. The parent signs them like any other data.
- NSEC or NSEC3 records prove that a name or type doesn't exist, by signing the gap between two names that do.
A validating resolver starts from one key it trusts, the root's, built in like the root hints.
It checks the root's DNSKEY with it, the DS for com against that, com's DNSKEY against the
DS, and so on down to the RRSIG over example.com's A record. A forged answer fails the check,
however perfectly its ID and port were guessed. The root zone has been signed since July 2010;
its key was changed for the first time in October 2018, and a second new key,
KSK-2024, took over on 11 October 2026.
The resolver reports the result in the header. If it validated the answer, and the client signalled that it understands DNSSEC by setting DO or AD in its query, it sets AD in the reply. If validation fails, the client gets SERVFAIL instead of the forged data. The laptop's query set neither, so R1's reply has AD clear whatever the resolver did. A client that wants to check signatures itself sets CD, and gets the records unvalidated, signatures included. DNSSEC protects the data, not the privacy: the signed answers are still readable by anyone on the path, which is what encrypted transports are for.
Amplification
The UDP article explained reflection attacks: send small requests with a forged source address, and let a server send big replies to the victim. DNS is a classic amplifier, with replies up to dozens of times the size of the question, especially for queries that return many or signed records. The defences:
- No open resolvers. A recursive resolver should only answer its own users. R1's dnsmasq listens only on the LAN interfaces, so nobody on the Internet can use it. The forgotten open resolvers on misconfigured routers are what attackers go looking for.
- Response Rate Limiting on authoritative servers, which notices the same answer going to the same address over and over and stops, or sends a tiny truncated reply that makes a genuine client retry over TCP, which can't be spoofed.
- Minimal answers to ANY. A query for type ANY used to return every record for a name. RFC 8482 (2019) lets servers answer with just one.
- BCP 38, as ever: networks that drop packets with forged source addresses stop reflection at the source.
When the authoritative servers vanish: Facebook, 2021
The BGP article told how, on 4 October 2021, a maintenance command disconnected Facebook's data centres from each other, and Facebook's DNS servers, designed to withdraw their BGP announcements when they can't reach the data centres, all withdrew at once, around 15:40 UTC. Here's what that looked like from DNS's side.
Facebook ran its own authoritative servers for facebook.com, in its own address space. The
.com zone still held the delegation, NS records and glue, so resolvers knew exactly which
addresses to ask. But with the routes withdrawn, there was no path to those addresses. Every
query timed out, and resolvers everywhere returned SERVFAIL. Once cached answers expired, every
Facebook, Instagram and WhatsApp name stopped resolving. Apps and users kept retrying, and
Cloudflare reported resolvers worldwide handling about 30 times their usual query volume;
its public resolver couldn't resolve facebook.com from about 15:50 to 21:20 UTC.
The lesson is the one in RFC 1034's "at least two servers": they need to fail independently,
and here every server depended on the same network. That's why our ns2.example.com lives with a
different provider on a different network from ns1. The servers being down was only half of
it; DNS was the other system that had to keep working for Facebook to be reachable, and it
couldn't without BGP.
DNS on the Command Line
dig
dig sends exactly the queries you ask for and prints everything that comes back. Here's the
laptop asking R1 again ten minutes after the first lookup, without EDNS so that the reply is the
same 45-byte shape we decoded (blank lines removed):
dig +noedns example.com on the laptop
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18077
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 3000 IN A 203.0.113.80
;; Query time: 0 msec
;; SERVER: 192.168.10.1#53(192.168.10.1) (UDP)
;; WHEN: Fri Oct 30 09:24:07 UTC 2026
;; MSG SIZE rcvd: 45
dig picked its own ID, 18077 in decimal. The flags line lists the bits that are
set: qr rd ra is our 81 80. The TTL is 3000, counting down in R1's
cache. An aa in the flags would mean the answer came straight from the source.
dig +trace skips the resolvers and does the walk itself, from the root down, just like the ISP
resolver in our walkthrough. Trimmed:
$ dig +trace +nodnssec +nocookie example.com
. 518400 IN NS a.root-servers.net.
. 518400 IN NS b.root-servers.net.
(11 more, c to m)
;; Received … bytes from 192.168.10.1#53(192.168.10.1)
com. 172800 IN NS a.gtld-servers.net.
(12 more, b to m)
;; Received … bytes from 192.0.2.53#53(a.root-servers.net)
example.com. 172800 IN NS ns1.example.com.
example.com. 172800 IN NS ns2.example.com.
;; Received 164 bytes from 192.0.2.60#53(a.gtld-servers.net)
example.com. 3600 IN A 203.0.113.80
;; Received 56 bytes from 203.0.113.10#53(ns1.example.com)
The third step is the 164-byte referral we decoded. The last reply is 56 bytes: our 45-byte
answer plus dig's 11-byte OPT record. Other handy forms: dig AAAA example.com,
dig -x 203.0.113.80 for the PTR, dig @203.0.113.10 example.com to ask one server directly
(look for aa in the flags), and dig +short for just the data.
What the laptop is configured to use
On a plain Linux system, the stub's settings are in one file:
$ cat /etc/resolv.conf
nameserver 192.168.10.1
search home.arpa
Both came from DHCP options 6 and 15. On systems with systemd-resolved, resolv.conf says
nameserver 127.0.0.53 instead, and resolvectl shows the real upstream servers per interface:
resolvectl status eth0 lists 192.168.10.1 and R1's IPv6 address, and
resolvectl query example.com resolves through the same path as every application and reports
which link and protocol the answer came from. getent hosts example.com asks via the system's
full lookup order, which on Linux usually checks /etc/hosts first: HOSTS.TXT's descendant
still wins over DNS.
dnsmasq on R1
The DHCP article showed the DHCP half of R1's configuration. The DNS half is just as short:
# /etc/dnsmasq.conf on R1 (DNS part)
domain-needed
bogus-priv
no-resolv
server=198.51.100.53
server=2001:db8:1200::53
local=/home.arpa/
expand-hosts
cache-size=1000
log-queries
domain-needed: never forward a bare name likenasupstream.bogus-priv: answer reverse lookups for private ranges locally.no-resolvandserver=: use the ISP's resolvers (the IPv4 one came in the ISP's DHCP option 6, the IPv6 one via DHCPv6 or a Router Advertisement) rather than reading/etc/resolv.conf.local=/home.arpa/: answer forhome.arpafrom local data only, never forwarding.expand-hosts: add the domain to names in R1's own/etc/hoststoo.cache-size=1000: the default is 150 names, small even for a home.log-queries: log every query, worth having while learning, noisy afterwards.
With logging on, the lookups from this page leave a trail on R1:
dnsmasq[812]: query[A] example.com from 192.168.10.10
dnsmasq[812]: forwarded example.com to 198.51.100.53
dnsmasq[812]: reply example.com is 203.0.113.80
dnsmasq[812]: query[A] example.com from 192.168.10.40
dnsmasq[812]: cached example.com is 203.0.113.80
dnsmasq[812]: query[A] laptop.home.arpa from 192.168.10.40
dnsmasq[812]: DHCP laptop.home.arpa is 192.168.10.10
The first lookup was forwarded, the desktop's ten minutes later came from the cache, and
laptop.home.arpa came from the lease file. Sending dnsmasq SIGUSR1 writes its cache
statistics to the log, including how many queries it answered locally and how many it forwarded.
Where to Go Next
- HTTP: the next article. The laptop has
203.0.113.80and a TCP connection; now it can ask for the page, withHost: example.comtelling the server which site it wants. - UDP: the datagram that carried the query, its checksum, random source ports, and reflection attacks.
- NAT: how the laptop's packets reach
203.0.113.80once it has the address, and port allocation strategies. - DHCP: where the laptop got
192.168.10.1as its DNS server andhome.arpaas its domain. - IPv6: Happy Eyeballs, NAT64 and the RDNSS option that also names R1 as a resolver.
- BGP: anycast for the root servers, and the routing failure that took Facebook's DNS with it.
- TLS: the encryption under DoT and DoH, and the certificates CAA records control.
Key Takeaways
- DNS replaced SRI-NIC's single HOSTS.TXT file with a hierarchical, delegated, cached database: Mockapetris's RFC 882/883 (1983), then RFC 1034/1035 (1987), still the core specification.
- Names are paths in a tree of labels ending at the empty root label,
example.com.; labels up to 63 bytes, names up to 255. A zone is the part of the tree one set of authoritative servers answers for; NS records in the parent delegate the rest. - Stub resolver (laptop), forwarder (dnsmasq on R1), recursive resolver (the ISP's) and authoritative servers (root, .com, ns1/ns2.example.com). The root is 13 letters run by 12 organisations, anycast to around 2,000 instances; resolvers find it from root hints and a priming query.
- A cold lookup asks the root, then .com, then example.com's server, following referrals with glue. Clients send recursive queries (RD); resolvers send iterative ones. Every record is cached for its TTL, and caches pass on only the time remaining.
- Messages are a 12-byte header (ID, QR, Opcode, AA, TC, RD, RA, Z, AD, CD, RCODE, four counts) then question, answer, authority and additional sections. Records are name, type, class, TTL, length, data. The laptop's query is 29 bytes; R1's reply is 45, flags
81 80, TTL 3600, UDP checksum63 3f, IPv4 checksuma5 48. - Names are length-prefixed labels ending in
00. A byte starting with11is a compression pointer:c0 0cmeans "the name at offset 12". Decoders must guard against pointer loops. - Key types: A, AAAA, NS, CNAME, SOA, MX, TXT, PTR (under in-addr.arpa and ip6.arpa), SRV, CAA and HTTPS/SVCB. Negative answers (NXDOMAIN, or NODATA as an empty NOERROR) carry the SOA and are cached for min(SOA TTL, SOA minimum).
- UDP answers were limited to 512 bytes; TC sends clients to TCP with a 2-byte length prefix. EDNS(0)'s OPT pseudo-record advertises bigger buffers; since DNS Flag Day 2020 the default is 1232 bytes. DoT (853), DoH (443) and DoQ encrypt the path but not from the resolver.
- dnsmasq answers
laptop.home.arpafrom DHCP leases, with AA set and TTL 0. home.arpa (RFC 8375) is reserved for home networks; .local belongs to multicast DNS on port 5353. - A and AAAA are independent records; clients ask for both and use Happy Eyeballs. DNS64 synthesises an AAAA from the A record when none exists, with the NAT64 prefix, unless the client asks to validate DNSSEC itself.
- Random IDs and source ports (RFC 5452) defend against Kaminsky-style poisoning, and NATs mustn't de-randomise them; DNSSEC signs the data with a chain of DS and DNSKEY records from the root. Open resolvers enable amplification. Facebook's 2021 outage showed authoritative servers need to fail independently.
The laptop finally has what it needed: example.com is 203.0.113.80, and
2001:db8:113::80 too. Everything from here on has been covered: the SYN, the trip
through R1's NAT, the routers along the way. What's left is
the reason for all of it: the request the browser sends once the connection is open, and the
page that comes back. That's HTTP.