CloudAcademia
EN

Networking · Module 11 · DNS: How Names Become Addresses

Lab: Tracing a Resolution and Running Your Own Zone

Lab60 minBeginnerMarkdown

Showing raw Markdown: the renderer could not load.

## Goal
Use `dig` to follow a real name resolution from the root down, read every part of a DNS answer, and compare DNS transports. Then run your own authoritative DNS server in a container, serving the zone `lab.example`, query it, change a record and watch the SOA serial decide when the change goes live.

## Objectives
- Follow a resolution from the root to the authoritative servers with `dig +trace`, and see caching at work as the TTL counts down.
- Query and recognize the common record types: A, AAAA, CNAME, MX, NS, TXT, PTR, SOA and CAA.
- Read `dig` output: status, flags (`qr`, `aa`, `rd`, `ra`, `ad`, `tc`), and the answer, authority and additional sections.
- Send the same query over UDP, TCP, DNS over TLS and DNS over HTTPS, and see truncation trigger a retry over TCP.
- Run an authoritative server for a zone of your own, change a record and confirm the change with the SOA serial.

## Prerequisites
- `dig` from BIND 9.18 or later (`dig -v`). On Fedora/RHEL: `bind-utils`; on Debian/Ubuntu: `bind9-dnsutils`; on macOS: `brew install bind` (the `dig` that ships with macOS is older and lacks `+tls` and `+https`). On Windows, use a Linux distribution in WSL2.
- Podman 4 or later (tested with Podman 5.8, rootless, no `sudo`), or Docker 20.10 or later: replace `podman` with `docker` in every command.
- Internet access for Part 1. Steps 3, 5 (the direct query), 8 and 9 talk to servers other than your network's own resolver, so they fail on networks that only allow DNS to their own resolver; see Troubleshooting.
- About 75 MB of disk space for the CoreDNS image.
- [The DNS lesson](lesson.md) of this module.

> [!WARNING]
> Part 1 sends ordinary lookups for public names to public resolvers; that is normal DNS use. Don't go beyond it: no zone transfer (AXFR) attempts, floods, scans or "open resolver" tests against servers you don't own. Part 2 runs a server bound to `127.0.0.1` only, so nothing outside your machine can reach it, and the only zone transfer you try is against that server. The lab is free and changes nothing on your system outside one folder and one container image, both removed at the end.

> [!NOTE]
> The outputs below were captured in November 2026. Addresses, TTLs, name servers and signatures of real domains (such as `example.com`, which IANA hosts with a commercial DNS provider) change over time, so yours will differ. The structure, flags and status codes are what you should compare. Your own zone uses documentation addresses only (RFC 5737 and RFC 3849).

