All posts
Networking

DNS Internals and Security: Recursion, Caching, and Cache Poisoning

How DNS resolution really works under the hood — recursion, caching, TTLs — and how attackers poison caches, plus the defenses that stop them.

SKSushan Khadka
March 15, 2026 (5mo ago)4 min read
DNS Internals and Security: Recursion, Caching, and Cache Poisoning — article by Sushan Khadka (namelessnerd)

Every connection you make starts with a question nobody thinks about: what IP is this name? Get that answer wrong — or let an attacker forge it — and TLS, your firewall, and your good intentions all point at the wrong server.

DNS Internals and Security: Recursion, Caching, and Cache Poisoning - diagram by Sushan Khadka (namelessnerd)

How a name actually resolves

Your machine runs a dumb stub resolver. It hands the whole job to a recursive resolver, which does the real legwork. That recursor walks the tree top-down: ask a root server who owns .com, ask the TLD server who's authoritative for example.com, then ask the authoritative server for the actual record. Three hops, one answer.

It helps to name the players precisely, because the security story hinges on the distinction:

The record types you meet

A DNS answer is more than an IP. The common records:

That last category matters for security beyond resolution: SPF and DKIM records in DNS are what let a receiving mail server decide whether an email claiming to be from your domain is forged.

Why caching exists (and why it bites)

Nobody wants to re-walk the tree on every lookup, so resolvers cache answers for the length of each record's TTL. Short TTLs mean fresh data and more traffic; long TTLs mean speed but slow propagation when you change records — which is why a migration you shipped an hour ago is still sending some users to the old server. That cache is also the attack surface: poison one entry and every client behind that resolver inherits the lie until the TTL expires. One successful forgery, thousands of victims.

The Kaminsky race

Classic DNS rides UDP with no authentication, so the resolver simply trusts the first reply whose transaction ID matches its query. An off-path attacker — one who cannot even see your traffic — doesn't need to intercept anything. They just flood the resolver with forged replies, each guessing that 16-bit transaction ID, racing the real authoritative server's answer. Win the race once and you've planted a bogus record in the cache.

A 16-bit ID is only 65,536 possibilities, but the naive attack had a catch: if you guess wrong, the real answer arrives and gets cached, and you're locked out until its TTL expires. Dan Kaminsky's 2008 insight removed that limit. Instead of attacking www.example.com directly, he had the attacker query random non-existent subdomains — a1b2.example.com, x9z8.example.com — each of which forces a fresh lookup with no cached answer to wait on. In the forged reply, the attacker didn't just answer the subdomain; they smuggled in a malicious record for the whole domain's authoritative server. Unlimited fast retries turned a theoretical 1-in-65,536 guess into a practical few-second attack.

Shutting the door

None of these is a complete answer alone — DNSSEC authenticates but doesn't encrypt; DoH encrypts but doesn't prove the authoritative data is genuine. Layered, they cover each other's gaps.

The takeaway

Read more posts