Chapter 7 · DNS & DHCPThe student-friendly guide + hands-on Kali labs

Chapter 7 · The student-friendly guide

DNS & DHCP

The two quiet helpers that make the Internet usable: DNS turns names you can remember into IP addresses, and DHCP hands every device an address the moment it joins.

Name resolutionDNS hierarchy Queries & cachingDHCP & DORA

Use ← → arrow keys, the dots below, or the ☰ menu to navigate. Switch to the Lab Guide up top.

The big picture

Two application-layer helpers

💡
Think of it like… moving into a new flat. DHCP is the landlord handing you keys and your flat number the instant you arrive. DNS is the phone book that turns a person’s name into the number you actually dial.
🔎
1

DNS — the Internet’s phone book

Translate www.google.com142.250.74.36. A distributed, hierarchical database of names. UDP port 53.

📮
2

DHCP — automatic addressing

Give a joining host an IP, mask, gateway & DNS server automatically. The four-step DORA handshake. UDP ports 67/68.

Part 1 · DNS

What is the Domain Name System?

A protocol that translates host names → IP addresses

Why: humans can’t remember IP addresses. DNS gives us human-readable names instead of numbers.

Defined by the RFCs

DNS was specified in RFC 1034 (concepts) and RFC 1035 (implementation). It’s one of the oldest and most essential Internet services.

🧑 you type
www.google.com
DNS lookup
🖥️ browser connects to
142.250.74.36

Part 1 · DNS

Where the name lives: a URL, dissected

https://www.example.com:443/path?q=1
scheme

https — the protocol to speak.

host / subdomain

www — a label inside the domain.

domain + TLD

example.com — what DNS resolves.

path / query

/path?q=1 — handled after connecting.

📌
DNS only resolves the name part (www.example.com). The scheme, port and path are used by the browser after the IP address is known.

Part 1 · DNS

Why DNS is distributed, not centralized

One giant DNS server for the whole planet would fail for four reasons:

💥

Single point of failure

One server down = the whole Internet loses name resolution.

🌊

Traffic volume

Every lookup on Earth hitting one box — impossible to serve.

🛠️

Maintenance & scaling

Updating and growing a single database becomes unmanageable.

🌍

Distance / geography

Wherever you put it, half the world is far away — high latency.

🧠
So instead: DNS is a hierarchy — authority is delegated down a tree and copies are spread worldwide. No single owner, no single failure.

Part 1 · DNS

A hierarchy of servers

🌐 Root servers — the top of the tree (“.”)
⌄ delegates to
🏷️ TLD servers — .com · .net · .org · .uk · .ae
⌄ delegates to
📇 Authoritative servers — hold the real records for a domain
⌄ answers
💻 Local / resolver — asks on your behalf & caches the answer
💡
Think of it like… a postal system: the root points to the country, the TLD to the city, and the authoritative server is the exact street address.

Part 1 · DNS · the hierarchy

Root servers

Top of the whole tree

A root server’s “zone” is the entire name space. It usually stores no domain records itself — it delegates, keeping references to the TLD servers and saying “ask them.”

Distributed worldwide

There are 13 root server identities (A–M), each mirrored to hundreds of physical servers across the globe via anycast — so a root is always near you.

📌
Key idea: the root doesn’t know where google.com is — it only knows who is in charge of .com. Delegation, not answers.

Part 1 · DNS · the hierarchy

TLD (Top-Level Domain) servers

Each TLD server tracks the authoritative servers registered under its extension.

Generic TLDs (gTLD)

.com, .net, .org… managed by large IT organisations. e.g. .com & .net are run by VeriSign.

Country TLDs (ccTLD)

.uk, .us, .es, .ae… usually managed by that country’s telecom / registry authority.

💡
Think of it like… the .com TLD server is the “.com directory desk” — it doesn’t hold google’s address, it tells you which authoritative server does.

Part 1 · DNS · the hierarchy

Authoritative servers

The source of truth