## Architecture
<figure class="diagram" style="--dg-w: 1080px"><svg xmlns="http://www.w3.org/2000/svg" class="dg" viewBox="0 0 1080 440" width="1080" height="440" role="img" aria-labelledby="dns-lab-architecture-title dns-lab-architecture-desc" font-family="Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif" xml:lang="en">
<title id="dns-lab-architecture-title">Lab architecture: dig queries public resolvers and a local CoreDNS container</title>
<desc id="dns-lab-architecture-desc">Your computer runs dig in a terminal. In part 1, dig queries public resolvers such as 1.1.1.1, 9.9.9.9 and 8.8.8.8, or the system resolver, over UDP or TCP port 53, TLS port 853 or HTTPS port 443; the resolvers make iterative queries to the DNS hierarchy: the root, com and example.com. In part 2, dig queries a Podman container named dns-lab on 127.0.0.1 port 5300, which is mapped to port 53 inside the container, where CoreDNS 1.12.0 is authoritative for the zone lab.example. The Corefile and the zone file db.lab.example live in the folder ~/dns-lab, mounted read-only into the container.</desc>
<rect class="dg-bg" x="0.5" y="0.5" width="1079" height="439" rx="16" fill="#ffffff" stroke="#e3e3dd"/>
<g class="dg-l2"><rect class="dg-tint" x="20" y="20" width="640" height="400" rx="16" fill="#f1f7f3" stroke="#a1ccb1" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(36 33) scale(0.7500)" fill="none" stroke="#15803d" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g>
<text x="62" y="47" font-size="13" class="dg-ink" fill="#15803d" font-weight="700">Your computer</text></g>
<g class="dg-l1"><rect class="dg-tint" x="680" y="20" width="380" height="400" rx="16" fill="#f0f6f9" stroke="#9ac3d9" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(696 33) scale(0.7500)" fill="none" stroke="#0369a1" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g>
<text x="722" y="47" font-size="13" class="dg-ink" fill="#0369a1" font-weight="700">Internet</text></g>
<g class="dg-l7"><rect class="dg-tint" x="40" y="232" width="600" height="172" rx="16" fill="#f6f2fd" stroke="#c5a9f0" stroke-width="1.2" stroke-dasharray="6 5"/>
<g class="dg-icon" transform="translate(56 245) scale(0.7500)" fill="none" stroke="#6d28d9" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"/><path d="m3.3 7 8.7 5 8.7-5"/><path d="M12 22V12"/></g>
<text x="82" y="259" font-size="13" class="dg-ink" fill="#6d28d9" font-weight="700">Podman container: dns-lab</text></g>
<rect class="dg-card" x="44" y="64" width="260" height="112" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(60 80) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M20 16V7a2 2 0 0 0-2-2H6a2 2 0 0 0-2 2v9m16 0H4m16 0 1.28 2.55a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45L4 16"/></g>
<text x="102" y="101" font-size="15" class="dg-text" fill="#17171c" font-weight="700">dig</text>
<text x="62" y="132" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">dig @&lt;server&gt; &lt;name&gt;</text>
<text x="62" y="152" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">your terminal</text>
<rect class="dg-card" x="60" y="278" width="280" height="112" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l7"><g class="dg-icon" transform="translate(76 294) scale(1.2500)" fill="none" stroke="#6d28d9" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 6h16"/><path d="M4 12h10"/><path d="M4 18h6"/><circle cx="18" cy="16" r="3"/><path d="m22 20-1.8-1.8"/></g></g>
<g class="dg-l7"><text x="118" y="315" font-size="15" class="dg-ink" fill="#6d28d9" font-weight="700">CoreDNS 1.12.0</text></g>
<text x="78" y="346" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">authoritative: lab.example</text>
<text x="78" y="366" font-size="12.5" class="dg-muted" fill="#5c5c68" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">listens on :53 udp/tcp</text>
<rect class="dg-card" x="392" y="278" width="230" height="112" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(408 294) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"/><path d="M14 2v4a2 2 0 0 0 2 2h4"/><path d="M10 9H8"/><path d="M16 13H8"/><path d="M16 17H8"/></g>
<text x="450" y="315" font-size="15" class="dg-text" fill="#17171c" font-weight="700">~/dns-lab</text>
<text x="410" y="346" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">Corefile</text>
<text x="410" y="366" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">db.lab.example</text>
<rect class="dg-card" x="700" y="64" width="340" height="112" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-l1"><g class="dg-icon" transform="translate(716 80) scale(1.2500)" fill="none" stroke="#0369a1" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M4 6h16"/><path d="M4 12h10"/><path d="M4 18h6"/><circle cx="18" cy="16" r="3"/><path d="m22 20-1.8-1.8"/></g></g>
<g class="dg-l1"><text x="758" y="101" font-size="15" class="dg-ink" fill="#0369a1" font-weight="700">Public resolvers</text></g>
<text x="718" y="132" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">1.1.1.1 · 9.9.9.9 · 8.8.8.8</text>
<text x="718" y="152" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">or your system resolver</text>
<rect class="dg-card" x="700" y="292" width="340" height="112" rx="12" fill="#ffffff" stroke="#cfcfc8"/>
<g class="dg-icon-neutral" transform="translate(716 308) scale(1.2500)" fill="none" stroke="#17171c" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/></g>
<text x="758" y="329" font-size="15" class="dg-text" fill="#17171c" font-weight="700">DNS hierarchy</text>
<text x="718" y="360" font-size="12.5" class="dg-text" fill="#17171c" font-weight="500" font-family="JetBrains Mono, ui-monospace, Menlo, Consolas, monospace">root → com. → example.com.</text>
<text x="718" y="380" font-size="13" class="dg-muted" fill="#5c5c68" font-weight="500">and other real zones</text>
<g class="dg-l1"><path class="dg-stroke" d="M306 110H692" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M687 104l8 6-8 6" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><rect class="dg-bg-plain" x="362.2" y="98" width="275.6" height="24" rx="12" fill="#ffffff"/><text x="500" y="114.5" font-size="11.5" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle">Part 1: UDP/TCP 53 · TLS 853 · HTTPS 443</text></g>
<g class="dg-l1"><path class="dg-stroke" d="M870 178V284" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><path class="dg-stroke" d="M864 279l6 8 6-8" stroke="#0369a1" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l1"><rect class="dg-bg-plain" x="806.26" y="219" width="127.48" height="24" rx="12" fill="#ffffff"/><text x="870" y="235.5" font-size="11.5" class="dg-ink" fill="#0369a1" font-weight="600" text-anchor="middle">iterative queries</text></g>
<g class="dg-l7"><path class="dg-stroke" d="M290 178V270" stroke="#6d28d9" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l7"><path class="dg-stroke" d="M284 265l6 8 6-8" stroke="#6d28d9" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/></g>
<g class="dg-l7"><rect class="dg-bg-plain" x="310.84" y="192" width="198.32" height="24" rx="12" fill="#ffffff"/><text x="410" y="208.5" font-size="11.5" class="dg-ink" fill="#6d28d9" font-weight="600" text-anchor="middle">Part 2: 127.0.0.1:5300 → :53</text></g>
<path class="dg-line" d="M390 352H346" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-dasharray="7 6"/>
<path class="dg-line" d="M353 346l-8 6 8 6" stroke="#cfcfc8" stroke-width="2.5" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
</svg></figure>

