task 5.1 · chapter 5 of 8: dns · 15 min
Names and answers
objective
Capture three lookups, match each question to its answer by transaction ID, and read an address, a TTL, an alias (CNAME) and a name that doesn’t exist.
answers/5.1.ymlopen a file in VS Code: Ctrl+P (Cmd+P on a Mac), type its name, Enter
| Capture | make capture AT=laptop:eth1 NAME=5.1 X=dns: web.lab, intranet.lab, nas.lab |
|---|---|
| Filter | dns |
| Your answers | answers/5.1.yml |
new to this? step by stepbeginner
make capture AT=laptop:eth1 NAME=5.1 X=dns, open it, filterdns.- Open web.lab’s response: the address and its Time to live.
- Challenge: intranet.lab’s response (two answers), and the response that says No such name.
- Fill in answers/5.1.yml, then
make check T=5.1.
more in meet the lab
A question, an answer, and how long to trust it
DNS on the wire
Networking 101 described DNS as the network’s phone book: you give it a name, it gives you an address. On the wire that’s exactly two packets, usually UDP to port 53: a query with the question in it, and a response with the question copied back and the answers added.
UDP doesn’t keep a conversation going the way TCP does (chapter 6), so how does the laptop know which response answers which question? Each query carries a random 16-bit transaction ID, and the server copies it into its response. Wireshark pairs them up for you and notes the frame number of the other half.
in one sentence A DNS lookup is one query and one response, matched by a transaction ID.
What’s in an answer
Each answer is a record: a name, a type, a value, and a TTL.
| Record type | Value |
|---|---|
| A | an IPv4 address |
| AAAA | an IPv6 address |
| CNAME | another name: this name is an alias, look up that one instead |
The TTL (time to live, again, but not the IP header’s) says how many seconds the answer may be kept and reused before asking again. Low TTLs mean changes spread fast; high ones mean fewer lookups.
When the answer is no
A response always has a reply code (rcode). No error (0) means here’s your answer. NXDOMAIN
(3), which Wireshark shows as No such name, means the name doesn’t exist. That’s an answer too, not a failure
to answer: the server is sure.
dig, and the same thing in Wireshark
dig is the tool for asking DNS directly. Its answer section is the record, TTL included:
laptop:~# dig web.lab
...
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30408
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
...
;; ANSWER SECTION:
web.lab. 60 IN A 192.168.2.10
id: 30408 is the transaction ID, in decimal. The three lookups the lab makes, in Wireshark:
2 0.177191250 192.168.1.175 → 192.168.2.53 DNS 90 Standard query 0x4ed9 A web.lab OPT
3 0.177997208 192.168.2.53 → 192.168.1.175 DNS 94 Standard query response 0x4ed9 A web.lab A 192.168.2.10 OPT
4 0.214206625 192.168.1.175 → 192.168.2.53 DNS 95 Standard query 0x0e93 A intranet.lab OPT
5 0.214420333 192.168.2.53 → 192.168.1.175 DNS 120 Standard query response 0x0e93 A intranet.lab CNAME web.lab A 192.168.2.10 OPT
6 0.249419875 192.168.1.175 → 192.168.2.53 DNS 90 Standard query 0x0ef2 A nas.lab OPT
7 0.249925583 192.168.2.53 → 192.168.1.175 DNS 78 Standard query response 0x0ef2 No such name A nas.lab OPT
Frame 5 opened, answers only (... marks lines left out):
Domain Name System (response)
Transaction ID: 0x0e93
Flags: 0x8580 Standard query response, No error
...
Answers
intranet.lab: type CNAME, class IN, cname web.lab
...
Time to live: 60 (1 minute)
CNAME: web.lab
web.lab: type A, class IN, addr 192.168.2.10
...
Time to live: 60 (1 minute)
Address: 192.168.2.10
OPT on the end of each line is EDNS, a small extension record dig adds to say it can take bigger
answers. It isn’t part of the answer.
The first lookup
Capture the laptop looking up three names:
run in the terminalmake capture AT=laptop:eth1 NAME=5.1 X=dnsOpen
/captures/5.1.pcapngand filterdns. Check each query’s transaction ID against the response below it.Click the response for web.lab and open Answers. Read the address and the Time to live.
Fill in the follow-along lines:
editanswers/5.1.ymlCtrl+P → 5.1.ymlweb_ip: 192.168.2.10 ttl: 60
An alias and a no
cname_target: the name intranet.lab is an alias for;nxdomain_name: the name that doesn’t exist.
hint
intranet.lab’s response has two answers. The first one is the CNAME.
hint
Filter dns.flags.rcode == 3.
show the solutionanswers/5.1.yml
or pull it into your lab: make solve T=5.1, then git diff --staged shows what changed
cname_target: web.lab
nxdomain_name: nas.lab
The server answered intranet.lab with it’s really web.lab, and web.lab is 192.168.2.10, both in one
response, so the laptop didn’t have to ask twice. Websites do this all the time: www.example.com is often a
CNAME for a content delivery network’s name.
5 check: run it, then prove it
$ make check T=5.1when it's right, you'll see
╭─ task 5.1 · names and answers
│ ✓ captures/5.1.pcapng: taken on laptop:eth1, 7 frames
│ ✓ web.lab's address, from the answer (follow along): 192.168.2.10
│ ✓ how long that answer may be cached, in seconds (follow along): 60
│ ✓ the name intranet.lab is an alias for (challenge): web.lab
│ ✓ the name that doesn't exist (challenge): nas.lab
╰─ 5/5 checks passed verified