22.8. Operating and Troubleshooting DNS and DHCP
The services built so far fail in recognizable patterns, and every pattern has a short diagnostic path. This section walks the ones worth rehearsing: blocked ports, conflicting listeners, packet captures, stale caches, bad delegations, exhausted pools, and backups that actually restore.
22.8.1. Firewall Rules and Conflicting Local Listeners
Every service in this chapter is a listening socket, and the firewall policy is a list of them. The complete exposure for the practice network:
| Host | Service | Port/protocol | Who should reach it |
|---|---|---|---|
resolver, ns2 (.54) |
Unbound | 53/tcp+udp | both LANs' clients |
| ns1, ns2 | BIND authoritative | 53/tcp+udp | resolvers; secondaries for transfer (tcp) |
| ns1, ns2 | Kea DHCPv4 | 67/udp | LAN clients (broadcast), the relay |
| ns1 | Kea DHCPv6 | 547/udp | LAN clients (multicast) |
| ns1, ns2 | kea-dhcp-ddns | 53001/udp on loopback | the local Kea servers only |
| ns1, ns2 | Kea HA peer channel | 8000/tcp | the other peer only |
| ns1 | radvd | ICMPv6, no port | LAN clients |
Chapter 18 built nftables rulesets; the practice network keeps its filtering minimal because the links are isolated, so this section's rule is a deliberate fault to recognize rather than the correct baseline. In a root shell on resolver, install a drop rule for LAN DNS traffic:
# nft add table inet ch22; nft 'add chain inet ch22 input { type filter hook input priority -10; policy accept; }'; nft add rule inet ch22 input ip saddr 192.168.232.0/24 udp dport 53 drop
The three commands are one ruleset: a table, an input chain at a slightly early priority, and a rule dropping UDP port 53 from the practice LAN. All three print nothing - nftables reports silence on success. From the client, DNS now hangs - on lanclient, as john:
$ dig @192.168.232.53 www.handbook.test A +time=2 +tries=1
;; communications error to 192.168.232.53#53: timed out
; <<>> DiG 9.20.30-1~deb13u1-Debian <<>> @192.168.232.53 www.handbook.test A +time=2 +tries=1
; (1 server found)
;; global options: +cmd
;; no servers could be reached
The signature of a dropped packet is time, not an error: the
query is never answered and never refused, so dig waits out its
own +time=2 +tries=1 bounds and reports no servers could be
reached. Compare the fast failures - REFUSED means the server
answered "no", SERVFAIL means it answered "couldn't" - and the
diagnosis is mechanical: timeout is a path problem (firewall,
routing, down host), refusal is a policy problem, SERVFAIL is a
resolution problem. A blocked port shows as the first. Remove the
table and recover:
# nft delete table inet ch22
Silent again, and the next query answers:
$ dig @192.168.232.53 www.handbook.test A +short
192.168.232.10
The other listen-on-port failure is a conflict: two daemons claiming the same socket. Reproduce it by starting a second Unbound while the service instance holds its ports - on resolver, as john. Selected output - two socket-buffer warnings omitted:
$ sudo unbound -d -c /etc/unbound/unbound.conf
[1795346376] unbound[13135:0] error: can't bind socket: Address already in use for 127.0.0.1 port 8953
[1795346376] unbound[13135:0] error: cannot open control interface 127.0.0.1 8953
[1795346376] unbound[13135:0] fatal error: could not open ports
Address already in use is the kernel refusing the bind, and the
message names the port: 8953 here because the running service
holds both 53 and its control port, and the control port is the
one the new process hit first. A conflicting service on port 53
produces the same message with port 53 - the classic culprits
on a fresh server being dnsmasq or systemd-resolved's stub
listener on 127.0.0.53 (Chapter 17
covered that stub). The diagnosis is one command from
Section 22.2.2 - ss -lunpt 'sport = :53' names the process
holding the port, and the fix is stopping whichever service
should not be there. The foreground Unbound above exits by
itself after its fatal error; nothing is left to clean up.
22.8.2. Following DNS Queries and DHCP Exchanges with Packet Captures
When logs and queries disagree with reality, the packet is the
court of last resort. tcpdump's working set:
| Option | Description |
|---|---|
-i iface |
capture on this interface |
-n |
do not resolve addresses to names - resolution would itself need DNS |
-c N |
stop after N packets, so bounded captures end themselves |
-w file |
write raw packets to a file for later reading |
-r file |
read a capture file back |
-vv |
verbose decoding, including DHCP option contents |
The capture tool is not installed by default; the same install serves both hosts this section captures on - as root on lanclient and on ns1:
# apt install tcpdump
Capture a DNS exchange from the client side. In a root shell on lanclient, start the capture writing into john's workspace (the full path, because the root shell's working directory is not the workspace):
# tcpdump -i eth1 -n -c 4 -w /home/john/debian-handbook/dns-dhcp/dns.pcap port 53
The capture runs silently until four packets or a Ctrl+C. In another session, trigger one query - on lanclient, as john:
$ dig @192.168.232.53 www.handbook.test A +short
192.168.232.10
Read the capture back - same host, as john, in the workspace:
$ tcpdump -r dns.pcap -n | head -6
reading from file dns.pcap, link-type EN10MB (Ethernet), snapshot length 262144
14:25:55.704388 IP 192.168.232.100.52261 > 192.168.232.53.53: 16347+ [1au] A? www.handbook.test. (58)
14:25:55.704876 IP 192.168.232.53.53 > 192.168.232.100.52261: 16347$ 1/0/1 A 192.168.232.10 (62)
Two packets, one exchange: the query A? www.handbook.test., sourced
from lanclient's leased address .100, carrying id 16347 and one
answer 1/0/1 A 192.168.232.10 carrying the same id - the
request/response pair, half a millisecond apart. The -n flag is what
keeps this readable - without it, tcpdump would try to resolve every
address through the very service being captured. The banner line is
the file's metadata, printed as it opens.
The same technique on the server side captures DHCP, whose broadcasts a client-side capture also sees but whose server-side view is the one that answers "did the server even receive it?". In a root shell on ns1, start a capture for the DHCP ports, writing into the workspace there:
# tcpdump -i eth1 -n -c 5 -w /home/john/debian-handbook/dns-dhcp/dhcp.pcap udp port 67 or udp port 68
Five packets this time: a release plus the four-message exchange. Trigger both from the client - on lanclient, as john:
$ sudo dhclient -r eth1
Removed stale PID file
The same pid-file bookkeeping as Section 22.6.3's release - the stale entry left by an earlier one-shot run is reported and discarded, and the release itself goes to the server (it is the first packet in the capture below). Then a fresh request:
$ sudo dhclient -1 eth1
Silent on success; the client rebinds. Read the capture - on ns1, as root:
# tcpdump -r /home/john/debian-handbook/dns-dhcp/dhcp.pcap -n | head -8
reading from file /home/john/debian-handbook/dns-dhcp/dhcp.pcap, link-type EN10MB (Ethernet), snapshot length 262144
11:34:00.444326 IP 192.168.232.100.68 > 192.168.232.10.67: BOOTP/DHCP, Request from 52:54:00:64:7a:37, length 300
11:34:01.522705 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 52:54:00:64:7a:37, length 300
11:34:01.523481 IP 192.168.232.10.67 > 192.168.232.100.68: BOOTP/DHCP, Reply, length 330
11:34:01.523919 IP 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 52:54:00:64:7a:37, length 300
11:34:01.524605 IP 192.168.232.10.67 > 192.168.232.100.68: BOOTP/DHCP, Reply, length 330
The default decoder labels every client-to-server packet "Request"
and every server-to-client packet "Reply" - the message type is
a DHCP option inside, and five packets map to the exchange:
unicast RELEASE from the configured address, broadcast DISCOVER
from 0.0.0.0, OFFER back, broadcast REQUEST, ACK. The same file, read
more verbosely, names the message types; the 2>/dev/null drops the
banner the plain readback printed, so only the decoded packets remain -
as root on ns1:
# tcpdump -r /home/john/debian-handbook/dns-dhcp/dhcp.pcap -n -vv 2>/dev/null | head -24
11:34:00.444326 IP (tos 0x0, ttl 64, id 45799, offset 0, flags [DF], proto UDP (17), length 328)
192.168.232.100.68 > 192.168.232.10.67: [bad udp cksum 0x5306 -> 0x0226!] BOOTP/DHCP, Request from 52:54:00:64:7a:37, length 300, xid 0x2dd6ae50, Flags [none] (0x0000)
Client-IP 192.168.232.100
Client-Ethernet-Address 52:54:00:64:7a:37
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message (53), length 1: Release
Server-ID (54), length 4: 192.168.232.10
Hostname (12), length 9: "lanclient"
11:34:01.522705 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
0.0.0.0.68 > 255.255.255.255.67: [udp sum ok] BOOTP/DHCP, Request from 52:54:00:64:7a:37, length 300, xid 0xa1bdbf6b, Flags [none] (0x0000)
Client-Ethernet-Address 52:54:00:64:7a:37
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message (53), length 1: Discover
Requested-IP (50), length 4: 192.168.232.100
Hostname (12), length 9: "lanclient"
Parameter-Request (55), length 7:
Subnet-Mask (1), BR (28), Time-Zone (2), Default-Gateway (3)
Domain-Name (15), Domain-Name-Server (6), Hostname (12)
11:34:01.523481 IP (tos 0x10, ttl 128, id 0, offset 0, flags [DF], proto UDP (17), length 358)
192.168.232.10.67 > 192.168.232.100.68: [udp sum ok] BOOTP/DHCP, Reply, length 330, xid 0xa1bdbf6b, Flags [none] (0x0000)
Your-IP 192.168.232.100
Client-Ethernet-Address 52:54:00:64:7a:37
Now the types are explicit: DHCP-Message (53), length 1:
Release, then Discover - and the DISCOVER even shows the
parameter request list, the client naming the options it wants
(subnet mask, gateway, domain name, resolvers, hostname), which
is Section 22.5.2's option table as it appears on the wire. The
head -24 cut the stream just as the third packet (the OFFER)
began decoding. The checksum warning on the release packet shows
the same placeholder value in every capture of this exchange,
while the lease messages themselves verify correctly ([udp sum
ok]) - a quirk of the client's raw-socket RELEASE path, not a
fault in the exchange. Both capture
files were written by a root shell into john's workspace, but
tcpdump drops savefile ownership to its own unprivileged user,
so the files are readable without being john's; removing them
needs write permission on the directory rather than file
ownership, which john has - when they have served their purpose,
rm ~/debian-handbook/dns-dhcp/*.pcap in john's shell cleans
up.
22.8.3. Stale Caches, Incorrect Delegation, and Exhausted Pools
Stale caches. A resolver serves what it cached until the TTL
runs out, which is correct behavior that looks exactly like a
broken server. The zone has a record built for this: cache
with a 30-second TTL. First look at what the resolver holds - on
lanclient, as john:
$ dig @192.168.232.53 cache.handbook.test A +short
192.168.232.10
Now change the record at its source, with an authenticated
update - as john on ns1, write
~/debian-handbook/dns-dhcp/cache-change.update:
server 127.0.0.1
zone handbook.test
update delete cache.handbook.test. A
update add cache.handbook.test. 30 A 192.168.232.60
send
Apply it as root on ns1:
# nsupdate -y hmac-sha256:ddns-key:Y2hhcHRlcjIyLWRkbnMta2V5LTAwMDEtYWJjZGVm < /home/john/debian-handbook/dns-dhcp/cache-change.update
Silent - applied. Ask the resolver again:
$ dig @192.168.232.53 cache.handbook.test A +short
192.168.232.10
Still the old address, and nothing is wrong: the authoritative server has the new record, but the resolver's cached copy has TTL time left, and DNS is a system designed to answer from cache. Flush the one name - on resolver, as root:
# unbound-control flush cache.handbook.test
ok
$ dig @192.168.232.53 cache.handbook.test A +short
192.168.232.60
The new address, immediately after the flush. The operational
lesson cuts both ways: after any deliberate record change, either
wait out the TTL (30 seconds here - this is why the record's TTL
is short) or flush the resolvers, and never "fix" a working
resolver that is serving old-but-unexpired data. Negative answers
cache the same way - the SOA's negative TTL governs how long a
name's nonexistence is remembered, which is the invisible
failure after removing a record and re-adding it quickly. Restore
the record with the same batch edited to add
192.168.232.10 back, applied as above.
Incorrect delegation. Section 22.4.3 broke the chain at its
most subtle link - a DS that matched nothing - and its diagnosis
generalizes to the whole delegation family: the parent's NS
records name servers that do not serve the zone (a lame
delegation), the glue disagrees with the zone's real addresses,
or the DS matches a key the child no longer publishes. The
diagnostic sequence is always the same three queries: ask the
parent for the delegation (dig @parent zone NS - do the
delegated servers look right?), ask each named server directly
(dig @server zone SOA - does each answer authoritatively?),
and ask through the resolver (dig @resolver zone A - does
validation accept the result?). A delegation that answers
directly but fails through the resolver is a DNSSEC chain
problem; one that fails everywhere is a delegation problem;
one that fails on a single named server is a broken secondary.
Exhausted pools. The last failure is the simplest: more clients than addresses. To make it observable without a hundred machines, shrink the pool to one address and take the HA peer out of the picture first - in a root shell on ns2:
# systemctl stop kea-dhcp4-server
Stopping the standby matters for the drill's honesty: with both
peers up, the failure would be masked by failover, which is the
design working rather than the pool problem. Now replace the
pool on ns1 - edit /etc/kea/kea-dhcp4.conf so subnet 1's pool
line reads:
# subnet 1's pool line in /etc/kea/kea-dhcp4.conf, shrunk to one address
"pools": [ { "pool": "192.168.232.200 - 192.168.232.200" } ],
One address, .200, outside every lease already granted.
Restart the service - as root on ns1:
# systemctl restart kea-dhcp4-server
Silent; the new configuration is live. The first new client gets the one address - two more identities on lanclient, root shell:
# ip link add link eth1 name mv3 address 52:54:00:22:00:07 type macvlan mode bridge
# ip link set mv3 up
$ sudo dhclient -1 -v mv3
Internet Systems Consortium DHCP Client 4.4.3-P1
Copyright 2004-2022 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/mv3/52:54:00:22:00:07
Sending on LPF/mv3/52:54:00:22:00:07
Sending on Socket/fallback
DHCPDISCOVER on mv3 to 255.255.255.255 port 67 interval 7
DHCPOFFER of 192.168.232.200 from 192.168.232.10
DHCPREQUEST for 192.168.232.200 on mv3 to 255.255.255.255 port 67
DHCPACK of 192.168.232.200 from 192.168.232.10
bound to 192.168.232.200 -- renewal in 258 seconds.
The pool's only address, granted. The second new client finds nothing - same host, one more identity:
# ip link add link eth1 name mv4 address 52:54:00:22:00:08 type macvlan mode bridge
# ip link set mv4 up
$ sudo dhclient -1 -v mv4
Internet Systems Consortium DHCP Client 4.4.3-P1
Copyright 2004-2022 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/mv4/52:54:00:22:00:08
Sending on LPF/mv4/52:54:00:22:00:08
Sending on Socket/fallback
DHCPDISCOVER on mv4 to 255.255.255.255 port 67 interval 8
DHCPDISCOVER on mv4 to 255.255.255.255 port 67 interval 17
DHCPDISCOVER on mv4 to 255.255.255.255 port 67 interval 14
DHCPDISCOVER on mv4 to 255.255.255.255 port 67 interval 9
DHCPDISCOVER on mv4 to 255.255.255.255 port 67 interval 12
No DHCPOFFERS received.
Unable to obtain a lease on first try. Exiting.
Five DISCOVERs, growing intervals, then the client gave up:
No DHCPOFFERS received. The client cannot tell "no server"
from "server with nothing left" - both look like silence. The
server knows, and its log says so - as root on ns1:
# grep ALLOC_ENGINE_V4_ALLOC_FAIL /var/log/kea/kea-dhcp4.log | tail -3
2026-11-22 11:18:53 WARN ALLOC_ENGINE_V4_ALLOC_FAIL_SUBNET [hwtype=1 52:54:00:22:00:08], cid=[no info], tid=0xca357364: failed to allocate an IPv4 lease in the subnet 192.168.232.0/24, subnet-id 1, shared network (none)
2026-11-22 11:18:53 WARN ALLOC_ENGINE_V4_ALLOC_FAIL [hwtype=1 52:54:00:22:00:08], cid=[no info], tid=0xca357364: failed to allocate an IPv4 address after 1 attempt(s)
2026-11-22 11:18:53 WARN ALLOC_ENGINE_V4_ALLOC_FAIL_CLASSES [hwtype=1 52:54:00:22:00:08], cid=[no info], tid=0xca357364: Failed to allocate an IPv4 address for client with classes: ALL, HA_ns1, UNKNOWN
Three WARN lines, one failed request: the allocation engine
reporting, per subnet and per client, that there was nothing to
give - the client's link address matches the silent exchanges
above, and the transaction id ties them together. This pair of
captures is the exhaustion signature: a client that sees
silence, a server log that says ALLOC_FAIL. Sizing the fix is
capacity arithmetic - the pool had one address and two clients -
and the operational habit is watching utilization before it
reaches the cliff: the lease CSV of Section 22.5.3 or
lease4-get-all on the control socket both give the count of
granted leases, which is the number to trend.
Recovery: restore the full pool configuration on ns1 (edit
/etc/kea/kea-dhcp4.conf back to the
192.168.232.100 - 192.168.232.150 range) and restart the
service - in a root shell on ns1:
# systemctl restart kea-dhcp4-server
Silent. The standby returns the same way - in a root shell on ns2:
# systemctl start kea-dhcp4-server
Also silent. The waiting client, once it retries, gets its lease - on lanclient, as john:
$ sudo dhclient -1 -v mv4
Internet Systems Consortium DHCP Client 4.4.3-P1
Copyright 2004-2022 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/mv4/52:54:00:22:00:08
Sending on LPF/mv4/52:54:00:22:00:08
Sending on Socket/fallback
DHCPDISCOVER on mv4 to 255.255.255.255 port 67 interval 4
DHCPOFFER of 192.168.232.102 from 192.168.232.10
DHCPREQUEST for 192.168.232.102 on mv4 to 255.255.255.255 port 67
DHCPACK of 192.168.232.102 from 192.168.232.10
bound to 192.168.232.102 -- renewal in 230 seconds.
.102 from the restored pool. Remove the drill's links in
lanclient's root shell - ip link del mv3 and ip link del mv4.
22.8.4. Backing Up Zones, Configuration, and Lease Data
Everything this chapter built lives in a short list of directories: BIND's configuration and zones, Kea's configuration and leases, Unbound's configuration, and radvd's file. One command captures the set - in a root shell on ns1:
# tar -czf /home/john/debian-handbook/dns-dhcp/dns-dhcp-backup.tgz /etc/bind /var/lib/bind /etc/kea /var/lib/kea /etc/unbound /etc/radvd.conf
tar: Removing leading `/' from member names
tar: Removing leading `/' from hard link targets
The two tar notices are the archiver converting absolute paths
to relative ones so extraction does not overwrite live files by
accident - the archive's paths begin etc/bind/..., var/lib/
bind/.... The archive lands in john's workspace, root-owned.
Inspect it - as john on ns1, in the workspace:
$ ls -lh dns-dhcp-backup.tgz; tar -tzf dns-dhcp-backup.tgz | grep -E "handbook.test.db|kea-leases4.csv" | head -4
-rw-r--r-- 1 root root 44K Nov 22 11:20 dns-dhcp-backup.tgz
var/lib/bind/handbook.test.db.jnl
var/lib/bind/handbook.test.db.signed
var/lib/bind/handbook.test.db.signed.jnl
var/lib/bind/handbook.test.db
The listing confirms the zone's full family is inside: the unsigned master, the journal of dynamic updates, the signed view and its journal. Extract and compare - as john:
$ rm -rf restore; mkdir restore; tar -xzf dns-dhcp-backup.tgz -C restore
The command prints nothing; the archive unpacks under
restore/ in the workspace. The strongest verification of a
backup is comparing it byte-for-byte with the live original -
still as john:
$ cmp /var/lib/bind/handbook.test.db restore/var/lib/bind/handbook.test.db && echo identical
identical
cmp reports differences and prints nothing when files match,
so the && prints identical only on byte equality - the
extracted zone is the live zone. Finally, validate that the
backup's contents are usable, not just present - as john:
$ python3 -m json.tool restore/etc/kea/kea-dhcp4.conf >/dev/null; named-checkzone handbook.test restore/var/lib/bind/handbook.test.db | tail -2
zone handbook.test/IN: loaded serial 2026112201
OK
Two checks in one command: the JSON configuration parses, and
the backed-up zone file loads cleanly under named-checkzone
with its serial intact. A backup that validates this way can be
restored with confidence: stop the services, extract the archive
over the real paths, restore ownership (chown bind:bind
/var/lib/bind/*, chown _kea:_kea /var/lib/kea/*), restart the
services, and verify serials and leases with the commands that
built them. Chapter 15 schedules and
tests backups as a discipline; this section's additions to that
discipline are the DNS-specific ones.
Two of those additions matter enough to state twice. First, the
command above does not include /var/cache/bind - the DNSSEC
signing keys. Configuration and zones can be rebuilt from
documentation and sweat; a lost key cannot, and its DS is
published in the parent, so a replacement key means a new DS and
a coordination event. Extend the tar command with
/var/cache/bind, and treat the resulting archive as a secret:
the private key files are exactly as sensitive as the TSIG keys
whose publication this chapter warned about. Second, the
*.jnl files in the archive are a snapshot of a live journal -
a dynamic zone's in-flight updates. The freeze/thaw procedure
from Section 22.3.5 gives a quiesced, consistent copy if the
backup moment must be exact; for everything else, the journal
and master file together reconstruct the zone, which is why
both belong in the archive.
That closes the chapter's loop: the plan of Section 22.1 named the failure domains, Sections 22.2 through 22.7 filled them with services that authenticate every cross-host trust, and this section walked each failure with a tool that names it. The practice network's final state is worth one look before teardown - every service running, both peers synchronized, both chains of trust intact - because that is the shape the next outage will interrupt, and the shape the drills restore.