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.
How would you know that your DNS service is healthy from the user's point of view, before anyone complains, and how would you avoid paging people for noise?
Sample Answer
Direct answer
Measure what a user experiences, not what the server says about itself: a synthetic probe (a scripted lookup run on a schedule) resolves real names through the same resolvers users use, from several regions, and checks both the answer and the time. Page a human only when probes from more than one region fail persistently. Everything else (error ratios, cache hit ratio, per-region latency drift) goes to dashboards and tickets, because those signals are noisy on their own and many have causes nobody should be woken for.
What to measure, and who gets told
| Signal | What it tells you | Source | Action |
|---|---|---|---|
| Probe success: NOERROR and the expected answer | The user-visible outcome, including wrong answers | Probes in 3 or more regions | Page when at least 2 regions fail 3 probes in a row |
| Probe latency, 95th percentile (p95: 95% of probes are faster) per region | Slowness a user feels, per region | Same probes | Ticket when above baseline for 15 minutes; alert only if it nears client timeouts |
| Two probe kinds: a warm name and a unique never-cached name | Warm = resolver speed. Unique = the full path to the authoritative servers | Probe names under a zone you control, e.g. a wildcard record (explained after the table) | Compare: only the unique name slow points past the resolver |
| SERVFAIL ratio (the resolver's "could not answer" code) | Upstream or resolver trouble | Resolver counters | Ticket; page only if probes also fail |
| NXDOMAIN ratio (the "name does not exist" code), against its own baseline | A jump means a client or deploy is asking for wrong names | Resolver counters | Ticket |
| Cache hit ratio = hits / (hits + misses) | Falling hit ratio raises latency and upstream load | Resolver counters | Dashboard |
| Zone consistency: the SOA serial (the zone version number) equal on every name server (NS, the servers named as the zone's authorities) | Replication or zone-transfer problems (a zone transfer is how a secondary server copies the zone from the primary) | Probe that asks each NS | Ticket |
A unique name needs a wildcard record, one that answers for every name under a label. Put *.probe IN A 203.0.113.50 (an illustrative address) in a zone you control and every name ending in .probe.example.com resolves, so each probe can invent a name no cache has ever seen, such as probe-$RANDOM-$(date +%s).probe.example.com. A real generated name from the lab, passed through the script below, was probe-11127-1791275626.probe.example.com:
$ dns-probe.sh 127.0.0.1 probe-11127-1791275626.probe.example.com 203.0.113.50
probe resolver=127.0.0.1 name=probe-11127-1791275626.probe.example.com result=ok answer=203.0.113.50 latency_ms=0
The per-region and unique-name points are what make it "from the user's point of view": a resolver can report zero errors while one region's users wait seconds, and a cached name can hide an authoritative outage.
A probe you can run
This script checks one resolver and one name, labels the outcome and prints one machine-readable line. It passes shellcheck (a shell linter) with no findings.
#!/usr/bin/env bash
# Synthetic DNS probe: one line per (resolver, name) with outcome and latency.
# usage: dns-probe.sh RESOLVER NAME EXPECTED_ANSWER
set -u
resolver=$1 name=$2 expect=$3
out=$(dig @"$resolver" "$name" A +tries=1 +time=2 +noall +comments +answer +stats 2>&1)
status=$(grep -o 'status: [A-Z]*' <<<"$out" | awk '{print $2}')
ms=$(grep -o 'Query time: [0-9]*' <<<"$out" | awk '{print $3}')
answer=$(grep -E "^${name//./\\.}\.[[:space:]]" <<<"$out" | awk '{print $NF}' | sort | paste -sd, -)
if [ -z "$status" ]; then result=no_response
elif [ "$status" != NOERROR ]; then result=$status
elif [ "$answer" != "$expect" ]; then result=wrong_answer
else result=ok; fi
printf 'probe resolver=%s name=%s result=%s answer=%s latency_ms=%s\n' \
"$resolver" "$name" "$result" "${answer:--}" "${ms:--}"
Against a lab resolver (Unbound on 127.0.0.1 forwarding example.com to an nsd authoritative server on 127.0.0.2, with www = 203.0.113.10 and api = 203.0.113.11):
$ dns-probe.sh 127.0.0.1 www.example.com 203.0.113.10
probe resolver=127.0.0.1 name=www.example.com result=ok answer=203.0.113.10 latency_ms=1
$ dns-probe.sh 127.0.0.1 www.example.com 198.51.100.7 # expectation drifted
probe resolver=127.0.0.1 name=www.example.com result=wrong_answer answer=203.0.113.10 latency_ms=0
$ dns-probe.sh 127.0.0.1 nope.example.com -
probe resolver=127.0.0.1 name=nope.example.com result=NXDOMAIN answer=- latency_ms=0
--- authoritative server stopped
probe resolver=127.0.0.1 name=api.example.com result=no_response answer=- latency_ms=-
--- resolver address with nothing listening
probe resolver=127.0.0.9 name=www.example.com result=no_response answer=- latency_ms=-
What each line of the script does:
set -umakes an unset variable an error, so a forgotten argument stops the script instead of probing an empty name. The next line takes the three arguments.out=$(dig ...)runs one query and stores everything it prints.@"$resolver"picks the server to ask;+tries=1 +time=2means one attempt with a 2 second wait;+noall +comments +answer +statsprint only the header comments, the answer section and the statistics (including the query time);2>&1also captures error messages.status=takes the textstatus: NOERRORout of the header (grep -oprints only the matching part,<<<"$out"feeds the variable togrepas its input) andawk '{print $2}'keeps the second word,NOERROR.ms=does the same forQuery time: 12(third word,12).answer=keeps the answer-section lines that start with the probed name.${name//./\.}replaces every.in the name with\.because in a regular expression a bare dot means any character (www\.example\.com);awk '{print $NF}'keeps the last field of each line, the address;sort | paste -sd, -sorts the addresses and joins them with commas, so a multi-address answer compares the same way each time.- The
ifchain labels the outcome in this order: no status at all isno_response; any status other thanNOERRORis reported as that code; aNOERRORwhose address list differs from the expected one iswrong_answer; otherwiseok. printfprints onekey=valueline;${answer:--}means "use-when empty".
Four outcomes are visible: a correct answer, a wrong answer (the probe catches a changed record that a status-code check would miss), an error code, and no answer at all. When the authoritative server stops, a user of an uncached name sees a timeout, not a clean error, because the resolver spends longer retrying than the probe's 2 second limit. Ship the line to your metrics system and compute the ratio per region. The REFUSED code (the server declines to answer, for example because the client is not allowed to ask) and SERVFAIL both land in the result= field as their own labels.
Resolver-side counters come from the resolver itself. For Unbound, unbound-control stats_noreset prints total.num.cachehits, total.num.cachemiss and, when extended-statistics: yes is set in the server: block of unbound.conf, num.answer.rcode.SERVFAIL (all seen in the lab with that option on; without it the per-rcode lines are absent); other resolvers publish comparable counters, so check your own resolver's documentation for the exact names.
Paging without noise
Assume a probe fails by chance with probability 0.5% (an assumed figure for transient packet loss, independent between probes), runs every 30 seconds from each of 3 regions, so 2,880 probes per region per day.
- Page on any single failed probe: 2,880 x 3 x 0.005 = 43.2 expected false pages a day (8,640 probes x 0.5%).
- Page on 3 failures in a row at one region: 2,880 x 3 x 0.005^3 = 0.001 a day, at the price of a 90 second detection delay (3 x 30 s). The pieces: a day has 86,400 seconds, and one probe every 30 seconds gives 86,400 / 30 = 2,880 probes per region; 3 regions give 2,880 x 3 = 8,640 probes a day. Each probe ends one possible run of 3, so there are about 8,640 runs, and a run is all-failed with probability 0.005^3 = 1.25 x 10^-7. Then 8,640 x 1.25 x 10^-7 = 0.00108, about 0.001 a day.
- Require at least 2 of the 3 regions to agree before paging, and send a single-region failure as a ticket: a local network fault near one probe host stops paging anyone.
Real failures are correlated, so the independence assumption is optimistic. That is why the rule needs two regions and a duration, not just a threshold. Also silence the alert during announced maintenance, and keep a deliberate-NXDOMAIN probe separate so an expected "no such name" result is not counted as an outage.
If you set a service-level objective (SLO: a target for the share of good probes) of 99.9% over 30 days, the error budget (how much failure the target still allows) is 0.1% of the 30 x 24 x 60 = 43,200 minutes in the window, which is 43.2 minutes of probe-failed time.
What query logging costs
Assume an illustrative 2,000 queries per second and about 150 bytes per log line: 2,000 x 150 = 300,000 B/s, or 25.92 GB a day. Logging 1% of NOERROR queries cuts that to about 259 MB a day; keep all SERVFAIL and REFUSED lines, because they are rare: at 0.1% of traffic that is 2 per second, about 25.9 MB a day. Counters stay unsampled and are cheap, so rates and ratios never depend on the sample.
Pitfalls
Alerting on the server's own "up" check misses wrong answers and regional slowness. Paging on SERVFAIL ratio alone wakes people for one customer's broken delegation (the NS records that hand a name to the servers responsible for it). Probing only popular names measures the cache, not the service.
Design name resolution for an environment with several cloud accounts, Kubernetes clusters and an on-premises network, where internal services need private names and the same names must resolve differently outside. How do queries flow in each direction, and what would you do to avoid inconsistent answers?
Sample Answer
Direct answer
Give every zone exactly one owner, let resolvers find the owner by forwarding on the longest matching domain suffix, and generate any name that must differ inside versus outside from one source of truth. Concretely: a private root such as internal.example.com split into sub-zones (aws., k8s., onprem.), each served by the team and system that owns those hosts; on-premises resolvers forward the cloud and cluster sub-zones to the cloud resolvers' inbound endpoints; the cloud resolvers forward the on-premises sub-zone out through outbound endpoints; each Kubernetes cluster's CoreDNS (the in-cluster DNS server) answers its own names and forwards the rest to the cloud resolver. Split-horizon (same name, different answer inside and outside) is done by two zones of the same name with different audiences, and every record in both comes from one repository and is checked by an automated consistency test.
Two rules do most of the work: one owner per zone, and forwarding on the longest matching suffix. Everything else below (generated views, the checker script, TTL choices) exists to keep those two rules true over time.
Terms used below. A zone is one slice of the DNS namespace that a single set of servers is responsible for. Kubernetes terms: a cluster is a set of machines running containers; a pod is the smallest unit that runs your containers and gets its own IP address; a namespace is a named grouping of cluster objects, and kube-system is the one where Kubernetes keeps its own components; a ConfigMap is a cluster object that holds configuration text other components read (CoreDNS reads its settings from one); cluster.local is the default DNS suffix for names inside a cluster, such as my-service.default.svc.cluster.local. AWS terms: a private hosted zone is a DNS zone that only the VPCs you attach it to can see; an inbound endpoint is a set of IP addresses inside your VPC that resolvers outside it (such as on-premises ones) can send queries to; an outbound endpoint is the set of addresses from which the VPC resolver sends queries out to resolvers elsewhere; a forwarding rule says "queries for this domain go to these resolver addresses". An on-premises resolver does the same with a conditional forwarder. A stub domain in CoreDNS is a block that sends one suffix to a chosen upstream resolver. Longest-suffix match means that when several rules fit a name, the one with the most matching trailing labels wins: api.k8s.corp.lab matches both corp.lab and k8s.corp.lab, and k8s.corp.lab is chosen.
Who asks whom
| Query starts at | Asks first | What sends it onward | Answered by |
|---|---|---|---|
Pod, name ends cluster.local | CoreDNS in the cluster | nothing, CoreDNS owns it | CoreDNS |
| Pod, any other name | CoreDNS | default forward (or a stub-domain block) to the cloud resolver | cloud resolver, or the stub domain's upstream |
| Cloud workload, cloud name | VPC resolver (base plus 2) | the private hosted zone attached to that VPC | the hosted zone |
| Cloud workload, on-premises name | VPC resolver | forwarding rule, out through the outbound endpoint | on-premises resolvers |
| On-premises client, cloud or cluster name | on-premises resolver | conditional forwarder to the inbound endpoint addresses | the VPC resolver behind the endpoint |
| Anyone, public name | their resolver | normal recursion | the public zone's provider |
Query flow in each direction
The cloud side is described with Amazon Route 53's resolver (VPC Resolver, where a VPC is a Virtual Private Cloud, a private network inside a cloud account); other clouds have equivalent inbound and outbound forwarding features.
- Pod to an in-cluster name (
cluster.local): CoreDNS answers it. These names never leave the cluster. - Pod to any other name: CoreDNS forwards to the cloud resolver (in a VPC, the address at the base of the VPC range plus two, for example 10.0.0.2 for 10.0.0.0/16). Kubernetes lets you add stub domains in the
corednsConfigMap inkube-system, for example the block shown after this list, which sends one suffix to a specific upstream. CoreDNS does not support a hostname as the upstream of a stub domain, only IP addresses. - Cloud workload to a cloud name: the VPC resolver answers from the private hosted zone (a private DNS zone attached to chosen VPCs) associated with that VPC. Route 53 picks the most specific matching zone and returns NXDOMAIN (name does not exist) if that zone has no such record. It does not fall back to the public zone.
- Cloud workload to an on-premises name: a forwarding rule for
onprem.internal.example.comsends the query out of an outbound endpoint to the on-premises resolvers over the VPN or private link. If a query matches several rules the most specific one wins, and a resolver rule overrides a private hosted zone of the same name. Rules can be shared across accounts, so one set of rules serves all accounts. - On-premises client to a cloud name: the on-premises resolver has a conditional forwarder for
aws.internal.example.comandk8s.internal.example.compointing at the cloud resolver's inbound endpoint addresses. Point the forwarders at the inbound endpoint addresses, not at the VPC base-plus-two address: the inbound endpoint is the address set AWS provides for queries coming from your own network. - Anyone to a public name: resolved recursively as usual. The public zone for
example.comstays at its public provider.
The stub-domain block from flow 2 (the format Kubernetes documents for the coredns ConfigMap, whose own example uses consul.local:53 and 10.150.0.1; the suffix here is this design's):
onprem.internal.example.com:53 {
errors
cache 30
forward . 10.150.0.1
}
Reading it line by line: onprem.internal.example.com:53 { opens a block that applies only to queries for that suffix, arriving on port 53. errors makes CoreDNS log the errors it hits to standard output. cache 30 keeps answers for at most 30 seconds. forward . 10.150.0.1 sends every query in this block to the upstream resolver at 10.150.0.1 (the . means all names in the block's zone; the address is illustrative). Queries for any other suffix do not match this block and take CoreDNS's default path.
Making the longest-suffix rule concrete (executed)
Unbound configured with two forward zones, corp.lab to one authoritative server and k8s.corp.lab to another, chose by suffix. Because the lab upstreams sit on loopback, the server: block needs do-not-query-localhost: no; without it Unbound refuses to use 127.0.0.1 upstreams and answers SERVFAIL. In production the forward addresses are real resolver addresses and that line is not needed.
server:
do-not-query-localhost: no
forward-zone:
name: "corp.lab"
forward-addr: 127.0.0.1@5301
forward-zone:
name: "k8s.corp.lab"
forward-addr: 127.0.0.1@5302
The server on port 5301 held corp.lab with ldap IN A 10.0.0.20 and www IN A 10.0.0.80; the server on port 5302 held k8s.corp.lab with api IN A 10.96.0.1. dig @127.0.0.1 +short ldap.corp.lab A returned 10.0.0.20 (from the parent zone's server) and dig @127.0.0.1 +short api.k8s.corp.lab A returned 10.96.0.1 (from the cluster's server). The lab uses corp.lab; in production, build the private root under a domain you own so it cannot collide with a name someone else registers.
Split-horizon without inconsistency
The same name can legitimately differ by audience. In BIND this is a view per audience; two views of corp.lab, with the internal one matched by source address, answered www.corp.lab differently from the same server:
view "internal" { match-clients { 127.0.0.1; }; zone "corp.lab" { type primary; file "/z/db.corp.int"; }; };
view "external" { match-clients { any; }; zone "corp.lab" { type primary; file "/z/db.corp.ext"; }; };
The two zone files were identical except for one line, www IN A 10.0.0.80 in db.corp.int and www IN A 203.0.113.80 in db.corp.ext. Queried from 127.0.0.1 it returned 10.0.0.80; queried from 127.0.0.2 (dig -b 127.0.0.2 @127.0.0.2, after ip addr add 127.0.0.2/32 dev lo so that BIND listens on that address) it returned 203.0.113.80. In Route 53 the same pattern is a public and a private hosted zone with the same name. The private one wins for the VPCs it is attached to, and a name missing from it yields NXDOMAIN inside, so every public name the inside also needs must be copied into the private zone.
What I do to avoid inconsistent answers
- One owner per name. Each sub-zone has one authoritative system. A parent zone delegates with NS records (private hosted zones support NS delegation of a subdomain); nobody duplicates a sub-zone into a second place.
- Same rules everywhere. The forward rules on every resolver (on-premises, each VPC, each cluster) come from one definition, because an environment missing the
k8srule falls into the parent zone's rule and gets NXDOMAIN from a server that never held the name. - Generate both split-horizon views from one record source. Internal and external records live in the same repository and are rendered into each zone, so a name cannot exist in one view only by accident.
- Test it continuously. A checker script queries each resolver for a list of expected answers and flags any mismatch:
#!/usr/bin/env bash
# usage: dnscheck.sh expected.txt resolver [resolver...] (resolver = host or host:port)
exp=$1; shift; rc=0
while read -r name type want; do
[[ -z $name || $name == \#* ]] && continue
for r in "$@"; do
host=${r%%:*}; port=53; [[ $r == *:* ]] && port=${r##*:}
got=$(dig @"$host" -p "$port" +short +time=2 +tries=1 "$name" "$type" 2>&1 | grep -v "^;;" | sort | paste -sd, -)
if [[ $got == "$want" ]]; then s=ok; else s=MISMATCH; rc=1; fi
printf '%-9s %-22s via %-15s want=%-12s got=%s\n' "$s" "$name" "$r" "$want" "${got:-<empty>}"
done
done < "$exp"
exit $rc
The expectations file expected.txt has one name type want line per check:
# name type want
ldap.corp.lab A 10.0.0.20
api.k8s.corp.lab A 10.96.0.1
www.corp.lab A 10.0.0.80
Run as bash dnscheck.sh expected.txt 127.0.0.1:53 127.0.0.1:5354, with an on-premises resolver (the Unbound configuration above, port 53) and a cloud-side resolver (a second Unbound on port 5354 with only the corp.lab forward zone, built without the k8s rule), it printed:
ok ldap.corp.lab via 127.0.0.1:53 want=10.0.0.20 got=10.0.0.20
ok ldap.corp.lab via 127.0.0.1:5354 want=10.0.0.20 got=10.0.0.20
ok api.k8s.corp.lab via 127.0.0.1:53 want=10.96.0.1 got=10.96.0.1
MISMATCH api.k8s.corp.lab via 127.0.0.1:5354 want=10.96.0.1 got=<empty>
ok www.corp.lab via 127.0.0.1:53 want=10.0.0.80 got=10.0.0.80
ok www.corp.lab via 127.0.0.1:5354 want=10.0.0.80 got=10.0.0.80
and exited 1, so a pipeline stops. Run it from each environment against its own resolver. The MISMATCH row is the one to act on: the resolver on port 5354 returned nothing (<empty>) for the k8s name because it lacks the k8s forwarding rule.
Reading the script: exp=$1; shift; rc=0 stores the expectations file name, drops it from the argument list so "$@" holds only resolvers, and starts the exit code at 0. while read -r name type want reads each line of the file as three fields. [[ -z $name || $name == \#* ]] && continue skips blank lines and lines starting with # (comments). host=${r%%:*} cuts everything from the first : onward, leaving the host; port=53; [[ $r == *:* ]] && port=${r##*:} keeps 53 unless the resolver was written host:port, in which case ${r##*:} keeps everything after the last :. For 127.0.0.1:5354 these give 127.0.0.1 and 5354. In the dig line, +short prints only the answer data, +time=2 +tries=1 limits the wait to two seconds and one attempt, grep -v "^;;" drops dig's error lines (they start with ;;), sort orders multi-address answers, and paste -sd, - joins the lines into one comma-separated string so it can be compared with the expected value. The if compares, sets s to ok or MISMATCH and sets rc=1 on any mismatch, printf prints the aligned row, ${got:-<empty>} prints <empty> when nothing came back, and done < "$exp" feeds the file to the loop. exit $rc returns 1 if any row mismatched.
- Short TTLs on dynamic names, longer on stable ones. Cluster service names change often (the Kubernetes example above caches for 30 seconds); stable infrastructure names can be longer. Mismatched TTLs can also make two environments disagree for a few minutes even when the data is identical.
Trade-offs
- A central resolver layer is one more path to keep highly available; give each endpoint at least two addresses in different zones or sites.
- Split-horizon doubles the places a record can be wrong. If the inside and outside answers do not need to differ, publish one name and expose it only on private addresses behind access control.
- If everything is in a single cloud with no on-premises network, drop the on-premises forwarders and keep the rest.
You migrated an organisation's mail to a new provider by changing MX records, but some senders keep delivering to the old hosts for hours. Why does that happen, and how would you have planned the cutover to avoid lost mail and allow a safe rollback?
Sample Answer
Direct answer
Senders keep using the old hosts because a mail sender looks up the MX record (MX = "mail exchanger", the DNS record that names the server that accepts mail for a domain) through its own resolver, and that resolver is allowed to keep the answer for the record's TTL (time-to-live, the number of seconds a cached answer may be reused). The TTL clock starts when each resolver cached the record, not when you edited the zone, so the last stragglers disappear one full old TTL after your change. To avoid lost mail you lower the TTL ahead of time, make the new provider ready before the switch, keep the old host accepting and relaying mail long enough, and keep a rollback that does not strand mail in the wrong place.
Why it happens (shown, not asserted)
This lab uses an authoritative server (the one holding the zone) and a separate caching resolver standing in for a sender's resolver. The MX TTL is 3600 seconds.
$ dig @127.0.0.1 example.com MX +noall +answer # port 53: the sender's caching resolver, which now caches it
example.com. 3600 IN MX 10 mx.old-host.example.com.
# admin edits the zone: MX now points at mx.new-host, serial bumped, zone reloaded
$ dig -p 5353 @127.0.0.1 example.com MX +noall +answer # port 5353: the authoritative server holding the zone
example.com. 3600 IN MX 10 mx.new-host.example.com.
# five seconds later, same sender resolver
$ dig @127.0.0.1 example.com MX +noall +answer
example.com. 3594 IN MX 10 mx.old-host.example.com.
The authoritative server already says "new", yet the resolver still hands out "old" with a TTL counting down (3594). Every resolver that cached the record at a different moment expires at a different moment, so mail trickles to the old host for up to one old TTL. Three things can stretch the tail further. The first affects every migration. The second applies only to senders whose resolver operator has raised a minimum. The third applies only when the migration also moves the domain's name servers.
- The TTL that matters is the one the record carried when it was cached. Lowering it on cutover day does nothing for caches already holding the long one.
- Some resolvers enforce a minimum TTL. Unbound has a
cache-min-ttlsetting (a floor on how short a cached TTL may be) whose default is 0 (disabled), but operators can raise it, so a few senders will hold answers longer than you published. - If you also moved nameservers, the delegation itself is cached by resolvers. A live query to the .com registry servers for example.com returned NS records with TTL 172800 (48 hours) and a DS record with TTL 86400 (24 hours). The NS records are the delegation, the list at the parent zone of which servers answer for your domain; the DS record, which exists only if the zone is DNSSEC-signed, is a fingerprint of your signing key. You cannot lower those, because the registry sets them. A resolver that cached the old delegation just before you changed it keeps sending queries to the old name servers for up to 48 hours, so a nameserver move needs a 48-hour overlap where both providers serve identical data.
Cutover plan
Assume the current MX TTL is 86400 s (24 hours) and the target is 300 s.
| When | Action | Check |
|---|---|---|
| T-7 days | Build the new provider: every mailbox, alias, group and shared mailbox exists. Publish the new provider's DKIM (DomainKeys Identified Mail, a signing key in DNS) selectors (a selector is the label that picks which key, as in selector1._domainkey.example.com). Add the new provider to SPF (Sender Policy Framework, the TXT record that lists who may send as your domain) next to the old sender. | swaks --to user@example.com --server mx.new-host.example.com (swaks is an SMTP test tool that sends one message straight to a named server) delivers to a real mailbox |
| T-7 days | Configure the old host's relay (accept, then forward onward without keeping a copy) and test it for a test address only. Keep storing real mail on the old host: until the MX changes, users still read the old mailboxes, so relaying their live mail early would send it to a store they are not reading. | Send a message to the test address via the old host, find it in the new mailbox |
| T-2 days, 09:00 | Lower the MX TTL from 86400 to 300. | dig @<authoritative-ns> example.com MX +noall +answer shows 300 |
| T-1 day, 09:00 | Confirm that 24 hours (one old TTL) have passed since the TTL was lowered, so no resolver still holds a copy cached under the 86400 TTL. | Queries via several public resolvers show a TTL no higher than 300 |
| T0, 09:00 | Change MX to the new host and, at the same moment, switch the old host's relay on for every address, then run a final incremental copy of mailbox contents from the old store to the new provider so nothing delivered before the switch is left behind. Remove the old MX, or leave it at a worse preference number as described in the paragraph on coexisting MX records. | Authoritative answer shows the new host, plus the old host at preference 20 only if you chose to keep it |
| T0 to T+7 days | Old host keeps accepting and relaying. Watch its inbound connection count fall, and the new provider's rise. | Old host's inbound count per hour trends to near zero |
| T+7 days | Decommission the old host once a full day shows only spam and no real senders. Raise the TTL back (for example 3600). | Final audit of the old host's logs |
Why seven days: RFC 5321 section 4.5.4.1 says a sending server MUST delay retrying a destination after an attempt has failed, that the retry interval SHOULD be at least 30 minutes, and that the give-up time generally needs to be at least 4-5 days. A sender whose message is queued against the old host can therefore legitimately try it for days. Seven days covers that.
Both MX records can coexist during the transition. RFC 5321 section 5.1 says lower preference numbers are tried first and equal-preference hosts must be randomised. Putting the old MX at preference 20 and the new at 10 sends nearly everything to the new host while leaving a safety net, because every host in the list delivers to the same place.
Rollback that does not lose mail
The reason for relaying from the old host is that mail lands in the new provider's mailboxes whichever server the sender picked. Rollback is then three actions. First, set the MX back to the old host (it propagates in about 5 minutes because of the 300-second TTL). Second, reverse the relay so the old host stores mail instead of forwarding it. Third, bring back the mail already in the new provider's mailboxes: everything delivered after T0 is stored there and not in the old store, so either set the new provider to forward its inbound mail to the old host for the rollback window or export those messages and import them into the old mailboxes. Skipping the third step leaves recent mail in a store nobody is reading. Decide the trigger in advance, for example "deferral or bounce reports from known partners in the first hour, or the new provider's inbound count not rising within 30 minutes of the change". A deferral is a temporary failure reply (an SMTP 4xx code) after which the sender queues the message and retries.
What actually loses mail
| Failure | Result |
|---|---|
| Old host shut down or answering 5xx (permanent failure) for mailboxes it no longer holds | Senders get a non-delivery report and the mail is gone for good |
| Old host accepts mail into a store nobody reads | Silent loss, the worst case |
| New provider missing an alias or group that the old host had | Bounces that start only on cutover day |
| TTL lowered on cutover day instead of two days earlier | Hours of mail to the old host, which is tolerable only because of the relay |
Trade-offs
A shorter TTL costs more queries to your authoritative servers during the window, which is negligible for one MX record. Leaving the old host as a relay for a week costs a server and patching for a week, which is cheap against lost customer mail. A single sharp cutover with no overlap is only acceptable when both stores are the same system.
A security team wants to block clients from using public encrypted DNS, while users argue it protects their privacy. How do DoH and DoT change what an enterprise can see and enforce, and what would you propose?
Sample Answer
Direct answer
Encrypted DNS protects the query from everyone on the path, and that includes the enterprise. DoT (DNS over TLS) wraps DNS in TLS on its own TCP port, 853 (RFC 7858). DoH (DNS over HTTPS) carries DNS messages inside ordinary HTTPS requests (RFC 8484). Once a device talks to a public encrypted resolver, the company can no longer see the names it looks up, apply DNS-based blocking, or log queries per client. I would not fight this with a blanket ban alone. I would run an enterprise resolver that itself speaks encrypted DNS, point managed devices at it by policy (so users get privacy from the local network and the company keeps visibility on its own devices), block the unmanaged routes at the network edge, and be explicit with staff about what the company can see.
What each side sees and can enforce
| Plain DNS (UDP/TCP 53) | DoT (TCP 853) | DoH (TCP 443) | |
|---|---|---|---|
| Query names visible to the network | Yes | No (encrypted) | No (encrypted) |
| Easy to identify as DNS | Yes, by port | Yes, by port 853 | No, looks like web traffic to a firewall that only reads ports |
| Block with a firewall rule | Port rule works | One rule: deny outbound TCP 853 | Port rule would block all web traffic; needs destination lists or TLS inspection |
| Enterprise DNS filtering, logging, response policy (rewriting or refusing the answer for chosen names) | Works | Works only if devices use the enterprise resolver | Works only if devices use the enterprise resolver |
| What remains visible | Everything | Destination IP, volume, timing | Destination IP, volume, timing, and usually the server name the client announces in the TLS handshake (SNI, server name indication, normally sent unencrypted so the server knows which site is wanted) |
RFC 8484 states this plainly: filtering or inspection systems that rely on unsecured transport of DNS will not function in a DoH environment. The protocol encrypts and authenticates the server, but it does not tell the resolver who is a managed device.
The two positions are both partly right
- Security team: DNS logs and DNS firewalls (blocking known-bad domains, spotting command-and-control beaconing (malware contacting its operator's server at regular intervals), alerting on newly registered domains) only work if the queries pass through resolvers the company controls. A browser that silently sends its lookups to a public DoH service bypasses all of it.
- Users: On a coffee-shop or home network, plain DNS is readable and forgeable by anyone on the path, and encrypted DNS fixes that. The privacy gain is real against the local network and the ISP. It does not hide queries from the resolver operator, so it moves trust to a different party rather than removing it.
What I would propose
Steps 1 to 3 do the enforcing. Steps 4 to 6 make the setup smoother for clients and defensible to staff.
- Run an enterprise resolver that supports encrypted DNS. Clients on the corporate network and on VPN use it, over DoT or DoH, so the connection is protected from the LAN while the company keeps logging and filtering at the resolver. The resolver should also forward upstream over TLS. An Unbound example that passes
unbound-checkconf(the forwarder address is a documentation placeholder, which stands in for the vetted upstream you choose):
server:
interface: 127.0.0.4
tls-cert-bundle: /etc/ssl/certs/ca-certificates.crt
forward-zone:
name: "."
forward-tls-upstream: yes
forward-addr: 192.0.2.53@853#dns-upstream.example.net
Reading the block, line by line:
server:opens the global section.interface: 127.0.0.4is the address Unbound listens on for client queries (a loopback placeholder here; on a real resolver it is the address your clients are pointed at).tls-cert-bundlenames the file of trusted certificate authorities (CAs) that Unbound uses to check the upstream's TLS certificate. Without it the upstream cannot be authenticated.forward-zone:withname: "."means "the root", so every name that is not answered locally is forwarded rather than resolved by walking down from the root servers.forward-tls-upstream: yesmakes Unbound speak DoT (TLS) to the upstream instead of plain port 53.forward-addr: 192.0.2.53@853#dns-upstream.example.nethas three parts: the upstream's IP address,@853the port to connect to, and#dns-upstream.example.netthe name that the upstream's certificate must carry. The#namepart is what stops someone else answering on that IP: Unbound completes the TLS handshake only if the certificate is valid for that name.
unbound-checkconf printed unbound-checkconf: no errors in <file>, naming the file it checked. It checks syntax only; it does not contact the upstream.
- Configure managed endpoints by policy, and lock the settings. Firefox has a
DNSOverHTTPSenterprise policy withEnabled,ProviderURLandLockedkeys, so you can point it at the enterprise DoH endpoint and stop users changing it. Chrome'sDnsOverHttpsModepolicy takesoff,automatic(DoH first, with fallback to insecure) orsecure(DoH only, with no fallback, so resolution fails if the DoH server is unreachable), sosecurewith the enterprise template is the managed-device setting. An operating-system or browser setting that the user can change is not enforcement. - Block the unmanaged routes at the network edge. Deny outbound TCP 853 except from your resolvers (one firewall rule). For DoH, deny outbound connections to the public DoH providers you identify by address list or secure web gateway category, and refuse their hostnames at the enterprise resolver so a client that uses the system resolver to find them fails. A secure web gateway is a proxy that filters web traffic by site category, which is how "public DoH provider" can be a category you block. In the lab, an Unbound resolver configured with
local-zone: "dns.google." always_refuseand the same forcloudflare-dns.com.returned:
dns.google: status: REFUSED
cloudflare-dns.com: status: REFUSED
- Let clients discover the enterprise's own encrypted resolver. DDR (Discovery of Designated Resolvers, RFC 9462) lets a client that knows only the plain resolver address ask that resolver for the name
_dns.resolver.arpa.with record type SVCB (service binding, a record that says how to reach a service: target host name, protocol and port). The answer points to the same operator's encrypted endpoint. With a local-data entry in Unbound, the lab returned:
$ dig @127.0.0.1 _dns.resolver.arpa. SVCB +noall +answer
_dns.resolver.arpa. 300 IN SVCB 1 dns.corp.example. alpn="dot" port=853 ipv4hint=192.0.2.53
Read it as: priority 1, target host dns.corp.example., alpn="dot" the protocol (DoT), port=853, and ipv4hint an address to try without another lookup (all values are illustrative). The security rule is that for verified discovery the client must check that the encrypted resolver's certificate lists the IP address of the plain resolver it started from (RFC 9462 requires an iPAddress entry in the certificate's subjectAltName). The reason is that the plain query can be forged by anyone on the path, and a certificate naming that IP shows the owner of that address designated the encrypted endpoint. Advertising DDR means clients upgrade to your resolver rather than to a public one.
5. Give guests and personal devices a separate network with no promise of DNS visibility, so you are not trying to inspect devices you do not manage.
6. Write down the privacy rules. Say what the resolver logs, how long they are kept, who may query them, and that encrypted DNS is on for staff against outside observers. This turns a dispute into a documented trade-off.
Why not just block everything
Blocking 853 is cheap and reliable. Blocking DoH is a moving target: any HTTPS server can answer DNS queries, so address lists age, and TLS inspection (a gateway that decrypts and re-encrypts traffic using a certificate the company's devices trust) breaks pinned applications (apps that accept only their own expected certificate and so reject the gateway's) and adds cost and legal exposure. Block what is cheap (853, known provider hostnames and addresses), and rely on managed-endpoint policy for the rest. Some devices, such as unmanaged phones or applications that ship their own resolver, will still get through, and the answer to that gap is endpoint management, not more DNS rules.
Performance and privacy trade-offs
- Performance: A TLS or HTTPS connection costs extra round trips once, then queries reuse the connection, so steady-state latency is close to plain DNS. Enterprise resolver capacity must cover many long-lived TLS sessions. Cache hits at the enterprise resolver are faster than a cold lookup to a public service.
- Privacy: Employees' lookups are visible to the company on managed devices, which is a policy and legal decision, not just a technical one. Public encrypted DNS hides queries from the local network but hands them to the provider.
- Failure mode: With Chrome's
securemode, an outage of the enterprise resolver means no resolution at all, whileautomaticfalls back to insecure DNS. Choose consciously and monitor the resolver.
A secondary DNS server has stopped picking up changes made on the primary. How do zone transfers work, what are the usual reasons they fail, and how would you debug and then lock transfers down?
Sample Answer
Direct answer
A secondary (also called slave) keeps a copy of a zone by comparing the serial number in the zone's SOA record (start of authority, the zone's header record) with the primary's, then pulling changes over TCP with a zone transfer. A secondary that stops updating is almost always one of four things: the serial did not increase, the secondary never heard or accepted the NOTIFY (the primary's "something changed" message), TCP port 53 is blocked, or the transfer is rejected by an access list or TSIG (transaction signature) check. Debug by comparing serials on both servers, then testing a transfer by hand from the secondary's own host, and lock transfers down by allowing them only to holders of a TSIG key.
How a zone transfer works
- Serial comparison. The SOA record holds SERIAL, REFRESH, RETRY and EXPIRE (RFC 1035 section 3.3.13). The secondary asks the primary for the SOA every REFRESH seconds. If the primary's serial is greater (compared with sequence-space arithmetic on an unsigned 32-bit number, not plain subtraction; the next paragraph shows what that means), the secondary pulls the zone. A failed refresh is retried after RETRY seconds. If nothing succeeds for EXPIRE seconds, the secondary stops answering for the zone.
What "greater" means (RFC 1982). The serial is a 32-bit counter, so it runs from 0 to 4294967295 and then wraps to 0. A seriali1counts as newer thani2wheni1 > i2andi1 - i2is less than 2^31 (2147483648), or wheni1 < i2andi2 - i1is more than 2^31. Normal case: the primary holds 2024010103 and the secondary 2024010102; the difference is 1, so the primary's is newer and the secondary pulls. Wrap case: the primary's counter has passed 4294967295 and wrapped to 0 while the secondary holds 4294967295; plain comparison says 0 is smaller, but the rule above says 0 is newer (the gap, 4294967295, is more than 2^31). Backwards case: a primary serial of 2023123101 against a secondary's 2024010102 differs by 887001, which is less than 2^31, so the primary's counts as older and is ignored. Jumps larger than 2^31 in one step (for example from 100 to 3000000000) also count as older. All of these were computed with Python against the RFC 1982 rule. This is why a date-counter serial (YYYYMMDDnn) can only be increased by small steps and a lowered serial is silently ignored. - NOTIFY. After a change, the primary sends a NOTIFY message (RFC 1996) to the servers in its notify set (the zone's NS servers plus any
also-notifyaddresses) so they do not wait a full REFRESH. A secondary that receives NOTIFY from an address that is not a known primary for the zone (not one of the addresses in that zone'sprimarieslist on the secondary) ignores it and logs an error (RFC 1996 section 3.10); it does not query the sender, so it learns of the change only when its own REFRESH timer fires. A NOTIFY from a known primary makes the secondary check that primary's SOA at once instead of waiting. NOTIFY is a shortcut. The refresh timer is the safety net. - Transfer. AXFR (full zone transfer) is defined over TCP only (RFC 5936), starts and ends with the zone's SOA record, and a general-purpose implementation is recommended to use TSIG to control it. IXFR (incremental transfer, RFC 1995) sends only the differences since the secondary's serial and falls back to a full transfer when the primary lacks that history.
- Authentication. TSIG (RFC 8945) signs each message with a shared secret and a timestamp, so the primary can accept transfers by key instead of by source address.
The lab used for the evidence below
Primary at 127.0.0.2, secondary at 127.0.0.3, BIND 9.20, zone example.com. The primary has allow-transfer { key xfer-key; }, also-notify { 127.0.0.3; }; the secondary has primaries { 127.0.0.2; } and server 127.0.0.2 { keys { xfer-key; }; }, with a key made by tsig-keygen -a hmac-sha256 xfer-key.
Debug in this order
1. Compare serials on both servers. This tells you at once whether the secondary is behind.
$ dig +short @127.0.0.2 example.com SOA | awk '{print "primary serial",$3}'
$ dig +short @127.0.0.3 example.com SOA | awk '{print "secondary serial",$3}'
dig +short prints just the SOA data, seven space-separated fields: primary server, contact mailbox, serial, refresh, retry, expire, minimum. For example ns1.example.com. hostmaster.example.com. 2024010103 7200 3600 1209600 300. The serial is the third field, which is why awk prints $3. A healthy pair prints the same number twice. With the primary at 2024010103 and a secondary that has not caught up, the lab printed:
primary serial 2024010103
secondary serial 2024010102
A lower number on the secondary means it is behind; the other steps find out why.
Equal serials but a missing record means the change was made without bumping the serial. In the lab, adding late IN A 192.0.2.30 to the primary and reloading without changing the serial left the secondary answering status: NXDOMAIN for late.example.com, because from its point of view nothing had changed. Fix: increment the serial on every change, or generate it (a date-counter such as 2024010102 or a Unix timestamp) in the deploy pipeline.
A serial that moves backwards is ignored. When the primary's serial was set to 2023123101 while the secondary held 2024010102, the secondary kept 2024010102 and never received the new record. Recovery is to raise the serial above the old value, or to follow the documented serial-reset procedure for your server software.
2. Is NOTIFY arriving, and from where? Check the secondary's log. A multi-homed primary (one with more than one IP address) may send NOTIFY from a different address than the one the secondary lists. Before the fix, the lab primary sent from 127.0.0.1 and the secondary logged:
received notify for zone 'example.com'
zone example.com/IN: refused notify from non-primary: 127.0.0.1#50034
Without NOTIFY the secondary only learns of the change at its next REFRESH, which is why this fault looks like "works, but slowly". Fix on the primary: notify-source 127.0.0.2; (and transfer-source 127.0.0.3; on the secondary for its own transfers). After the fix the log shows notify from 127.0.0.2#56137: serial 2024010103 and the transfer starts at once.
3. Is TCP/53 open both ways? UDP/53 may work while TCP is dropped, so SOA checks pass and NOTIFY arrives but the transfer hangs. In the lab, after iptables -A INPUT -p tcp --dport 53 -j DROP on the primary and a serial bump:
primary serial 2024010103
secondary serial 2024010102
$ dig +tcp +time=2 +tries=1 @127.0.0.2 example.com SOA
;; Connection to 127.0.0.2#53(127.0.0.2) for example.com failed: timed out.
The secondary logs notify from 127.0.0.2#56137: serial 2024010103 then Transfer started. and nothing further. Test from the secondary's host with dig +tcp @primary example.com SOA.
4. Is the transfer authorised? Request a full transfer by hand from the secondary's host, with the key:
$ dig @127.0.0.2 example.com AXFR +noall +comments # no key
;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 3605
(flags and OPT lines omitted)
; Transfer failed.
$ dig @127.0.0.2 example.com AXFR -y hmac-sha256:xfer-key:<secret>
Without a key the lab primary returned REFUSED (a plain dig ... AXFR without +comments prints only ; Transfer failed., so add +noall +comments to see the status). With a wrong secret the transfer failed and the response carried TSIG ... BADSIG. Other TSIG failures to recognise (RFC 8945): BADKEY (key name or algorithm unknown to the server) and BADTIME (the timestamp is outside the allowed "fudge" window, the number of seconds the two servers' clocks may differ before a signature is rejected; 300 seconds is the recommended value, so the cause is clock drift between the two servers). BADSIG means the signature did not verify (usually a wrong secret). Fix clock sync with NTP (network time protocol), or correct the key name, algorithm and secret on both sides.
5. Force the retry once the cause is fixed. On BIND, rndc retransfer example.com on the secondary pulls the zone immediately. In the lab it exited with status 0 and the secondary moved from 2024010101 to 2024010105. Then re-check serials.
Lock transfers down
The first two items are the controls that decide whether a stranger can pull the zone: refuse transfers by default, and allow them only with a key. The remaining items add layers around those two.
- Set a global
allow-transfer { none; };inoptions, and open it per zone:allow-transfer { key xfer-key; };. In the lab an unsigned request was REFUSED while a signed one returned the zone, with the SOA record appearing as first and last record. - Use a key per secondary,
hmac-sha256or stronger (RFC 8945 discourages SHA-1), and rotate keys on a schedule. - Add a source-address allow-list at the network layer as well: TCP/53 from the secondaries only, and a firewall rule that lets the secondaries' source addresses reach the primary. The network rule limits who can reach the port at all, and the key limits who may pull the zone once they can, so each covers a gap the other leaves.
- Keep the primary hidden (not listed in the zone's NS records, so resolvers never query it and only the secondaries face the internet; the secondaries are the servers you publish).
- Monitor SOA serial parity across all name servers and alert when they differ for longer than REFRESH plus RETRY.
Why open transfers matter
An open AXFR hands out every hostname in the zone, including internal-looking names (vpn, jenkins, staging-db), which saves an attacker the guesswork of enumeration.
Unlock Full Question Bank
Get access to all 40 DNS, DHCP, and Name Resolution interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.