An authoritative server maintains and provides the actual DNS records for one or more domains — the real IP addresses of that organisation’s servers.

Who asks it?

When any client — inside or outside the network — needs to reach one of the organisation’s servers, it ultimately gets that server’s IP from the authoritative server.

Root
“ask .com”
TLD (.com)
“ask google’s NS”
Authoritative
“it’s 142.250.74.36”

Part 1 · DNS

The domain name space

A domain = a subtree

The whole name space is an inverted tree. A domain is any subtree of it; the domain’s name is the name of the node at the top of that subtree.

Read it right-to-left

www.example.com.

The trailing . is the root. Then TLD (com) → domain (example) → host (www). Fully written, that’s an FQDN.

🧠
Memory hook: DNS names are read right → left, from the most general (root/TLD) to the most specific (host).

Part 1 · DNS

DNS records: what the server stores

RecordMaps…Example
Aname → IPv4 addressexample.com → 93.184.216.34
AAAAname → IPv6 addressexample.com → 2606:2800:220:1::
CNAMEalias → canonical namewww → example.com
MXdomain → mail server (+ priority)10 mail.example.com
NSzone → its authoritative name serverns1.example.com
PTRIP → name (reverse lookup)34.216.184.93.in-addr.arpa
TXTarbitrary text (SPF, DKIM, verification)"v=spf1 -all"

Self-Test #1

DNS — structure & records

Tap a green answer to reveal it.

Q Why is DNS built as a hierarchy instead of one central server?
A To avoid a single point of failure, huge traffic on one box, hard scaling, and long distances — so authority is delegated and copies spread worldwide.
Q Which server type actually holds a domain’s real records?
A The authoritative server (root & TLD only delegate).
Q Which record maps a name to an IPv4 address? To a mail server?
A A record → IPv4; MX record → mail server.
Q In www.example.com, which part is the TLD?
A com — read right-to-left, it sits just below the root.

Part 1 · DNS · resolution

Resolving a name: two query styles

Iterative

Each server it asks replies “I don’t know — but ask this server”, handing back a referral. The local resolver chases the chain itself: root → TLD → authoritative.

Recursive

Each server keeps the session open and asks the next one on your behalf, passing the final answer back down the chain.

DNS runs over UDP, port 53. Small, fast, connectionless queries — perfect for a quick question-and-answer (large replies / zone transfers fall back to TCP 53).

Part 1 · DNS · resolution

Iterative query — the resolver does the walking

Client
Local resolver

…then the resolver asks each level and gets a referral back each time:

Resolver
Root
“ask .com”
TLD
“ask ns1”
Authoritative
the record
📌
The local resolver finally returns the record to the client and caches it, so the next client asking the same name is answered instantly.

Part 1 · DNS · resolution

Recursive query — each server asks the next

Sessions stay open; the request is passed up the tree and the answer flows back down the same chain.

Client
Local
Root
TLD
Auth

↩ the DNS record is forwarded back down: Auth → TLD → Root → Local → Client

💡
Iterative vs recursive: iterative = you get directions and drive there yourself; recursive = you send a courier who fetches it and brings it back.

Part 1 · DNS · performance

Caching & TTL: fast, but watch staleness

Caching speeds things up

When a resolver learns a mapping, it stores it in its cache. The next matching query is answered from cache — no full walk of the tree. Cached answers are marked unauthoritative.

TTL stops staleness

Each record carries a Time To Live (seconds). After it expires, the cache entry is invalid and the resolver must ask the authoritative server again.

The trade-off: a long TTL means fewer lookups but slower propagation of changes; a short TTL updates fast but costs more queries. Admins tune TTL before a migration.

Part 1 · DNS · tools

Querying DNS yourself

nslookup

On UNIX & Windows, retrieves a name↔address mapping.

nslookup www.google.com

dig

Far more detail: record type, TTL, the authority chain and the query time.

dig www.google.com
🧪
Try it live: the Lab Guide (top-right) walks you through dig, nslookup, dig +trace (the whole hierarchy) and watching DNS on the wire with tcpdump.