*Figure 1. Part 1 talks to the real DNS through resolvers; Part 2 talks to your own authoritative server on `127.0.0.1:5300`.*

Port 5300 is used because port 53 needs administrator rights and is usually taken by your system's resolver, and port 5353 is used by multicast DNS (mDNS, for example Avahi or Bonjour).

## Steps

### Step 1 — Check your tools and create a working folder
Confirm the versions first: `+tls` and `+https` need BIND 9.18 or later. You'll keep the zone files in one folder, so cleanup is easy.

```bash
dig -v
podman --version
mkdir -p ~/dns-lab && cd ~/dns-lab
```

> [!WARNING]
> Run every following command from `~/dns-lab`. Step 11 mounts the current folder into the container with `:Z`, which relabels it for SELinux; run from your home folder, it would relabel and expose all of it.

Expected output (versions may be newer):
```text
DiG 9.18.50
podman version 5.8.7
```

Check that nothing already listens on port 5300 (Linux):
```bash
ss -lntu | grep ':5300 ' || echo "port 5300 is free"
```

Expected output:
```text
port 5300 is free
```

If something is listed, pick another high port (for example 5301) and use it everywhere this lab says `5300`. On macOS, use `lsof -nP -i :5300` instead; no output means the port is free.

## Part 1 — The real DNS, read-only

### Step 2 — Your first lookup, read in full
Start with a plain query to your system's resolver and read every section, as in Figure 2 of the lesson.

```bash
dig example.com
```

Expected output:
```text
; <<>> DiG 9.18.50 <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46107
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;example.com.			IN	A

;; ANSWER SECTION:
example.com.		176	IN	A	104.20.23.154
example.com.		176	IN	A	172.66.147.243

;; Query time: 2 msec
;; SERVER: 127.0.0.53#53(127.0.0.53) (UDP)
;; WHEN: Fri Nov 06 22:12:34 CET 2026
;; MSG SIZE  rcvd: 72
```

Write down, in your notes:
- **Status** `NOERROR` and flags `qr rd ra`: a response (`qr`), you asked for recursion (`rd`), and the server offers it (`ra`). There is no `aa`: a resolver answered, not the authoritative server. There is no `ad` either: this resolver didn't report DNSSEC validation.
- **Answer**: two A records (an RRset), each with name, TTL, class `IN`, type and address.
- **SERVER**: which resolver answered and over which transport. `127.0.0.53` is the local stub of systemd-resolved on many Linux systems; yours may be your router's or your ISP's address. The large `udp: 65494` comes from that local stub; real resolvers usually advertise 1232.

### Step 3 — Follow the delegation from the root
`+trace` makes `dig` itself do what a recursive resolver does: ask the root, follow each referral, and finish at the authoritative servers.

```bash
dig +trace example.com
```

Expected output (long `RRSIG` signature lines shortened to `…`):
```text
.			22378	IN	NS	a.root-servers.net.
.			22378	IN	NS	b.root-servers.net.
...
.			22378	IN	NS	m.root-servers.net.
.			23505	IN	RRSIG	NS 8 0 518400 20261119170000 20261106160000 8763 . …
;; Received 1037 bytes from 127.0.0.53#53(127.0.0.53) in 3 ms

com.			172800	IN	NS	a.gtld-servers.net.
...
com.			172800	IN	NS	m.gtld-servers.net.
com.			86400	IN	DS	19718 13 2 8ACBB0CD28F41250A80A491389424D341522D946B0DA0C0291F2D3D7 71D7805A
com.			86400	IN	RRSIG	DS 8 1 86400 20261119170000 20261106160000 8763 . …
;; Received 1171 bytes from 2801:1b8:10::b#53(b.root-servers.net) in 77 ms

example.com.		172800	IN	NS	hera.ns.cloudflare.com.
example.com.		172800	IN	NS	elliott.ns.cloudflare.com.
example.com.		86400	IN	DS	2371 13 2 C988EC423E3880EB8DD8A46FE06CA230EE23F35B578D64E78B29C3E1 C83D245A
example.com.		86400	IN	RRSIG	DS 13 2 86400 20261113013408 20261106002408 65344 com. …
;; Received 506 bytes from 2001:503:d2d::30#53(k.gtld-servers.net) in 37 ms

example.com.		300	IN	A	172.66.147.243
example.com.		300	IN	A	104.20.23.154
example.com.		300	IN	RRSIG	A 13 2 300 20261107221240 20261105201240 34505 example.com. …
;; Received 179 bytes from 2606:4700:50::adf5:3aa2#53(hera.ns.cloudflare.com) in 3 ms
```

