Opscraft
How DNS works behind the scenes · Lesson 9 of 9 · 3 min read

Interview questions and model answers

"Explain how DNS resolution works end to end."

The application asks the OS stub resolver, which checks /etc/hosts and local caches, then sends a recursive query to the configured resolver. On a cache miss, the resolver starts from the root hints and asks a root server, which refers it to the TLD's name servers; the TLD server refers it to the domain's authoritative name servers; the authoritative server returns the record. The resolver caches every step by TTL and returns the answer. The client's query is recursive; the resolver's queries are iterative. A warm cache short-circuits most of this.

"How many root servers are there?"

Thirteen root server identities, A through M, run by twelve organisations — but each is served by many anycast instances worldwide, well over a thousand sites in total, so queries reach a nearby instance.

"What's the difference between a recursive and an iterative query?"

In a recursive query the client asks for a final answer and the server does all the work — that's what stubs send to resolvers. In iterative queries the server answers with what it knows, often a referral to other servers — that's how resolvers talk to root, TLD and authoritative servers.

"dig resolves a name but the application can't. Why?"

dig queries DNS directly, while applications go through the system resolver: /etc/hosts entries, nsswitch order, search domains and ndots, a different resolver configured for the app, its own cache like the JVM's, or a browser using DNS over HTTPS. I'd compare with getent hosts, check /etc/hosts and resolv.conf, and the app's DNS settings.

"Pods resolve Services in their namespace but not another namespace's short name. Why?"

Short names only expand with the pod's own namespace search domain first. Another namespace's Service needs service.namespace or the full service.namespace.svc.cluster.local.

"Kubernetes DNS is slow and CoreDNS CPU is high. What do you do?"

Reduce query volume — the ndots:5 search expansion multiplies external lookups, so use FQDNs with trailing dots or lower ndots — deploy NodeLocal DNSCache to cache on each node and avoid the conntrack race, scale CoreDNS replicas and give them enough CPU, check for throttling at the VPC resolver's per-ENI packet limit, and look at CoreDNS metrics for SERVFAILs or slow upstreams.

"What is DNS cache poisoning and how is it prevented?"

Injecting forged records into a resolver's cache so users are sent to an attacker's server. It's mitigated by randomised query IDs and source ports, DNSSEC validation, and encrypted DNS between clients and resolvers.

"Why shouldn't you run an open recursive resolver?"

Because attackers use open resolvers for amplification DDoS — small spoofed queries generate large responses aimed at a victim. Recursion should be limited to your own clients.