Self-Test #2

DNS — queries & caching

Tap a green answer to reveal it.

Q Which transport protocol and port does DNS normally use?
A UDP, port 53 (TCP 53 for large replies / zone transfers).
Q In an iterative query, what does each server return if it doesn’t know the answer?
A A referral — “I don’t know, but ask this server” (the next level down).
Q What does TTL control, and why does it matter?
A How long a resolver may cache a record. Too long = stale answers after a change; too short = more queries.
Q A cached answer is flagged how, and why?
A Unauthoritative — to signal it came from cache, not directly from the authoritative server.

Part 2 · DHCP

Dynamic Host Configuration Protocol

A block of addresses gets assigned to an organisation — then someone has to hand them out to hosts. Doing it by hand is painful. DHCP does it automatically.

What it is

An application-layer protocol using the client-server model. It configures TCP/IP for a host: IP address, subnet mask, default gateway and DNS server.

Manual vs automatic

An admin could assign every address by hand. DHCP removes that work — and the typos — by leasing addresses on demand.

Part 2 · DHCP

Why DHCP is worth it

📌

Permanent addresses

Configure DHCP to always give the same host/router a fixed (reserved) IP.

Temporary leases

Hand out on-demand, time-limited addresses — e.g. a traveller’s laptop in a hotel.

♻️

Address reuse

Reclaim addresses when leases expire, so a small pool serves many devices.

💡
Oversubscription: an ISP with 1000 addresses can serve 4000 households — as long as no more than a quarter are online at once. Addresses are borrowed, not owned.

Part 2 · DHCP · operation

How a host gets an address: DORA

D
Discover
O
Offer
R
Request
A
Ack
StepWho → whoWhat happens
Discoverclient → broadcastJoining host broadcasts “any DHCP servers out there?” (only a random transaction-ID is set).
Offerserver → broadcastServer offers an IP (“your address”), its own server address, and a lease time.
Requestclient → broadcastClient picks the best offer and requests it (broadcast, so other servers know they lost).
Ackserver → broadcastServer confirms with DHCPACK (or DHCPNACK if the address is no longer free — client restarts).
🧠
Memory hook: DORA → Discover · Offer · Request · Ack. “DORA explores the network for an address.”

Part 2 · DHCP · operation

Ports, addresses & why it broadcasts

The DHCPDISCOVER packet

UDP  src port 68 → dst port 67
IP   src 0.0.0.0 → dst 255.255.255.255

Why those values?

The joining host has no address yet (so source = 0.0.0.0, “this host”) and doesn’t know the server (so destination = the 255.255.255.255 broadcast). Server replies use ports 67 → 68.

📌
Two well-known ports: 67 = server, 68 = client. Broadcasts throughout DORA let every DHCP server see who won and who lost each offer.

Part 2 · DHCP

Reliability, security & limits

🧮

Error control

DHCP rides on unreliable UDP, so it requires the UDP checksum, plus client timers + retransmission — with a random delay to avoid a stampede after a power cut.

🔓

Security problem

DHCP is unauthenticated — no credentials needed to get a lease. An attacker with access can exhaust the pool (starvation) — a denial of service.

📍

Limitations

Some machines (servers, routers) need fixed addresses. And the DHCP server must run continuously — it has to be up whenever a client needs an address.

🛡️
Defence: DHCP snooping on switches and port security limit rogue servers and starvation attacks — you’ll meet these ideas again in the Blue-Team track.

Self-Test #3

DHCP

Tap a green answer to reveal it.

Q Name the four DHCP messages, in order.
A Discover → Offer → Request → Ack (DORA).
Q What source & destination IP does a DHCPDISCOVER use, and why?
A Source 0.0.0.0 (no address yet), destination 255.255.255.255 (doesn’t know the server — broadcast).
Q Which UDP ports do the DHCP server and client use?
A Server = 67, client = 68.
Q Why is DHCP a security risk, and name one defence.
A It’s unauthenticated → pool-exhaustion / starvation DoS. Defence: DHCP snooping + switch port security.