Match each block to Figure 5 of the lesson:
1. Your resolver supplies the 13 root server names, `a` to `m` (like the root hints).
2. A root server (`b.root-servers.net` here) refers you to the 13 `com` servers. It also sends a **DS** record for `com`: the DNSSEC link from the root to `com`.
3. A `com` server refers you to the `example.com` name servers, with a DS record for `example.com`.
4. One of those servers answers with the A records. Its TTL is the full value, 300, because this is the authoritative copy, not a cached one.

Note the name servers `example.com` uses today; you'll need one of them in Step 5.

### Step 4 — Meet the record types
Ask for different types of data. `+noall +answer` hides everything except the answer section.

```bash
dig example.com AAAA +noall +answer
dig example.com NS +noall +answer
dig example.com SOA +noall +answer
dig example.com MX +noall +answer
dig example.com TXT +noall +answer
```

Expected output:
```text
example.com.		70	IN	AAAA	2606:4700:10::6814:179a
example.com.		70	IN	AAAA	2606:4700:10::ac42:93f3
example.com.		25054	IN	NS	elliott.ns.cloudflare.com.
example.com.		25054	IN	NS	hera.ns.cloudflare.com.
example.com.		1800	IN	SOA	elliott.ns.cloudflare.com. dns.cloudflare.com. 2418004112 10000 2400 604800 1800
example.com.		300	IN	MX	0 .
example.com.		300	IN	TXT	"v=spf1 -all"
example.com.		300	IN	TXT	"_k2n1y4vw3qtb4skdx9e7dxt97qrmmq9"
```

Read them against the lesson's record table:
- **AAAA**: the IPv6 addresses.
- **NS**: the authoritative servers, as in Step 3.
- **SOA**: primary server, contact mailbox (`dns@cloudflare.com`, with the `@` written as a dot), serial `2418004112`, then refresh, retry, expire and minimum (negative-caching TTL, 1800 s).
- **MX `0 .`** is a **null MX** (RFC 7505): `example.com` accepts no email. TXT `v=spf1 -all` adds that no server may send mail for it. Together, they protect a domain that should never send or receive email from being used for spoofed mail.
- The second TXT string is a typical domain-ownership token.

Now a **CNAME** and a **CAA** record, on well-known domains:

```bash
dig www.wikipedia.org +noall +answer
dig wikipedia.org CAA +noall +answer
```

Expected output:
```text
www.wikipedia.org.	17574	IN	CNAME	dyna.wikimedia.org.
dyna.wikimedia.org.	109	IN	A	185.15.58.224
wikipedia.org.		600	IN	CAA	0 iodef "mailto:dns-admin@wikimedia.org"
wikipedia.org.		600	IN	CAA	0 issue "pki.goog"
wikipedia.org.		600	IN	CAA	0 issue "letsencrypt.org"
```

The resolver followed the CNAME for you and returned the whole chain: alias first, then the A record of the target. Each record has its own TTL. The CAA records allow two CAs to issue certificates (`issue`) and give a contact for reports (`iodef`). The A address depends on where you are: large sites answer with a nearby data centre.

### Step 5 — Cached versus authoritative answers
Ask your resolver twice, about 10 seconds apart, and watch the TTL.

```bash
dig www.ietf.org +noall +answer; sleep 10; dig www.ietf.org +noall +answer
```

Expected output:
```text
www.ietf.org.		28	IN	A	104.16.45.99
www.ietf.org.		28	IN	A	104.16.44.99
www.ietf.org.		17	IN	A	104.16.44.99
www.ietf.org.		17	IN	A	104.16.45.99
```

The TTL went down by about the time that passed: both answers came from the same cached copy. When it reaches 0, the resolver fetches a fresh copy and the TTL jumps back to the zone's value. (The order of records in an RRset can change between answers; it carries no meaning.)

> [!TIP]
> If you try this against a large public resolver such as `1.1.1.1`, the TTL may jump around instead of counting down smoothly: anycast and load balancing can send your two queries to different caches.

Now ask one of the authoritative servers you noted in Step 3 directly, with recursion turned off:

```bash
dig @<ns> example.com +norec
```

`<ns>` is one of the `example.com` name servers from Step 3, for example `hera.ns.cloudflare.com`.

Expected output (header and answer):
```text
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40469
;; flags: qr aa; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
...
;; ANSWER SECTION:
example.com.		300	IN	A	172.66.147.243
example.com.		300	IN	A	104.20.23.154
```

