DNS on the wire a show in 8 chapters
Goal: send every question and its answer in one packet each way
1 of 8 Your guess
Before we start
You type example.com, and your computer asks a resolver for its address, the concierge from the last lesson. That question leaves your machine as a message, and the answer comes back as one.
What does the question look like the moment it goes out on the wire?
Pick the closest. You find out which fits at the end.
The links of 1987. Some carried only a few hundred bytes whole.
2 of 8 The problem
1987: the postcard rule
November 1987, the University of Southern California's Information Sciences Institute. Paul Mockapetris signs off RFC 1035, the document that still defines every DNS message sent today.
The internet then was a patchwork: Ethernet, dial-up lines, satellite hops. Some of those links refused to carry a big message whole. They split it in two, and two pieces are two chances to lose one.
Messages are measured in bytes: one byte is one whole number from 0 to 255. The fast way to send a DNS message is UDP: no handshake first, one packet out and one back.
So Mockapetris set one plain rule. A DNS answer sent by UDP may be at most 512 bytes, the largest piece he could trust every link of the day to carry whole.
Your goal: send every question and its answer in one packet each way, under the limit.
The real bytes of the lesson's query. The ID, 0a 04, is a random tag the reply must carry back.
3 of 8 The idea
Every letter, counted
A computer sees only bytes, in an order both ends agreed on in advance. Written in hex, a byte is two characters, 00 to ff.
The same byte can be read two ways. 65 in hex is 6 × 16 + 5 = 101, and in the numbering everyone agreed on in the 1960s, 101 is also the letter e. The format decides which reading applies where.
Why write a byte in hex?
Any byte fits in exactly two hex characters, 00 to ff, so every byte in a dump lines up in the same width. In ordinary numbers a byte takes one, two or three digits.
A telegram charges by the letter, so every letter is counted. DNS sends a name the same way: each chunk starts with how many letters follow. A dot would cost a byte, and would need special handling the moment a name contained one.
Press Play to write example.com onto the form, one byte at a time.
What changed
- The name: 11 characters typed → 13 bytes sent
Every DNS message starts with a header, always 12 bytes: a random ID, the flags, and four counts of what follows. Then the counted name, then 4 bytes saying what you want to know: an address, on the internet.
12 + 13 + 4 = 29 bytes. Nothing labels a field: the rulebook says where each one sits. 29 is a long way under 512.
26 names, 18 bytes each, spelled out in full: 242 + 26 × (18 − 2) = 658 bytes
4 of 8 Try it
The ditto mark
The answer to your question repeats the name once per address it hands back, and example.com has two. DNS never retypes it. It writes two bytes, c0 0c, meaning "same name as the one at byte 12 of this message". That is the ditto mark, a compression pointer.
Each answer is the 2-byte ditto mark, 10 fixed bytes, and the 4-byte address: 16 bytes. The reply echoes your 29-byte question, then adds two answers: 29 + 16 + 16 = 61 bytes.
A saving of 11 bytes looks like nothing until you ask for something big. Ask for the internet's 13 root name servers and one reply names them all, 26 names in total.
Here every name is spelled out in full. Now put the ditto marks back.
658 bytes: over the 512-byte limit.
What changed
- The root's reply: 658 → 242 bytes
The single most-sent message in all of DNS fits one packet only because of a saving from 1987.
1 trip for the stamp + 2 for TCP = 3 round trips, where one would do
5 of 8 The cost
Too long, call me
By the late 1990s DNS had new jobs. An answer might carry a security signing key, and answers that size stopped being rare. Ask for the root's signing keys while saying you take only 512 bytes, and this comes back.
17 bytes: the header and your question echoed, no answer at all. One bit is set, TC, truncated. Not an error: "ask me again the slow way".
The slow way is TCP: before any data moves, the two ends shake hands to open a connection, and then any size fits.
A whole lookup over UDP is two packets. Each message rides inside two envelopes, an IPv4 header of 20 bytes and a UDP header of 8: 20 + 8 + 29 = 57 bytes out and 20 + 8 + 61 = 89 back, one round trip. The stamp turns that into 3 round trips.
A page touches a dozen names. Paying three trips on every big one was the cost.
1,280 (IPv6's smallest guaranteed piece) − 40 (IPv6 header) − 8 (UDP header) = 1,232
6 of 8 The fix
1999: Vixie's note
August 1999. Paul Vixie, then at the Internet Software Consortium, writes RFC 2671: a note a machine can clip to its own question, saying "actually, I can take more than 512 bytes back".
A server that understands the note uses it. A server that has never heard of it ignores it and answers the old way. One extra record, twelve years later, moved the limit without breaking anything already running. It is called EDNS0.
Almost everything today writes 1,232 on the note: the largest reply that IPv6's smallest guaranteed piece can carry without being split.
The root's signing keys come back at 853 bytes. Over the old 512, under 1,232: one packet, one round trip, no stamp, no TCP.
What changed
- Round trips for the root's keys: 3 → 1
7 of 8 Your guess
Your picture now
Goal met: a question is 29 bytes, the root's reply 242 with its ditto marks, and with Vixie's note the root's 853-byte keys come back in one packet. Which picture is closest now?
Pick one.
c is the wire: counted chunks, in an order both ends know from the rulebook. a is how you typed it, but the dot never goes out. b labels every field, and DNS never does: RFC 1035 says where each field sits.
8 of 8 Keep this
Keep this
A DNS message is bytes in an agreed order: a 12-byte header, names as counted chunks, and a 2-byte ditto mark wherever a name repeats. It is small on purpose, so a question and its answer each fit in one packet.
The price: past the limit the reply comes back empty and stamped, and the redial over TCP costs two more round trips, unless the question carries the EDNS0 note.
Read the full lessonComing up You have read all 29 bytes of the question. Next: type them yourself and send them, and meet Dan Kaminsky's 2008 attack, a fake reply almost any computer would believe.