One-page cheat sheet

Chapter 7 in a single glance

DNS = names → IPs

  • Translate host → IP address
  • RFC 1034 / 1035
  • Runs on UDP port 53

Hierarchy

  • Root → TLD → Authoritative
  • Distributed = no SPOF
  • Root/TLD delegate, don’t answer

Records

  • A / AAAA = IPv4 / IPv6
  • CNAME alias · MX mail
  • NS · PTR (reverse) · TXT

Queries

  • Iterative = referrals, resolver walks
  • Recursive = servers relay
  • Cache + TTL (unauthoritative)

DHCP = auto addressing

  • App-layer, client-server
  • DORA: Discover·Offer·Request·Ack
  • Ports: server 67, client 68

DHCP gotchas

  • Discover: 0.0.0.0 → 255.255.255.255
  • Unauthenticated → starvation DoS
  • Servers/routers need static IPs

Names resolved, addresses assigned.

DNS turns human names into IP addresses through a worldwide hierarchy; DHCP hands those addresses out automatically with the DORA handshake. Revise with the cheat sheet, test yourself with the quizzes — and you’re ready.

Next up → Chapter 8 · Transport Layer

Ready to make it real? Switch to the 🧪 Lab Guide up top and run these concepts on Kali Linux.

1 / 26

Chapter 7 · Hands-on labs

DNS & DHCP, live on Kali Linux

Six short labs that turn the slides into commands you actually run — resolve names, walk the DNS hierarchy, watch TTLs tick down, sniff DNS on the wire, and capture a real DHCP DORA handshake. Each maps to a Chapter 7 topic and ends by connecting what you saw back to the concept.

SET-UP  ·  Open the Kali Terminal. A couple of labs use two terminals (Terminal A & B — just open a second tab). Tools: dnsutils (dig, nslookup), tcpdump, nmap. If one is missing: sudo apt install -y dnsutils tcpdump nmap. The is just the prompt — the Copy button copies only the command.
USE RESPONSIBLY  ·  Only query, sniff, or send DHCP on networks you own or are permitted to test. The DHCP lab sends a real broadcast — do it on your own LAN or a lab network, never someone else’s.
1 · Resolve2 · Hierarchy3 · Caching & TTL 4 · DNS on the wire5 · DHCP DORA6 · Leases & reverse✓ Answers
1

Resolve Names — dig, nslookup & host

Maps to Ch.7:DNS — translating host names to IP addresses; DNS record types (A, AAAA, MX, NS). You’ll learn:Turn a name into an address, then pull the different record types the server stores. Tools:dig, nslookup, host
1

The basic lookup — name → IPv4 (the A record):

dig +short www.google.com A
Representative — your answer will differ
142.250.74.36
2

Other record types — IPv6, mail and name servers:

dig +short google.com AAAA
dig +short google.com MX
dig +short google.com NS
Representative
2607:f8b0:4004:c07::71
10 smtp.google.com
ns1.google.com  ns2.google.com ...
3

Same question, three tools. Compare their output styles:

nslookup www.google.com
host www.google.com
Why it works  ·  Every one of these asks your configured resolver a DNS question and prints the record it gets back — exactly the “names → IP addresses” job from the slides. dig shows the most detail.
Your turn  ·  Run dig example.com A and read the full output (no +short). Which record type is in the ANSWER section, and what is its TTL? (answer below)
2

Walk the Hierarchy — Root → TLD → Authoritative

Maps to Ch.7:The distributed, hierarchical database; root, TLD and authoritative servers; iterative resolution. You’ll learn:Watch a single name get resolved one level at a time, exactly like an iterative query. Tools:dig +trace
1

Trace the whole hierarchy — dig starts at the root and follows referrals down:

