Notes
Stub and resolver
Your application does not do much. It calls the system's resolver library, which checks etc hosts first, then asks the nameserver listed in etc resolv dot conf. That server is a recursive resolver: on a laptop, your router or ISP; in AWS, the VPC resolver; in Kubernetes, CoreDNS. Its job is to find the answer, however many servers it has to ask, and cache it.
$ cat /etc/resolv.conf nameserver 10.0.0.2 search svc.cluster.local app → libc getaddrinfo() → /etc/hosts first → the nameserver listed systemd-resolved, cloud VPC resolver, CoreDNS in k8s
Recursion
On a cold cache, the resolver walks the tree. It asks a root server, which does not know the answer but says ask the.com servers. The.com servers say shoprung.com is served by these name servers. The authoritative server, run by your DNS provider, gives the real answer with a TTL. The resolver caches every step, so the next lookup is instant. dig plus trace shows this walk.
- 1 root: "ask the .com servers"
- 2 .com: "shoprung.com is served by ns1.provider"
- 3 authoritative: "A 203.0.113.10, TTL 300"
- resolver caches every step
- $ dig +trace shows the path
Records
Here are the records you will set, from our own lab zone served by dnsmasq. An A record maps a name to an IP version four address: ten dot zero dot one dot twenty, with a TTL of three hundred seconds. A CNAME makes www an alias for another name. MX says where email goes. TXT holds text, here an SPF email policy, and is used for domain verification. AAAA is the IP version six address, NS names the authoritative servers, and CAA limits who may issue certificates.
shoprung.test 300 A 10.0.1.20 www CNAME shoprung.test. MX 10 mail.shoprung.test. TXT "v=spf1 -all" also: AAAA (IPv6), NS (who is authoritative), SRV, CAA (who may issue certs)
TTL and caching
Every answer carries a TTL, how long it may be cached. We queried a name through a caching resolver and got three hundred seconds. Three seconds later the same query returned two hundred and ninety seven: the answer came from the cache and the TTL was counting down. This is why DNS changes are not instant: clients keep old answers until their TTL runs out. Before a migration, lower the TTL a day ahead.
$ dig api.shoprung.test api... 300 IN A 10.0.1.21 (3 seconds later) api... 297 IN A 10.0.1.21 TTL counts down in the cache a change is seen only after old TTLs expire lower TTL before a migration
Error answers
When something is wrong, read dig's status line. NOERROR means it worked, or that the name exists without that record type. NXDOMAIN means the name does not exist: a typo or a missing record. SERVFAIL means the resolver tried and failed, often a broken upstream or DNSSEC problem. REFUSED means the server will not answer you; our lab server refused names outside its zone because we gave it no upstream.
- NOERROR answer found (or the name exists with no record of that type)
- NXDOMAIN name does not exist
- SERVFAIL resolver could not get an answer (DNSSEC, upstream down)
- REFUSED server will not answer you (ours: no upstream configured)
Debugging
Debugging DNS means comparing answers. dig plus short gives just the result. dig at a public resolver tells you what the world sees. dig at your authoritative server tells you what you actually published. If those differ, it is caching. dig plus trace walks the delegation. And getent hosts shows what your application really gets, including etc hosts entries that dig ignores, a common source of confusion.
$ dig shoprung.com +short $ dig @1.1.1.1 shoprung.com $ dig @ns1.provider ... ask the authoritative $ dig +trace shoprung.com $ getent hosts shoprung.com what the app really sees (incl. /etc/hosts)
In clusters and clouds
In the cloud, Route fifty three hosts public zones and private zones visible only inside your VPCs, and the VPC resolver sits at the base address plus two. In Kubernetes, every service gets a name like service dot namespace dot svc dot cluster dot local, answered by CoreDNS; its default ndots of five makes external lookups try several search domains first. And cloud load balancers change IPs, so always point at their DNS name.
- AWS Route 53: public and private hosted zones
- VPC resolver at base + 2
- Kubernetes: svc.ns.svc. cluster.local via CoreDNS
- ndots:5 → extra lookups for external names
- load balancers change IPs: always use their DNS name
Common mistakes
Mistakes. Keeping a long TTL during a migration. A CNAME at the zone apex, which DNS does not allow; providers offer alias records instead. Hardcoding a load balancer's IP address. Testing with dig while the application reads etc hosts. And forgetting that NXDOMAIN answers are cached too, so querying a name before you create it can delay it.
- high TTL during a migration
- CNAME at the zone apex (use ALIAS/ANAME)
- hardcoding a load balancer's IP
- testing with dig, while the app reads /etc/hosts
- forgetting negative caching of NXDOMAIN
Say it like this
In the interview, the DNS part of what happens when you type a URL: the stub resolver checks etc hosts and its cache, then asks the configured recursive resolver. On a miss the resolver asks a root server, the TLD servers, then the domain's authoritative servers, and caches each answer for its TTL. To debug, I compare dig against the resolver and the authoritative server, and check TTLs.
- "The stub resolver checks
- /etc/hosts, then asks the recursive resolver. On a miss it
- asks a root, the TLD, then the authoritative server, and caches
- by TTL. I debug with dig against
- the resolver and the authoritative, and check TTLs."