Skip to content
Sign inGet all access
Chapter 1·8 minFree

Names and Answers

One query read properly, and the packet it travelled in.

Everyone edits DNS records. Almost nobody reads a DNS reply.

What DNS is for

Turning names into addresses, and a good deal more. Mail routing, certificate policy, domain ownership proofs and service discovery all live in the same database — chapter 3.

This course uses one tool. Every snippet is a dig against the live internet, so nothing you run can change anything.

Your first dig

Four sections come back. Blank lines and the dig banner removed, the reply is this:

terminal
dig @1.1.1.1 example.com
Output;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34279;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1;; OPT PSEUDOSECTION:; EDNS: version: 0, flags:; udp: 1232;; QUESTION SECTION:;example.com. IN A;; ANSWER SECTION:example.com. 13 IN A 104.20.23.154example.com. 13 IN A 172.66.147.243

+short

When you want the answer and nothing else:

dig @1.1.1.1 +short example.com | sort
Output104.20.23.154172.66.147.243

The header flags

One line carries the whole state of the reply:

dig @1.1.1.1 +noall +comments example.com | grep '^;; flags'
Output;; flags: qr rd ra ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
Flag Means
qr this is a response, not a question
rd recursion was desired
ra recursion is available here
aa authoritative answer — this server owns the zone
ad authenticated data — DNSSEC validated
tc truncated, ask again over TCP

aa is missing above because 1.1.1.1 does not own example.com. Ask a server that does:

dig @elliott.ns.cloudflare.com +noall +comments example.com | grep '^;; flags'
Output;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

aa appeared and ra vanished — an authoritative server owns the answer and will not recurse for you. Chapter 4 is about that division.

Question and answer

The question is echoed back, so you can tell what was actually asked:

dig @1.1.1.1 +noall +question example.com
Output;example.com. IN A

The answer is name, TTL, class, type, data — five columns:

dig @1.1.1.1 +noall +answer example.com | awk '{print $1,$4,$5}' | sort
Outputexample.com. A 104.20.23.154example.com. A 172.66.147.243

IN is the class, and in practice it is always IN — the others were defined in 1987 and are museum pieces.

Who answered

Every reply names the server that produced it:

terminal
dig @1.1.1.1 example.com | grep '^;; SERVER'
Output;; SERVER: 1.1.1.1#53(1.1.1.1)

One question, one packet

A query is one UDP datagram to port 53, and the reply is one back. The original limit was 512 bytes, which is why so much of DNS is terse.

terminal
dig @1.1.1.1 example.com | grep 'MSG SIZE'
Output;; MSG SIZE rcvd: 72

Truncation and TCP

When an answer does not fit, the server sets tc and sends nothing useful:

dig @1.1.1.1 +ignore +bufsize=512 TXT google.com | grep '^;; flags'
Output;; flags: qr tc rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

ANSWER: 0 — there is no data, only the instruction to ask again. A resolver retries over TCP automatically; +ignore above told dig not to:

dig @1.1.1.1 +tcp +short example.com | sort
Output104.20.23.154172.66.147.243

EDNS0

An extension that raises the UDP limit, announced in a pseudo-section:

dig @1.1.1.1 example.com | grep '^; EDNS'
Output; EDNS: version: 0, flags:; udp: 1232

1232 is the buffer this resolver will accept, chosen to stay under the real path MTU. Without EDNS0 the ceiling is 512 bytes and almost every DNSSEC answer truncates.

The query ID

Sixteen bits, chosen by the client, echoed in the reply:

terminal
dig @1.1.1.1 example.com | grep 'HEADER'
Output;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53726

That number plus the source port is the only thing tying a reply to a question. A forged packet arriving first, with the right ID, is believed.