dig +trace www.google.com
Representative — trimmed
.            NS a.root-servers.net.      <- root
com.         NS a.gtld-servers.net.      <- TLD (.com)
google.com.  NS ns1.google.com.          <- authoritative
www.google.com. A 142.250.74.36          <- the answer

Each block is one level replying “I don’t know, but ask this server” — the referral chain from the slides, made visible.

2

Ask one specific level yourself — query a root server directly and watch it refer you to .com:

dig @a.root-servers.net www.google.com
Why it works  ·  +trace performs the iterative walk itself: root delegates to the TLD, the TLD delegates to the authoritative server, and only the authoritative server returns the real A record.
Your turn  ·  In the +trace output, which server type finally returns the A record — root, TLD, or authoritative? (answer below)
3

Caching & TTL in Action

Maps to Ch.7:Caching, TTL, and authoritative vs unauthoritative answers. You’ll learn:See a TTL counter tick down between two queries — proof the answer came from cache. Tools:dig, resolvectl / /etc/resolv.conf
1

Who is your resolver? The server that caches on your behalf:

cat /etc/resolv.conf
resolvectl status 2>/dev/null | grep -i "DNS Server" || true
2

Query twice, fast. Watch the TTL in the ANSWER section shrink the second time:

dig example.com | grep -A1 "ANSWER SECTION"
sleep 5
dig example.com | grep -A1 "ANSWER SECTION"
Representative — note the TTL drop
;; ANSWER SECTION:
example.com.   3600  IN  A  93.184.216.34
;; ANSWER SECTION:
example.com.   3595  IN  A  93.184.216.34

The TTL fell by ~5 seconds — the resolver is counting down the cached entry’s life. When it hits 0, the next query goes back to the authoritative server.

Why it works  ·  A decreasing TTL is the cache at work: the record is being served from memory, aging by the second, exactly as the “Caching & TTL” slide describes.
Your turn  ·  Query a name with dig and look at the flags: line. Is the aa (authoritative answer) flag set when you ask your local resolver? (answer below)
4

DNS on the Wire

Maps to Ch.7:DNS runs over UDP port 53 — the query/response exchange. You’ll learn:Capture the actual DNS packets and confirm the protocol, port and transaction. Tools:tcpdump, two terminals
1

Start the sniffer in Terminal A — watch UDP port 53:

sudo tcpdump -i any -n udp port 53
2

Trigger a lookup in Terminal B (use a fresh name so it isn’t already cached):

dig kali.org
Terminal A shows the query then the response
IP 192.168.1.23.51512 > 192.168.1.1.53:  A? kali.org.
IP 192.168.1.1.53 > 192.168.1.23.51512:  A kali.org. 192.124.249.13

One packet out to port 53 (the question), one packet back (the answer) — DNS is a quick UDP question-and-answer, just as the slide says.

Why it works  ·  You saw the destination port 53 and the A? query with its matching reply — the on-the-wire proof that DNS is a UDP/53 request-response protocol.
Your turn  ·  Run dig for the same name twice while tcpdump runs. Why do you see packets the first time but maybe not the second? (answer below)
5

Capture a Real DHCP DORA

Maps to Ch.7:DHCP operation — Discover, Offer, Request, Ack; ports 67/68; broadcast addressing. You’ll learn:Watch all four DORA messages cross the wire, and read the ports & broadcast addresses from the packets. Tools:tcpdump, nmap (broadcast-dhcp-discover), two terminals

You’ll send a DHCP Discover safely with nmap’s broadcast script and watch the whole exchange in tcpdump. Do this only on your own LAN / lab.

1

Start the sniffer in Terminal A — DHCP uses UDP ports 67 & 68:

sudo tcpdump -i any -n port 67 or port 68
2

Send a Discover in Terminal B (nmap builds and broadcasts it for you):

