DNS, DHCP, and Name Resolution Questions
How names and addresses are served and kept working on a network. DNS: resolution flow (stub, recursive, authoritative, root/TLD referrals), host-side resolver configuration and why one machine or process resolves differently from another, record types and their pitfalls (including apex aliasing, MX, SRV and CAA use), zones, delegation and glue, caching, TTL and negative caching, split-horizon and private zones, reverse DNS, zone transfers (AXFR/IXFR, TSIG), DNSSEC and key rollover, resolver and authoritative fleet design, forwarding versus running recursion, encrypted DNS (DoH/DoT), truncation, TCP fallback and EDNS, DNS-layer attacks (cache poisoning, amplification, spoofed-source floods), DNS health from the user's point of view, and DNS changes, mail and registrar migrations and outages. DHCP: address assignment and leases, scopes and sizing, reservations, relay across VLANs including relay agent information (option 82), redundancy and failover, and rogue or exhausted-scope failures. Includes diagnosing resolution failures that masquerade as wider outages. Excludes the layered network fault-isolation method and general packet capture, Active Directory-integrated DNS on domain controllers, DNS-based service registries for microservices, load-balancing algorithm design and global traffic steering, incident-command process and SLO or error-budget design, and generic scripting or infrastructure-as-code tooling.
You are paged: customers in one region cannot reach api.example.com. How do you isolate whether the cause is DNS, the network or the service itself?
Sample Answer
Direct answer
Split the path into three stages and test each one independently of the others: name to address (DNS), address reachable (network), and service healthy (the application). The fastest discriminator is to bypass DNS: if the request works when you give the client the address by hand but fails by name, the fault is in name resolution. If it fails both ways, test the path to the address and then the service. For a one-region problem, the first question is which resolvers those customers use and whether they get a different answer from the resolvers that work.
Ordered checks
1. Define the symptom. Collect from a real affected user, or a probe in the region: what error (NXDOMAIN, SERVFAIL, timeout, connection refused, TLS error, HTTP 5xx)? Which resolver and which IP did the client use? Which networks are affected? Different error types point at different stages, and the table at the end maps them.
2. Bypass DNS with the known-good address. Take the address from a working region (or from the service's own inventory) and force the name to it:
$ curl -s --resolve api.example.com:8080:127.0.0.2 http://api.example.com:8080/health
ok
--resolve host:port:address makes curl skip DNS and connect to that address with the right Host header and certificate name. From an affected location:
- Works by address, fails by name: the problem is DNS. Go to step 3.
- Fails by address too: the problem is the network or the service. Go to step 5.
3. Compare resolvers (DNS is suspect). Ask the region's resolver, then ask other resolvers and the authoritative servers directly, with recursion off so you read what each one holds:
$ dig @regional-resolver api.example.com A
$ dig @other-resolver api.example.com A
$ dig +short NS example.com
$ dig @ns-a.example.com api.example.com A +norecurse
$ dig @ns-b.example.com api.example.com A +norecurse
What the outputs look like in a lab (real runs against local test servers; the second server holds an older copy of the zone, the third has no copy):
$ dig @127.0.0.1 api.example.com A +noall +answer # resolver
api.example.com. 60 IN A 192.0.2.10
$ dig +noall +answer @127.0.0.2 api.example.com A +norecurse # authoritative, current
api.example.com. 60 IN A 192.0.2.10
$ dig +noall +answer @127.0.0.3 api.example.com A +norecurse # authoritative, stale
api.example.com. 60 IN A 192.0.2.99
$ dig @127.0.0.4 api.example.com A +norecurse | grep status # lame: no copy of the zone
;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 8624
$ dig +short @127.0.0.2 example.com SOA
ns-a.example.com. hostmaster.example.com. 7 3600 900 1209600 60
$ dig +short @127.0.0.3 example.com SOA
ns-a.example.com. hostmaster.example.com. 6 3600 900 1209600 60
Healthy means every authoritative server prints the same answer and the same SOA serial (the version number, the 7 and the 6 above). A different address plus a lower serial is the stale server. status: REFUSED is the signature of a lame server, one that is listed for the zone but will not answer for it. Read the results in this order:
- All authoritative servers agree and answer correctly, but the regional resolver does not: the resolver's cache or forwarding path is wrong. Look at the TTL (time-to-live, how long a cache may keep an answer) in its answer.
- One authoritative server answers differently or not at all: a stale secondary or a lame server (one that does not answer for the zone). Compare SOA serials across them.
- No authoritative server answers from the affected region, but they do from elsewhere: the path to the authoritative servers is the issue, such as anycast routing (one address announced from many sites, so the network sends each client to a nearby one, possibly a failed one) sending that region to a failed node, or a firewall dropping UDP/TCP 53.
Reading the TTL. A lab run showed what a cache can hide. A resolver cached api.example.com (TTL 60 seconds), then the authoritative server was stopped. Steps 1 and 2 ran about four seconds apart, with the server still up; the server was stopped before step 3:
1. warm the resolver cache for api
api.example.com. 60 IN A 192.0.2.10
2. same name from resolver (cached, TTL counting down)
api.example.com. 56 IN A 192.0.2.10
3. a name not in cache
status: SERVFAIL
4. ask the authoritative server directly
;; communications error to 127.0.0.2#53: connection refused
The cached name still resolved with its TTL counting down while an uncached name returned SERVFAIL. So "it resolves for me" is not proof that DNS is healthy, and "it fails for those customers" may depend on whether their resolver had the name cached. A TTL that counts down confirms you are reading a cached copy.
4. Check the record types and the TTL interplay. Ask for A and AAAA separately (dig api.example.com AAAA). A client that prefers IPv6 and gets an AAAA record pointing at an unreachable address stalls even though A is fine. Follow any CNAME chain (a CNAME is an alias that points one name at another, so a chain runs name to name to address) with dig +noall +answer. Each link is cached on its own TTL, so a change to the final address shows up after that A record's TTL, while a change to where the CNAME points shows up after the CNAME's TTL. In the lab, www was a CNAME with TTL 300 pointing at api, whose A record had TTL 60:
$ dig @127.0.0.1 www.example.com A +noall +answer # resolver, first lookup
www.example.com. 300 IN CNAME api.example.com.
api.example.com. 43 IN A 192.0.2.10
$ dig @127.0.0.1 www.example.com A +noall +answer # three seconds later
www.example.com. 297 IN CNAME api.example.com.
api.example.com. 40 IN A 192.0.2.10
The two clocks count down separately, so the shortest TTL in the chain decides how soon the resolver must rebuild the chain, and the longest decides how long a change to that link can stay hidden. A failed lookup is held for the negative-caching time (a resolver remembering that the name did not exist), the lower of the SOA TTL and the SOA MINIMUM field (RFC 2308). If region-specific answers are used (geo or latency steering, or split-horizon DNS, where different clients get different answers depending on where they ask from), check that the region's resolver is being matched to the intended pool. After you fix a record, affected users only recover as caches expire. With a TTL of 3600 seconds, the last cache can hold the bad answer for up to an hour, which is why a TTL is lowered before a change, not during it.
5. DNS is fine, so test the network. Connect to the resolved address from the affected region:
- Test the TCP connection and time it:
curl -s -o /dev/null -w "%{time_connect} %{http_code}\n" https://api.example.com/health. A timeout in connect with a healthy DNS answer is a routing, firewall or load-balancer reachability problem. The first number is the seconds spent connecting and the second the HTTP status:
0.000053 200 # healthy: connected at once, service answered 200
0.000000 000 # broken: curl gave up (here after 3 s with -m 3), no connection, no status; curl exits with code 28
- Trace the path in both directions with
tracerouteormtrtoward the address, and compare with a region that works. Each line is one hop with its address and round-trip time. A hop that prints*is one that did not answer. In the lab:
$ traceroute -n -m 3 -w 1 -q 1 127.0.0.1 # healthy: the destination answers
1 127.0.0.1 0.012 ms
$ traceroute -n -m 3 -w 1 -q 1 198.51.100.7 # an address on a link where nothing answers
1 *
2 *
3 *
A path whose replies stop at a provider boundary (good hops, then only * lines) points at an upstream or peering fault, with the caveat that some routers never answer traceroute, so confirm with a real connection test.
- Check whether the failure is size-dependent, which suggests an MTU (maximum transmission unit, the largest packet a link carries without splitting it) or fragmentation fault: small requests work, large responses stall.
6. Network is fine, so test the service. Hit the health endpoint on the specific backend in that region, bypassing the load balancer if possible, then check load balancer target health, certificate validity, recent deployments and error rates for that region. If one backend pool or one region's load balancer fails health checks, the cause is the service even though DNS and the network are healthy.
Mapping symptoms to stages
| What you see | Most likely stage | Next move |
|---|---|---|
| NXDOMAIN (the name does not exist) from the regional resolver, correct answer elsewhere | DNS: stale cache or missing record at one authoritative server | Query each authoritative server directly, compare SOA serials |
| SERVFAIL (the resolver could not get a usable answer) for uncached names | DNS: resolver cannot reach or validate the authoritative servers | Query the authoritative servers from the resolver's network; check DNSSEC validity if signed |
| Resolves, but connection times out, and by-address also times out | Network | mtr to the address from the region |
| Resolves, by-address works, by-name fails after the cache expires | DNS record change or removal | Check the zone change history and TTLs |
| Connects, then 5xx or TLS error | Service | Backend health, certificate, deployment |
| Resolves to a different IP in the region than elsewhere | Geo steering or split-horizon answers | Check the steering configuration and the answer from each resolver |
Mitigate and verify
Fix the stage you found, for example restore the record, repair the stale secondary (rndc retransfer example.com on BIND), withdraw the broken anycast node, or fail the region over. Then verify from the outside: the same dig against the regional resolver returns the correct answer, the curl by name succeeds from the affected region, and error rates for that region return to baseline. Record the TTL of the old answer so you can tell customers when the last cached copy expires.
An internal DNS server answers for your company's names but every lookup for external names times out or fails. How do you find the cause and fix it?
Sample Answer
Direct answer
Internal names work because the internal server is authoritative for them (it holds the zone and answers from its own data). External names need recursion: the server must go and ask other servers on the client's behalf. So the fault is almost always in that outbound path: recursion is switched off or restricted, the forwarder (an upstream resolver this server hands its unknown queries to) is dead or unreachable, a firewall drops port 53, or large answers die in transit. You find which by asking the server a recursive question and reading the RCODE (the status code in the reply), then testing each hop from the server itself. Timeout means packets are being lost; fast REFUSED means a policy says no; SERVFAIL after a delay means the server tried and failed.
Ordered diagnosis
Run everything from the DNS server itself first, so you separate "the server cannot resolve" from "clients cannot reach the server".
The causes below are listed in diagnostic order, not frequency. From experience (an ESTIMATE, not a measurement), a dead forwarder and a recursion or client-access restriction are the usual culprits, while TCP and fragmentation faults are rarer and the hardest to spot.
1. Reproduce and read the RCODE. Ask the server for one internal and one external name. In the flags line of a reply, rd means recursion desired (the client asked the server to resolve for it) and ra means recursion available (the server says it is willing to).
dig @127.0.0.1 app.corp.example +short
dig @127.0.0.1 www.outside.test +tries=1 +time=15
| What you see | What it tells you |
|---|---|
status: REFUSED immediately, ra flag missing | The server will not recurse for you: recursion no, or your source address is outside the allowed-clients list (allow-recursion in BIND, "Enable recursion"/scope settings elsewhere) |
Hangs, then SERVFAIL or communications error ... timed out | The server accepted the query, tried to resolve it, and the upstream never answered usefully: forwarder dead, firewall, or MTU/EDNS trouble |
NXDOMAIN for a name that exists | Different problem: a zone you host is shadowing the name (for example an internal copy of the public zone), or negative caching |
NOERROR but only from some clients | Client-side path (ACL, split-horizon view, wrong resolver on the client), not the server |
2. Check the recursion setting and the client ACL. In BIND, recursion no; returns REFUSED for every non-local name, and an allow-recursion list that omits a subnet does the same for that subnet only. Confirm what is actually loaded, not what the file you edited says: named-checkconf -p | grep -E 'recursion|forward'.
3. Check the forwarder. List what the server forwards to, then query that address directly with recursion requested, bypassing the internal server:
dig @<forwarder-ip> www.outside.test +tries=1 +time=3
No reply means the forwarder or the path to it is the fault. Also check how the forward policy is set. A server has two ways to resolve an outside name: forwarding (hand the question to an upstream resolver and relay its answer) or iterating (do the walk itself: ask a root server, which refers it to the top-level domain's servers, which refer it to the domain's own servers). forward only; means the server asks the forwarders and never tries anything else, so one dead forwarder makes every external lookup fail. forward first; means it tries the forwarders and then falls back to iterating itself from the root hints (the built-in list of the root servers' addresses). Root hints are only used when the server resolves iteratively: with forward only they are irrelevant, and with a stale or missing hints file plus no working forwarder, you also get failure. Test root reachability directly: dig @a.root-servers.net . NS +norecurse.
4. Check the firewall on UDP and TCP 53. DNS uses UDP by default, but a client must retry over TCP when a reply is truncated (the TC bit), and RFC 7766 makes TCP support a required part of a full DNS implementation. Firewalls that allow only UDP 53 break exactly the large answers. Test both transports from the server to the upstream:
dig @<upstream> www.outside.test +norecurse +short
dig @<upstream> www.outside.test +tcp +short
If UDP works and TCP times out, fix the rule (outbound from the resolver to the upstream, TCP and UDP 53, with return traffic allowed). Also confirm replies come back: stateful firewalls and NAT can drop the answer, which looks identical to the query being dropped, so capture on the server (tcpdump -ni any port 53) to see whether queries leave and whether replies arrive.
5. Check EDNS and fragmentation. EDNS0 (the extension mechanism, RFC 6891) lets a resolver advertise a UDP payload size larger than 512 bytes. Every link has an MTU (maximum transmission unit, the largest packet it carries, 1500 bytes on typical Ethernet). If the advertised size is bigger than the path can carry, the answer is split into IP fragments (pieces the receiver must reassemble), and many firewalls and middleboxes (devices in the path such as firewalls, NAT boxes and load balancers that inspect traffic) drop fragments. The symptom is distinctive: small answers work and large ones (DNSSEC-signed responses, long TXT sets) time out. DNS Flag Day 2020 recommends an EDNS buffer size of 1232 bytes, derived from the IPv6 minimum MTU of 1280 minus 48 bytes of IPv6 and UDP headers. Test it:
dig @<upstream> www.outside.test +bufsize=1232 +noall +comments
dig @<upstream> big-answer.example TXT +bufsize=4096 +tries=1 +time=3
+bufsize=N sets the UDP size the query advertises in its EDNS option. If the large buffer hangs and 1232 works (or the TCP query works), lower the resolver's advertised size (edns-udp-size and max-udp-size in BIND) and allow fragments or TCP on the path.
What the transport and size tests print, run in the lab against a lab server (a loopback address standing in for the upstream) that also holds a TXT record of about 1,000 bytes. Over UDP with a 512-byte buffer and +ignore (do not retry over TCP), the server sets the tc (truncated) flag, which means "the answer did not fit, ask again over TCP", and returns no data. With +noall +comments +stats dig still prints more than is shown below (the Got answer, ->>HEADER<<- and OPT PSEUDOSECTION lines, the cookie, Query time and WHEN), so these blocks are trimmed to the lines that matter:
$ dig @127.0.0.30 big.outside.test TXT +norecurse +bufsize=512 +ignore +noall +comments +stats
;; flags: qr aa tc; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
;; SERVER: 127.0.0.30#53(127.0.0.30) (UDP)
;; MSG SIZE rcvd: 73
Without +ignore, dig prints ;; Truncated, retrying in TCP mode., retries over TCP by itself and gets the whole record (rcvd: 1129 bytes here; the exact size depends on the record you create). Trimmed the same way:
$ dig @127.0.0.30 big.outside.test TXT +norecurse +bufsize=512 +noall +comments +stats
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; SERVER: 127.0.0.30#53(127.0.0.30) (TCP)
;; MSG SIZE rcvd: 1129
On a network that blocks TCP 53, that second command is the one that times out, and a resolver then fails exactly on large answers. A plain TCP query of a small record (dig @127.0.0.30 www.outside.test +norecurse +tcp +short) printed 203.0.113.10, and a +bufsize=1232 query returned a reply whose OPT line read ; EDNS: version: 0, flags:; udp: 1232. That number in a reply is the server's own advertised size (BIND's default), not an echo of your option: with +bufsize=4096 and +bufsize=512 the reply still said udp: 1232. To see what dig actually sent, add +qr, which prints the outgoing query too: it showed udp: 1232 with no option (dig from BIND 9.20 already advertises 1232 by default), udp: 4096 and udp: 512 with those values. So the 512 query is the one that changes behaviour here (truncation), and the reply's EDNS line is not evidence that your buffer setting took effect.
6. Check upstream resolver health. If the forwarder answers you but slowly or with SERVFAIL, query a second public or ISP resolver and the other internal forwarders. Compare: one bad upstream among several gives intermittent failures (a rotating choice of server), not a total outage. Remove or fix the sick one. Also check the server's own load and logs (rndc status, the query and resolver logs), because a saturated resolver drops queries too.
Worked example
This was reproduced in a Debian container with BIND 9.20.29: an "internal" server on 127.0.0.1 (authoritative for corp.example) and an "outside" server on port 5353 standing in for the upstream.
Broken state: forwarders { 192.0.2.1; }; forward only; where 192.0.2.1 is a TEST-NET address (reserved for documentation) that nothing answers.
$ dig @127.0.0.1 app.corp.example +short
10.0.0.5
$ dig @127.0.0.1 www.outside.test +tries=1 +time=15
;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 39506
;; Query time: 10010 msec
The output above and below is trimmed to the lines that matter (the full dig reply also has the question section, cookie and WHEN lines). Internal works, external waits about 10 seconds and fails: the signature of a dead forwarder (step 3). Changing to recursion no; gives a different signature, instant REFUSED with the ra flag absent:
;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 30235
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1
Fix: recursion yes; allow-recursion { any; } (in production limit this to your own subnets, see below) and forwarders { 127.0.0.1 port 5353; }:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 30697
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
www.outside.test. 300 IN A 203.0.113.10
Direct upstream tests over both transports also returned 203.0.113.10, which is the step 4 evidence that UDP and TCP both work.
Forward only versus forward first, with the same dead forwarder. A second lab run listed a lab root server (127.0.0.30, holding the answer) in the resolver's root hints file, kept forwarders { 192.0.2.1; }, and changed only the policy line. The same query, dig @127.0.0.1 www.outside.test +tries=1 +time=30, was run once per policy; the two results are shown together below, each reduced to its status, answer and query-time lines:
forward only; status: SERVFAIL Query time: 10005 msec
forward first; status: NOERROR Query time: 1204 msec
www.outside.test. 300 IN A 203.0.113.10
With forward only the server waits out the dead forwarder and gives up; with forward first it falls back to iterating from the root hints and succeeds about a second later. The container could not reproduce the firewall dropping packets or a real MTU limit, so those two causes are commands you would run on a real network, not output I captured; the truncation and TCP behaviour above were executed.
The fix and how you verify it
Fix the cause you found: restore the forwarder or point at healthy ones (ideally two or more, in different locations), re-enable recursion for the right clients, open UDP and TCP 53 outbound from the resolver, and lower the EDNS buffer to 1232 if large answers hang. Verify with the same dig that failed, from the server and from a client subnet, then confirm a signed or large answer (+dnssec or a big TXT) succeeds. Add a monitor that resolves one external and one internal name every minute so the next failure is seen before users report it.
Trade-offs and pitfalls
- forward only versus forward first.
forward onlyis predictable and keeps all egress through approved upstreams (good where only the upstream may reach the internet), but it has a single point of failure.forward firstsurvives a dead forwarder by iterating from the roots, but needs outbound 53 to the whole internet, which many firewalls forbid. Pick based on whether your firewall allows the resolver to reach arbitrary servers. - Do not "fix" it by opening recursion to everyone. An open resolver is abused for amplification (reflection) attacks: an attacker sends small queries with a forged source address, and your server sends much larger answers at the victim. Allow recursion only for your own address ranges.
- Split-horizon shadowing. If you host an internal zone with the same name as a public one, any name missing from the internal copy returns
NXDOMAINinstead of being forwarded. That is an authoritative-zone problem, not a forwarder one. - Caching hides and delays. Names already in cache keep working after the forwarder dies and fail later as TTLs (time-to-live, how long an answer may be cached) expire, which is why an outage can look partial and "start" an hour late. Negative answers are cached too, so a repaired path can appear still broken until that expires.
- DNSSEC. DNSSEC (cryptographic signing of DNS data) validation failures also return
SERVFAIL. Rundig +cd(sets the checking-disabled bit, asking the resolver to return the data without validating the signatures): if that succeeds while the normal query fails, the cause is validation (a wrong clock, or a broken trust anchor, the configured public key that validation starts from), not reachability.
How can an attacker get a resolver to cache a forged answer, and what makes the attack hard today? What would you still worry about?
Sample Answer
Direct answer
An off-path attacker (one who cannot see the victim's traffic, as opposed to an on-path attacker, who sits on the route and can) tricks a recursive resolver into caching a forged answer by racing the real authoritative server: the resolver sends a query over UDP, and the attacker floods it with fake replies that must match the query's 16-bit transaction ID, its source port, its question and the server address it was sent to. A fake that arrives first and matches is accepted and cached for its TTL. The 2008 attack disclosed by Dan Kaminsky (CERT note VU#800113, 8 July 2008) made this practical against resolvers that used a fixed source port, and what makes it hard today is the combination of a random ID and a random source port on every query (RFC 5452), strict matching and bailiwick rules (a resolver accepts only data that belongs to the zone it asked about), and above all DNSSEC, which makes a forged answer fail signature validation. What I would still worry about: unsigned zones, attackers who can see or influence the path, side channels that reveal the source port, and compromises that produce valid-looking data, such as a hijacked registrar account.
The attack, in order
- The attacker makes the victim resolver ask a question whose answer it does not already hold, for instance by triggering a lookup (many resolvers answer anyone who can reach them, or a victim's own user or mail server can be induced to look the name up).
- The resolver sends a query to the authoritative server with a transaction ID and source port.
- The attacker sends many spoofed replies purporting to be from that server's address. Each carries a guessed ID and port. Only one reply per race can be accepted.
- If a forged reply matches and beats the real one, the resolver caches the attacker's data until its TTL (time-to-live) expires, and every client of that resolver is served it.
Why Kaminsky's variant mattered. Before it, attackers forged the answer for a real name such as www.example.test; after one failed race the real answer was cached and the attacker had to wait out the TTL. Kaminsky's insight was to ask for random names that cannot be cached, such as a1b2c3.example.test, so every attempt is a fresh race, and to put the poison not in the answer but in the authority and additional sections of the forged reply: an NS record for example.test and a glue A record pointing at the attacker's server. Here is an illustrative forged reply for a query about a1b2c3.example.test (203.0.113.66 is a documentation address standing in for the attacker's server):
;; QUESTION SECTION:
;a1b2c3.example.test. IN A
;; ANSWER SECTION: (empty: the name does not exist)
;; AUTHORITY SECTION:
example.test. 86400 IN NS ns.example.test.
;; ADDITIONAL SECTION:
ns.example.test. 86400 IN A 203.0.113.66
A DNS reply has an answer section (the records that answer the question), an authority section (which servers are responsible) and an additional section (extra records offered to save a lookup, such as the address of a name server). The NS record there says "example.test is served by ns.example.test", and the additional-section A record (glue, the address of a name server whose name sits inside the zone it serves) says where that server is. If the resolver caches them, every later query for any example.test name goes to the attacker. The glue is in-domain (it belongs to the zone being asked about), so a rule that rejects out-of-domain data does not stop it; what stopped it was making each race unlikely to be won.
What makes it hard: the arithmetic
RFC 5452 requires a resolver to match the query ID, the source and destination addresses, the destination port against the query's source port, and the question, and to pick the ID and source port unpredictably across the full range available (ports 53 or 1024 and above). A 16-bit ID gives 65,536 values; random ports multiply that. The ID and port randomisation is the main defence, so the arithmetic is worth doing. A pinned calculation, where the attacker lands 1000 distinct forged (ID, port) guesses in each race and the port range is Linux's default ephemeral range (the block of high port numbers the operating system hands to outgoing connections) 32768 to 60999:
import math
ids = 65536 # 16-bit DNS query ID
ports = 60999 - 32768 + 1 # Linux default ephemeral range 32768-60999
forged = 1000 # forged replies that land inside one race window
print(f"ports in range: {ports}")
print(f"ID x port space: {ids * ports} ({math.log2(ids * ports):.1f} bits)")
for label, space in (("fixed port ", ids), ("random port", ids * ports)):
p = forged / space
races = math.log(0.5) / math.log(1 - p)
print(f"{label}: p per race = {p:.3e}, races for 50% = {races:.0f}")
ports in range: 28232
ID x port space: 1850212352 (30.8 bits)
fixed port : p per race = 1.526e-02, races for 50% = 45
random port: p per race = 5.405e-07, races for 50% = 1282469
Where the races formula comes from: if one race is won with probability p, it is lost with probability 1 - p, so losing n races in a row has probability (1 - p)^n. The attacker has a 50% chance of at least one win when that equals 0.5, and solving (1 - p)^n = 0.5 for n gives n = ln(0.5) / ln(1 - p), which is the math.log(0.5) / math.log(1 - p) line. Check by running it forward: with the fixed port, 1 - (1 - 0.01526)^45 is 0.499, and with the random port 1 - (1 - 5.405e-07)^1282469 is 0.500 (both checked in Python).
With a fixed port, 1000 forged replies per race win about 1.5% of the time and about 45 races give a 50% chance, which Kaminsky's fresh-name trick makes cheap. With a random port, a race wins about 5.4 in ten million, and it takes about 1.28 million races for a 50% chance. The port range here is 28,232 ports, about 14.8 bits, so the total is 30.8 bits rather than the 32 you get from a full 64k range; narrowing the allowed range (a firewall rule, or a resolver setting such as Unbound's outgoing-port-avoid that removes ports from use) directly weakens it.
Other layers:
- Bailiwick and glue checks. A resolver should accept data only if it belongs to the zone it asked about (RFC 5452 section 6); Unbound's
harden-glue(defaultyes) trusts glue only within the server's authority. - 0x20 encoding. The resolver randomises the upper and lower case of the query name, for example asking for
eXaMpLe.TeStinstead ofexample.test; an honest server echoes the case back exactly, so a forger must guess the case pattern too, and every letter in the name adds one more bit to guess. Unbound'suse-caps-for-idis an experimental option and defaults tono. - DNSSEC. The real fix: the forged data has no valid signature under the zone's key, so a validating resolver rejects it regardless of how well the forger guessed (a chain of signatures from the root key down to the zone: each level vouches for the key of the level below).
What I would still worry about
| Residual risk | Why randomisation does not cover it |
|---|---|
| Zones and resolvers without DNSSEC | The race is only hard, not impossible; at 30.8 bits an attacker with a fast path still gets there eventually |
| On-path attackers | They see the ID and port, so there is nothing to guess; only DNSSEC (or an encrypted resolver-to-server channel) helps |
| Side channels that leak the port | A side channel is information that leaks through a side effect rather than the reply itself. The 2020 SAD DNS research (UC Riverside) used the global rate limit on outgoing ICMP (Internet Control Message Protocol, the error-message protocol, for example "port unreachable") messages: by probing and watching how many ICMP errors came back, the attacker could tell which source port was open, then guessed only the ID. Listed mitigations: randomise or disable that ICMP behaviour, add secrets such as 0x20 or DNS cookies (a random value the client and server exchange and echo, RFC 7873, which off-path forgers cannot know), deploy DNSSEC, and shorten the window a query stays outstanding |
| Port randomisation undone en route | A NAT or firewall that remaps source ports predictably gives back the entropy (the unpredictability, measured in bits); confirm with a capture that ports seen leaving the network still vary |
| Valid-looking bad data | A registrar or DNS-provider account takeover, or a hijacked route to an authoritative server, produces correctly signed or simply authoritative answers; DNSSEC does not stop a registrar compromise because the attacker can change the DS too |
| Shared resolvers | One poisoned cache serves everyone behind it, so open or lightly protected forwarders raise the blast radius |
What I would do
Run a validating resolver (with DNSSEC on), restrict who may query it, keep the outgoing port range wide, leave harden-glue on, sign my own zones, lock down registrar accounts with multi-factor authentication and registry locks where offered (a registry lock is an extra step in which the registry itself, not just the registrar, must approve changes to a domain's delegation), and capture traffic once to verify source ports actually vary leaving the network.
Which DNS record types would you expect to find in a typical production zone, what is each one for, and which one has bitten you or a colleague with a subtle operational pitfall?
Sample Answer
Direct answer
A production zone is built from a few record types, each with one job: SOA (start of authority) describes the zone and its refresh timers, NS names the servers that are authoritative, A and AAAA map a name to an IPv4 or IPv6 address, CNAME makes one name an alias of another, MX says where mail goes, TXT carries free text such as email-sender policy (SPF, Sender Policy Framework), SRV locates a service by host and port, CAA restricts which certificate authorities may issue certificates, and PTR (in a reverse zone) maps an address back to a name. Most zones are mostly SOA, NS, A/AAAA, CNAME and MX; TXT, SRV, CAA and PTR appear when a service needs them, and the DNSSEC records only in signed zones. The pitfall I would name is the CNAME: a name that owns a CNAME may own no other record type, so an alias placed at the zone apex quietly collides with the SOA, NS and MX records that must live there.
What each type is for
| Type | Purpose | Operational rule that matters |
|---|---|---|
SOA | Zone metadata: primary server, contact, serial, refresh, retry, expire, and the last field (the negative-caching TTL) | Secondaries re-fetch the zone only when the serial increases, so forgetting to bump it leaves them serving old data |
NS | Delegates and names the zone's servers | Keep at least two, on separate networks; the parent zone must carry matching NS records |
A / AAAA | Address of a host | A name can have several; publish AAAA only if the service really answers on IPv6 |
CNAME | Alias to a canonical name | Cannot coexist with other data at the same name (RFC 2181 section 10.1) |
MX | Mail exchangers, lowest preference number tried first | Target must be a name with an address record, not an alias (RFC 2181 section 10.3) |
TXT | Sender policy (SPF), domain-verification tokens | One SPF record per name; SPF allows at most 10 DNS-querying terms (RFC 7208 section 4.6.4) |
SRV | Priority, weight, port and host for a service | Needs the target host to have an address record |
CAA | Which CAs may issue for the name | A CA climbs the name tree to find the nearest CAA set (RFC 8659); no CAA anywhere means no restriction |
PTR | Reverse lookup, lives under in-addr.arpa or ip6.arpa | Owned by whoever controls the address block, often the ISP, not the domain owner |
DNSSEC (the DNS signing extensions) adds DNSKEY, DS, RRSIG and NSEC (or NSEC3) records to a signed zone; signing is a separate step on top of the plain zone shown here.
The SOA fields in plain words
The five numbers in the SOA record are all times in seconds except the serial (RFC 1035 section 3.3.13):
- serial: the version number of the zone. A secondary (a server that copies the zone from the primary) compares it with its own copy.
- refresh (7200 below, 2 hours): how often a secondary asks the primary whether the serial changed.
- retry (900, 15 minutes): how long a secondary waits before trying again after a refresh failed.
- expire (1209600, 14 days): if a secondary cannot reach the primary for this long, it stops answering for the zone.
- negative-caching TTL (300, 5 minutes; the last field, called MINIMUM in the record): how long a resolver may remember that a name or record type does not exist. RFC 2308 takes the smaller of this field and the
SOArecord's own TTL.
The second name in the SOA, hostmaster.example.com., is the responsible person's mailbox with the @ written as a dot (hostmaster@example.com).
A zone excerpt that loads
This zone excerpt was checked with named-checkzone from BIND 9.20 and loads cleanly (zone example.com/IN: loaded serial 2026100601, OK):
$TTL 3600
@ IN SOA ns1.example.com. hostmaster.example.com. (
2026100601 ; serial (YYYYMMDDnn)
7200 ; refresh
900 ; retry
1209600 ; expire
300 ) ; negative-caching TTL (SOA MINIMUM)
IN NS ns1.example.com.
IN NS ns2.example.net.
IN A 192.0.2.10
IN AAAA 2001:db8::10
IN MX 10 mail.example.com.
IN MX 20 mail-backup.example.com.
IN TXT "v=spf1 mx include:_spf.mailer.example.net -all"
IN CAA 0 issue "letsencrypt.org"
ns1 IN A 192.0.2.53
mail IN A 192.0.2.25
mail-backup IN A 192.0.2.26
www IN CNAME @
app 300 IN CNAME app-lb.cloud.example.net.
_sip._tcp IN SRV 10 60 5060 sip.example.com.
sip IN A 192.0.2.60
Reading the syntax:
$TTL 3600sets the default TTL (time-to-live, seconds a cache may reuse a record) for every record that does not state its own.appstates300, which overrides it.@stands for the zone's own name,example.com., called the apex.- A line that starts with spaces has no owner name written, so it reuses the previous owner: the
NS,A,AAAA,MX,TXTandCAAlines all belong to@. INis the record class, Internet, the only class used in practice.- Parentheses let the
SOAspan several lines, and;starts a comment. - A name ending in a dot (
ns1.example.com.) is complete. A name without one gets the zone name appended, sons1on its own meansns1.example.com.. Forgetting a trailing dot is a classic way to createhost.example.com.example.com.. _sip._tcpis the owner name of anSRVrecord: an underscore, the service name, then the protocol (RFC 2782), so the full name is_sip._tcp.example.com..SRV 10 60 5060 sip.example.com.reads: priority 10 (clients try the lowest number first), weight 60 (the share of traffic among targets with equal priority), port 5060, and the host that serves it, which must have an address record and must not be an alias.CAA 0 issue "letsencrypt.org"reads: flags 0 (the issuer-critical bit, 128, is not set), tagissue(this certificate authority may issue certificates for the name), and the authority's identifying domain (RFC 8659).MX 10andMX 20are preferences: the mail server with the lowest number is tried first.
The second NS points at a server in another zone (example.net), which needs no glue and keeps the zone reachable if example.com's own network is down. The www alias uses @, the zone apex, as its target, which is legal because the alias sits on www, not on the apex.
The pitfall in action: an alias at the apex
A common story: the team moves the site to a hosted platform that says "point your domain at lb.cloud.example.net", and someone replaces the apex A record with a CNAME. The apex also holds the SOA, NS and MX records, so the zone breaks. Here is that zone as bad.zone:
$TTL 3600
@ IN SOA ns1.example.com. hostmaster.example.com. 1 7200 900 1209600 300
IN NS ns1.example.com.
IN CNAME lb.cloud.example.net.
IN MX 10 mail.example.com.
ns1 IN A 192.0.2.53
mail IN A 192.0.2.25
$ named-checkzone example.com bad.zone
dns_master_load: bad.zone:5: example.com: CNAME and other data
dns_master_load: bad.zone:5: example.com: CNAME and other data
dns_master_load: bad.zone:5: example.com: CNAME and other data
zone example.com/IN: loading from master file bad.zone failed: CNAME and other data
zone example.com/IN: not loaded due to errors.
exit=1
BIND refuses the zone, which is the safe outcome. The same message appears several times because the alias collides with several records at once. Do not rely on a provider console to catch the same mistake: run a zone check (named-checkzone or the provider's validator) before publishing. Fixes: use the platform's address records, or the provider's flattening feature (often called ALIAS or ANAME, a non-standard provider feature that answers with plain A records), or put the site on www and redirect the apex.
A nearby trap is bad2.zone: no apex alias, but the mail host is an alias.
$TTL 3600
@ IN SOA ns1.example.com. hostmaster.example.com. 1 7200 900 1209600 300
IN NS ns1.example.com.
IN A 192.0.2.10
IN MX 10 mail.example.com.
ns1 IN A 192.0.2.53
mail IN CNAME mx1.example.com.
mx1 IN A 192.0.2.25
$ named-checkzone example.com bad2.zone
zone example.com/IN: example.com/MX 'mail.example.com' is a CNAME (illegal)
zone example.com/IN: loaded serial 1
OK
exit=0
$ named-checkzone -M fail example.com bad2.zone
zone example.com/IN: example.com/MX 'mail.example.com' is a CNAME (illegal)
zone example.com/IN: not loaded due to errors.
exit=1
Both runs print the word "illegal", and the difference is only what the checker is told to do about it: by default an MX that points at an alias is a warning, so the zone loads and the exit code is 0; with -M fail (BIND's check-mx-cname setting, which named.conf also accepts) the same finding stops the load. The record is invalid either way under RFC 2181 section 10.3, so a clean exit code from the default check does not mean the zone is correct. Delivery behaviour depends on the sending server. And a CNAME pointing at a third-party name that is later deprovisioned is a dangling alias that an attacker may be able to claim.
Pitfalls beyond the one
- TTL before a migration. Lower the TTL (time-to-live, how long caches may reuse a record) a full old-TTL ahead of a change; otherwise caches keep the old address.
- SPF 10-lookup limit. Each
include,a,mx,ptr,existsorredirectcounts toward 10; exceeding it yieldspermerrorand mail can be rejected. A TXT value over 255 characters must be split into several quoted strings, which readers concatenate (RFC 7208 section 3.3). - Serial not bumped. The zone file is correct on the primary and wrong everywhere else until the serial rises.
What is the difference between a stub resolver, a recursive resolver and an authoritative server, and where does each usually live? How does the client-side configuration on a host influence which one an application ends up talking to?
Sample Answer
Direct answer
A stub resolver is the small client built into the operating system or language runtime: it holds no zone data, walks nothing, and forwards each question to a configured server. A recursive resolver (also called a caching or full-service resolver) accepts that question, does whatever lookups are needed by following referrals from the root downward, caches the results, and returns one final answer. An authoritative server holds the records for the zones it serves and answers only for those, without caching anyone else's data. Stubs live on every host, recursive resolvers live inside the organisation or at an ISP or public provider, and authoritative servers live with the domain owner or a managed DNS provider. The host's client-side configuration decides which recursive resolver an application reaches, and whether it asks DNS at all.
Where each one lives and what it does
| Role | Typical location | Holds | Sets flags | Caches for others |
|---|---|---|---|---|
| Stub resolver | Every laptop, server, container: the C library, the OS DNS client service, sometimes the browser | A small cache at most | Sends RD (recursion desired) | Only for the local machine |
| Recursive resolver | Corporate resolver pair, ISP, cloud virtual-network (VPC, Virtual Private Cloud) resolver, public resolver | A shared cache | Replies with RA (recursion available) | Yes, for all its clients |
| Authoritative server | Domain owner's primary and secondaries, or a managed DNS provider | Zone files | Replies with AA (authoritative answer) | No |
RFC 1034 draws the same line: stub resolvers offload the work to recursive-capable servers through a configuration file, while full-service resolvers do the lookups themselves using a local cache.
How host configuration steers the application
- Which sources, in what order. On Linux,
/etc/nsswitch.confhas ahosts:line;files dnsmeans/etc/hostsis consulted before any DNS query, so a stale line there overrides DNS for that machine. - Which resolver.
/etc/resolv.conflists up to threenameserverentries (a limit documented in theresolv.confmanual page, MAXNS); on most desktops and servers the file is generated by DHCP (Dynamic Host Configuration Protocol), a VPN client or a local resolver service, not hand-edited. The defaults per that manual page:timeout5 seconds per server,attempts2,rotateoff, so a dead first server delays every lookup by up to the timeout before the second is tried. - Which name gets queried. The
searchlist andndots(default 1) decide when a short name such asmailis expanded: a name with fewer dots thanndotsis tried with each search suffix first. - Per-interface and per-domain rules. Windows and VPN clients can send different suffixes to different resolvers, and browsers can be set to bypass the OS and use their own encrypted-DNS resolver.
Lab check of the first and third points
With a stub pointed at the lab resolver, getent ahostsv4 goes through the C library's name service switch, the same path most applications use:
$ getent ahostsv4 www.example.test | head -1
192.0.2.20 STREAM web.example.test
$ echo '203.0.113.9 www.example.test' >> /etc/hosts
$ getent ahostsv4 www.example.test | head -1
203.0.113.9 STREAM www.example.test
$ dig +short www.example.test A
web.example.test.
192.0.2.20
Reading the getent lines: the first column is the address. The second is the socket type the answer is for: getent ahostsv4 prints one line per socket type (STREAM for TCP, DGRAM for UDP, RAW for raw sockets), all with the same address, so head -1 keeps only the STREAM line (without head, the lab printed all three, with an empty third column on the last two). The third column is the canonical name. Before the /etc/hosts edit it is web.example.test because in the lab zone www is an alias (CNAME) for web, and the second dig output shows that alias chain (web.example.test. then the address). After the edit the answer came from /etc/hosts, which has no alias, so the name is www.example.test itself.
After the /etc/hosts line is added, the application path returns 203.0.113.9 while dig, which talks to the DNS server directly and never reads /etc/hosts, still returns 192.0.2.20. That gap is a classic "it works in dig but not in the app" cause.
With search example.test in /etc/resolv.conf, the bare name mail expands:
$ dig +short mail
$ dig +search +short mail
192.0.2.30
$ host mail
mail.example.test has address 192.0.2.30
$ nslookup mail
Server: 127.0.0.20
Address: 127.0.0.20#53
Non-authoritative answer:
Name: mail.example.test
Address: 192.0.2.30
dig ignores the search list unless +search is given; host and nslookup apply it by default. In the nslookup block, Server and Address identify the resolver that answered (127.0.0.20, port 53). Non-authoritative answer: means the answer came from a server that is not itself authoritative for that zone, here the caching resolver, so the data may come from its cache or from a forward to another server. An answer read directly from the zone's own authoritative server has no such line.
How the expansion works, shown as real queries. Take ndots at its default of 1: a name with fewer than 1 dot (so mail) is tried with each suffix from the search list first, in order, and bare as a last resort; a name with at least 1 dot is tried as written first. With search lab.test example.test in /etc/resolv.conf, the lab resolver's query log (repeated lines removed) showed the exact names the C library asked for:
getent ahostsv4 mail -> mail.lab.test. then mail.example.test. (answered, stop)
getent ahostsv4 www.example.test -> www.example.test. (answered, stop)
getent ahostsv4 nosuch -> nosuch.lab.test. nosuch.example.test. nosuch. (all fail, exit code 2)
The first suffix produced no answer, so the second was tried; www.example.test has two dots, so it was asked as written and nothing else was tried; and a name that exists nowhere is tried with every suffix and then bare before getent gives up. Each failed attempt is a real query, which is another reason an unneeded search suffix slows lookups.
On Windows, the equivalents are Get-DnsClientServerAddress -AddressFamily IPv4 (which servers each interface uses), Resolve-DnsName -Name www.example.com -Type A -Server 192.0.2.53 -DnsOnly (query one server using DNS only, skipping LLMNR and NetBIOS), and Clear-DnsClientCache (the same as ipconfig /flushdns). What each one tells you. Get-DnsClientServerAddress -AddressFamily IPv4 returns one entry per network interface, listing the DNS server addresses that interface will use; compare it with what you expected (for example, the corporate resolver rather than a router or a leftover public one) and note that different interfaces, such as a VPN adapter, can list different servers. Resolve-DnsName ... -Server 192.0.2.53 -DnsOnly returns the DNS records the named server sent back (name, type, TTL and the address or target); a result there but a failure in the application points at the host's other sources (hosts file, LLMNR, NetBIOS, a different interface's servers), and an error there points at that server. Clear-DnsClientCache produces no output on success (Microsoft Learn lists its output as None); run Resolve-DnsName again to confirm the new answer. These parameter names were checked against Microsoft Learn and the lines parse in PowerShell 7; they were not executed because the DnsClient module is Windows-only, so no sample output is shown for them.
Pitfalls
- Debugging with the wrong tool.
dig @serverbypassesnsswitch.conf,/etc/hosts, the search list and the OS cache, so it proves the server is right, not that the application will see the same thing. Usegetent ahostsv4 nameon Linux to test the application's path. - Slow first lookups. A dead first
nameservercosts up to the timeout on every lookup that reaches it. Remove it, or put a healthy resolver first. - Recursion exposed on authoritative servers. A server that is both authoritative and open-recursive can be abused by outsiders; keep the two roles on separate listeners or hosts, or restrict recursion to your own address ranges.
- Fleet drift. Resolver lists arrive by DHCP, VPN and hand edits. When a resolver is retired, hosts that hard-coded its address are the ones that break.
Unlock Full Question Bank
Get access to all 39 DNS, DHCP, and Name Resolution interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.