`aa` is set and `ra` is not: an authoritative server, which doesn't do recursion for you. Run it again: the TTL stays at 300, because the server owns the data instead of caching it.

### Step 6 — A name that doesn't exist
Negative answers carry information too.

```bash
dig nonexistent.iana.org
```

Expected output (from the header to the authority section):
```text
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 4050
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;nonexistent.iana.org.		IN	A

;; AUTHORITY SECTION:
iana.org.		3600	IN	SOA	sns.dns.icann.org. noc.dns.icann.org. 2026110301 7200 3600 1209600 3600
```

`NXDOMAIN` with an empty answer, and the zone's SOA in the authority section. The resolver caches this "doesn't exist" for the smaller of the SOA's TTL and its last field (both 3600 here): negative caching, RFC 2308. This output came from a validating resolver, so it also carries `ad`: the non-existence itself was proven with DNSSEC.

> [!NOTE]
> Some DNS providers answer queries for non-existent names in signed zones with `NOERROR` and an empty answer instead of `NXDOMAIN` (a technique to make DNSSEC denial answers smaller). If you try other domains and see that, it's the provider's choice, not a mistake on your side.

### Step 7 — Reverse lookups
`-x` builds the reverse name under `in-addr.arpa` or `ip6.arpa` for you and asks for its PTR record.

```bash
dig -x 8.8.8.8 +noall +question +answer
dig -x 2001:4860:4860::8888 +short
```

Expected output:
```text
;8.8.8.8.in-addr.arpa.		IN	PTR
8.8.8.8.in-addr.arpa.	17593	IN	PTR	dns.google.
dns.google.
```

The question shows the reversed address. For the IPv6 address, `dig` writes all 32 hexadecimal digits backwards, one label each, under `ip6.arpa`; add `+noall +answer` instead of `+short` to see that name.

### Step 8 — Transports: UDP, TCP, TLS, HTTPS
Send the same query over each transport and read the `SERVER` line. `1.1.1.1` is used because it supports all four; any resolver that offers DoT and DoH would work.

```bash
dig @1.1.1.1 example.com +noall +answer +stats | grep SERVER
dig @1.1.1.1 example.com +tcp +noall +answer +stats | grep SERVER
dig @1.1.1.1 example.com +tls +noall +answer +stats | grep SERVER
dig @1.1.1.1 example.com +https +noall +answer +stats | grep SERVER
```

Expected output:
```text
;; SERVER: 1.1.1.1#53(1.1.1.1) (UDP)
;; SERVER: 1.1.1.1#53(1.1.1.1) (TCP)
;; SERVER: 1.1.1.1#853(1.1.1.1) (TLS)
;; SERVER: 1.1.1.1#443(1.1.1.1) (HTTPS)
```

Same question, same answer, four transports: port 53 over UDP and TCP (plaintext), 853 for DNS over TLS, 443 for DNS over HTTPS.

Now see **truncation**. The root zone's key set with signatures is about 1,100 bytes. Pretend your client can only receive 512 bytes over UDP, and tell `dig` not to retry (`+ignore`):

```bash
dig @1.1.1.1 . DNSKEY +dnssec +bufsize=512 +ignore | grep -E 'flags|SERVER'
```

Expected output:
```text
;; flags: qr tc rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
; EDNS: version: 0, flags: do; udp: 1232
;; SERVER: 1.1.1.1#53(1.1.1.1) (UDP)
```

`tc` is set and the answer is empty. Run it again without `+ignore`:

```bash
dig @1.1.1.1 . DNSKEY +dnssec +bufsize=512 | grep -E 'Truncated|flags:|SERVER|MSG'
```

Expected output:
```text
;; Truncated, retrying in TCP mode.
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1
;; SERVER: 1.1.1.1#53(1.1.1.1) (TCP)
;; MSG SIZE  rcvd: 1139
```

This is why TCP 53 must never be blocked: large answers, such as signed ones, depend on it.

### Step 9 — DNSSEC: validated, and failed on purpose
Ask a validating resolver for signed data and look for `ad`:

```bash
dig @1.1.1.1 example.com +dnssec +noall +comments | grep flags
```

Expected output:
```text
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
; EDNS: version: 0, flags: do; udp: 1232
```

`ad`: the resolver validated the chain of trust. The third answer record is the RRSIG signature (add `+answer` to see it).

`dnssec-failed.org` is a test domain whose operator deliberately keeps its DNSSEC broken so people can see what happens. Query it normally, then with checking disabled (`+cd`):

```bash
dig @1.1.1.1 dnssec-failed.org | grep status
dig @1.1.1.1 dnssec-failed.org +cd | grep -E 'status|flags:|EDE'
```

Expected output:
```text
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 26914
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18406
;; flags: qr rd ra cd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
; EDNS: version: 0, flags:; udp: 1232
; EDE: 9 (DNSKEY Missing): (no SEP matching the DS found for dnssec-failed.org.)
```