sudo nmap --script broadcast-dhcp-discover
nmap prints the server’s Offer
| broadcast-dhcp-discover:
|   IP Offered: 192.168.1.57
|   Server Identifier: 192.168.1.1
|   IP Address Lease Time: 1 day
|_  Router / DNS Servers: 192.168.1.1
Terminal A (tcpdump) shows DORA
IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from ...  Discover
IP 192.168.1.1.67 > 255.255.255.255.68: BOOTP/DHCP, Reply ...     Offer
IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request ...       Request
IP 192.168.1.1.67 > 255.255.255.255.68: BOOTP/DHCP, Reply ...     ACK

Read the packets: source 0.0.0.0 → destination 255.255.255.255, ports 68 → 67 (client → server) and 67 → 68 back — the exact values from the slides.

Why it works  ·  The client has no address yet, so it broadcasts from 0.0.0.0 to 255.255.255.255. You watched Discover · Offer · Request · Ack — the DORA handshake — happen for real.
Your turn  ·  From the capture, which port is the server on, and which is the client on? (answer below)
6

Your Lease & Reverse DNS

Maps to Ch.7:DHCP leases (address, lease time, gateway, DNS) + the DNS PTR (reverse) record. You’ll learn:Read the address DHCP actually gave you, then use DNS in reverse to turn an IP back into a name. Tools:ip, resolvectl, dig -x, lease files
1

What did DHCP give you? Your address, gateway and DNS server:

ip -br addr
ip route | grep default
resolvectl status 2>/dev/null | grep -i "DNS Server" || cat /etc/resolv.conf
2

Read the lease itself (path varies by client — try each):

cat /var/lib/dhcp/dhclient.leases 2>/dev/null
sudo grep -ri "lease\|dhcp" /var/lib/NetworkManager/ 2>/dev/null | head
Representative lease entry
lease {
  fixed-address 192.168.1.23;
  option routers 192.168.1.1;
  option dhcp-lease-time 86400;
  option domain-name-servers 192.168.1.1;
}
3

DNS in reverse — turn an IP back into a name with a PTR lookup:

dig -x 8.8.8.8 +short
Representative
dns.google.
Why it works  ·  DHCP handed you an address plus a gateway and DNS server (a lease with a lease-time), and dig -x uses a PTR record to map the IP back to a name — both chapter concepts, on your own machine.
Your turn  ·  Your lease shows dhcp-lease-time 86400. How long is that, and what must happen before it expires? (answer below)

Answer Key & Where Next

Lab 1. The ANSWER section holds an A record; the number before IN A (e.g. 3600) is its TTL in seconds — how long resolvers may cache it.

Lab 2. The authoritative server returns the real A record. The root and TLD servers only hand back referrals (NS records) pointing one level deeper.

Lab 3. No — when you ask your local resolver, the aa flag is not set: the answer is cached/relayed, i.e. unauthoritative. You’d only see aa when querying the authoritative server directly.

Lab 4. The first lookup isn’t cached, so it goes out over UDP/53 and you see both packets. The second is served from the resolver’s cache (while the TTL lasts), so no new query leaves — caching in action.

Lab 5. The server is on port 67, the client on port 68. Discover/Request go 68 → 67; Offer/Ack come back 67 → 68.

Lab 6. 86400 seconds = 24 hours. Before it expires the client must renew the lease (typically at ~50% of the lease time) or it loses the address.

This lab’s toolConnects to…
dig / nslookup (Labs 1–3)Chapter 2 — addressing & the resolver’s place in the stack
tcpdump on UDP/53 & 67/68 (Labs 4–5)Chapter 8 — UDP, the transport DNS & DHCP ride on
DHCP DORA & broadcast (Lab 5)Chapter 4 & the NSSA-241 capstone — configuring a DHCP server on a router
dig -x / PTR (Lab 6)Chapter 4 & 6 — IP addressing and the in-addr.arpa reverse zone
Nice work  ·  You’ve now seen every part of Chapter 7 at the terminal — resolution, the hierarchy, caching & TTL, DNS on the wire, and a real DHCP DORA handshake.
Chapter 7 — DNS & DHCP · Slides + Hands-On Kali Labs