The validating resolver refuses the bogus data with `SERVFAIL`. With `+cd` you get the data anyway, without `ad`, and an Extended DNS Error (EDE, RFC 8914) explains why validation failed: the key in the zone doesn't match the DS record in the parent. Note that everything you saw in this step travelled in plaintext: DNSSEC proves authenticity, not confidentiality.

## Part 2 — Your own authoritative server

### Step 10 — Write the zone file and the server configuration
An authoritative server needs two things: the zone data and a configuration that says which zone to serve. You'll use **CoreDNS**, a small open-source DNS server, with its `file` plugin. The zone `lab.example` is safe to use: the `example` TLD is reserved for documentation (RFC 2606) and never exists on the Internet.

Create the zone file in `~/dns-lab`:

```bash
cat > db.lab.example <<'EOF'
$ORIGIN lab.example.
$TTL 300
@       IN  SOA   ns1.lab.example. hostmaster.lab.example. (
                  2026110601 ; serial (YYYYMMDDnn)
                  3600       ; refresh
                  600        ; retry
                  604800     ; expire
                  60 )       ; minimum: negative-caching TTL
        IN  NS    ns1.lab.example.
        IN  MX    10 mail.lab.example.
        IN  TXT   "v=spf1 mx -all"
        IN  CAA   0 issue "ca.example.net"
ns1     IN  A     192.0.2.53
www     IN  A     192.0.2.10
www     IN  AAAA  2001:db8::10
mail    IN  A     192.0.2.25
app     IN  CNAME www.lab.example.
EOF
```

Then the CoreDNS configuration, the `Corefile`:

```bash
cat > Corefile <<'EOF'
lab.example {
    file /etc/coredns/db.lab.example {
        reload 10s
    }
    log
    errors
}
EOF
```

It says: for names in `lab.example`, answer from the zone file; check the file every 10 seconds for a new serial; log every query. Names outside `lab.example` are refused: this is an authoritative-only server, not a resolver.

No output is expected. `ls` should show `Corefile` and `db.lab.example`.

### Step 11 — Start the server in a container
Run CoreDNS with your folder mounted read-only and port 53 of the container published on `127.0.0.1:5300`, for both UDP and TCP.

```bash
podman run -d --name dns-lab \
  -p 127.0.0.1:5300:53/udp -p 127.0.0.1:5300:53/tcp \
  -v "$PWD":/etc/coredns:ro,Z \
  docker.io/coredns/coredns:1.12.0 -conf /etc/coredns/Corefile
```

- `-p 127.0.0.1:5300:53/udp` and `/tcp`: only your own machine can reach the server; DNS needs both protocols.
- `-v "$PWD":/etc/coredns:ro,Z`: mounts the current folder read-only. `Z` relabels it for SELinux (Fedora, RHEL); on systems without SELinux it does no harm, and you can drop it if your Docker version complains. The whole folder is mounted, not single files, so edits made by any text editor are seen inside the container.
- The image tag is pinned to `1.12.0` so the lab behaves the same for everyone.

Then check that it runs:
```bash
podman ps --filter name=dns-lab
podman logs dns-lab
```

Expected output (IDs differ):
```text
CONTAINER ID  IMAGE                             COMMAND               CREATED        STATUS        PORTS                                           NAMES
b0474e9d2db7  docker.io/coredns/coredns:1.12.0  -conf /etc/coredn...  2 seconds ago  Up 2 seconds  127.0.0.1:5300->53/tcp, 127.0.0.1:5300->53/udp  dns-lab
maxprocs: Leaving GOMAXPROCS=16: CPU quota undefined
lab.example.:53
CoreDNS-1.12.0
linux/amd64, go1.23.3, 51e11f1
```

`lab.example.:53` confirms the zone loaded and the server listens on port 53 inside the container.

### Step 12 — Query your zone
Ask your server directly. `-p 5300` sets the port; `+norec` because it isn't a resolver.

```bash
dig @127.0.0.1 -p 5300 www.lab.example +norec
```

Expected output (from the header to the server line):
```text
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 42732
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: ce837fc3bf088f64 (echoed)
;; QUESTION SECTION:
;www.lab.example.		IN	A

;; ANSWER SECTION:
www.lab.example.	300	IN	A	192.0.2.10

;; AUTHORITY SECTION:
lab.example.		300	IN	NS	ns1.lab.example.

;; Query time: 0 msec
;; SERVER: 127.0.0.1#5300(127.0.0.1) (UDP)
```

`aa`: you are now the authority. This server also lists the zone's NS record in the authority section. The `COOKIE` line is a DNS cookie (RFC 7873), a light protection against spoofed queries.

Now query each record type you published:

```bash
D="dig @127.0.0.1 -p 5300 +norec +noall +answer"
$D lab.example SOA
$D lab.example MX
$D lab.example TXT
$D lab.example CAA
$D www.lab.example AAAA
$D app.lab.example A
```

Expected output:
```text
lab.example.		300	IN	SOA	ns1.lab.example. hostmaster.lab.example. 2026110601 3600 600 604800 60
lab.example.		300	IN	MX	10 mail.lab.example.
lab.example.		300	IN	TXT	"v=spf1 mx -all"
lab.example.		300	IN	CAA	0 issue "ca.example.net"
www.lab.example.	300	IN	AAAA	2001:db8::10
app.lab.example.	300	IN	CNAME	www.lab.example.
www.lab.example.	300	IN	A	192.0.2.10
```

`D` is just a shell variable that saves typing. Every record has the zone's default TTL of 300 from `$TTL`. For `app`, the server followed the CNAME inside its own zone and added the target's A record.

Next, three answers that are not data:

```bash
dig @127.0.0.1 -p 5300 nope.lab.example +norec | grep -E 'status|SOA'
dig @127.0.0.1 -p 5300 www.example.com +norec | grep status
dig @127.0.0.1 -p 5300 lab.example AXFR
```

Expected output:
```text
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 32533
lab.example.		300	IN	SOA	ns1.lab.example. hostmaster.lab.example. 2026110601 3600 600 604800 60
;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 60198

; <<>> DiG 9.18.50 <<>> @127.0.0.1 -p 5300 lab.example AXFR
; (1 server found)
;; global options: +cmd
; Transfer failed.
```

- `NXDOMAIN` with your SOA. CoreDNS sends the SOA with its own TTL (300); per RFC 2308 a resolver caches the negative answer for the smaller of that TTL and the SOA's last field, so 60 seconds.
- `REFUSED` for `www.example.com`: your server isn't authoritative for it and doesn't recurse.
- The zone transfer fails because CoreDNS doesn't allow transfers unless you configure them (its `transfer` plugin). That's the safe default: only your own secondary servers should be able to copy a zone.

Finally, see the query log:
```bash
podman logs dns-lab 2>&1 | tail -3
```

Expected output (the client address depends on how Podman networking is set up on your machine):
```text
[INFO] <client-ip>:59919 - 48226 "A IN app.lab.example. udp 56 false 1232" NOERROR qr,aa 148 0.000053703s
[INFO] <client-ip>:38194 - 27721 "A IN nope.lab.example. udp 57 false 1232" NXDOMAIN qr,aa 118 0.000072779s
[INFO] <client-ip>:60166 - 21479 "AXFR IN lab.example. tcp 52 false 65535" - - 0 0.000022052s
```

Each line shows the client address and port, the message ID, the question, the transport (note `tcp` for the AXFR), the response code, the flags, the response size and the time taken. The refused `www.example.com` query isn't there: the `log` line in the `Corefile` applies only to the `lab.example` block.

### Step 13 — Change a record and watch the serial
You'll move `www` from `192.0.2.10` to `192.0.2.11`. First, change only the address and **don't** touch the serial. Open `db.lab.example` in a text editor and change the `www IN A` line, or on Linux:

```bash
sed -i 's/192\.0\.2\.10/192.0.2.11/' db.lab.example
grep '^www' db.lab.example
```

Expected output:
```text
www     IN  A     192.0.2.11
www     IN  AAAA  2001:db8::10
```

Wait at least 15 seconds (the `reload` interval is 10 s), then ask:

```bash
dig @127.0.0.1 -p 5300 www.lab.example +short
```

Expected output:
```text
192.0.2.10
```

Still the old address. CoreDNS (like secondary servers) only reloads a zone when the **serial** increases. Now raise the serial from `2026110601` to `2026110602`:

```bash
sed -i 's/2026110601 ; serial/2026110602 ; serial/' db.lab.example
```

Wait 15 seconds again and repeat the query and the log check:

```bash
dig @127.0.0.1 -p 5300 www.lab.example +short
dig @127.0.0.1 -p 5300 lab.example SOA +short
podman logs dns-lab 2>&1 | grep reloaded
```

Expected output:
```text
192.0.2.11
ns1.lab.example. hostmaster.lab.example. 2026110602 3600 600 604800 60
[INFO] plugin/file: Successfully reloaded zone "lab.example." in "/etc/coredns/db.lab.example" with 2026110602 SOA serial
```

The new address is live as soon as the serial goes up. On the real Internet, there would be one more delay: resolvers that cached the old A record keep returning it until its 300-second TTL runs out.

> [!NOTE]
> On macOS, `sed -i` needs an empty argument: `sed -i '' 's/…/…/' db.lab.example`. Or simply edit the file in any text editor.

## Verification
You have completed the lab if all of these are true:

| Check | Pass condition |
|---|---|
| Trace | In Step 3 you can name the server that answered at each level (root, `com`, `example.com`) and point to the DS records linking them. |
| Caching | In Step 5 the TTL from your resolver decreased between two queries, and the TTL from the authoritative server stayed the same with `aa` set. |
| Records | You identified A, AAAA, NS, SOA, MX (null MX), TXT, CNAME, CAA (Step 4) and PTR (Step 7) answers. |
| Transports | Step 8 showed `(UDP)`, `(TCP)`, `(TLS)` on port 853 and `(HTTPS)` on port 443, and a `tc` answer retried over TCP. |
| DNSSEC | Step 9 showed `ad` for `example.com` and `SERVFAIL` for `dnssec-failed.org`. |
| Your zone | `dig @127.0.0.1 -p 5300 www.lab.example +norec` shows `flags: qr aa` and, after Step 13, the address `192.0.2.11` with serial `2026110602`. |

## Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| `dig +trace` stops with `communications error … timed out` after the root list | Your network blocks outbound DNS to anything but its own resolver (common in companies, hotels and some home routers). | Skip Step 3 or run it on another network you're allowed to use; the rest of Part 1 goes through resolvers. |
| `+tls` or `+https` prints `Invalid option` | `dig` older than 9.18 (for example the one built into macOS) or built without DoH support. | Install a current BIND (`brew install bind`, or your Linux package) and check `dig -v`. |
| `+tls` or `+https` times out | The network blocks port 853, or filters DoH. | Note it as a finding: it's the trade-off from the lesson. Try another network you're allowed to use. |
| `podman run` fails with `address already in use` | Something already listens on `127.0.0.1:5300`. | Pick another port (for example 5301) in the `-p` options and in every `dig -p` command. |
| `dig @127.0.0.1 -p 5300 …` returns `connection refused` or times out | The container isn't running: an error in the `Corefile` or the zone file stops CoreDNS. | `podman logs dns-lab` shows the error and line number. Fix the file, then `podman rm -f dns-lab` and repeat Step 11. |
| `permission denied` reading `/etc/coredns/Corefile` in the logs | SELinux blocked the mounted folder. | Make sure the volume option includes `Z` (`:ro,Z`). |
| `REFUSED` for `www.lab.example` | The zone didn't load (for example, a typo in `$ORIGIN` or a missing final dot), so the server has no `lab.example` zone. | Check `podman logs dns-lab` and compare your zone file with Step 10. |
| A changed record doesn't appear | The serial wasn't increased, or less than 10 seconds passed. | Raise the serial and wait 15 seconds; look for `Successfully reloaded zone` in the logs. |
| `podman: command not found` | Podman isn't installed. | Install it from your distribution's packages, or use Docker and replace `podman` with `docker` in every command. |

## Challenge (optional)
Add a reverse zone for `192.0.2.0/24` to your server: a second `file` block in the `Corefile` for `2.0.192.in-addr.arpa`, and a zone file with an SOA, an NS and PTR records for `192.0.2.10`, `192.0.2.25` and `192.0.2.53`. Check it with `dig @127.0.0.1 -p 5300 -x 192.0.2.10 +norec`. Then lower the TTL of `www` to 60 seconds (remember the serial) and explain, in two sentences, why you would do that a day before a real migration.

## Cleanup
Stop and remove the container, remove the image, and delete the lab folder:

```bash
podman rm -f dns-lab
podman rmi docker.io/coredns/coredns:1.12.0
cd ~ && rm -r ~/dns-lab
```

Expected output (IDs differ):
```text
dns-lab
Untagged: docker.io/coredns/coredns:1.12.0
Deleted: 1cf5f116067c67da67f97bff78c4bbc76913f59057c18627b96facaced73ea0b
```

Check that nothing is left:
```bash
podman ps -a --filter name=dns-lab
podman images coredns/coredns
```

Both commands should print only their header lines. Part 1 created nothing to clean up; the records your resolver cached expire on their own.

## What you learned
- `dig +trace` shows the delegation chain: root referral to `com`, `com` referral to the domain's servers, and an authoritative answer, with DS records linking each level for DNSSEC.
- A resolver's TTL counts down because the answer comes from its cache; an authoritative server's TTL doesn't, and it sets `aa`.
- How to read each record type, including a null MX, a CNAME chain, CAA, SOA fields and PTR records under `in-addr.arpa` and `ip6.arpa`.
- The status codes NOERROR, NXDOMAIN (with SOA for negative caching), SERVFAIL (failed DNSSEC validation) and REFUSED.
- The same query works over UDP 53, TCP 53, TLS 853 and HTTPS 443, and a truncated (`tc`) UDP answer is retried over TCP.
- An authoritative server serves only its zones, refuses others, and should refuse zone transfers to strangers; zone changes take effect only when the SOA serial increases.