How DNS Works
The phone book that everybody (including attackers) needs
DNS translates names to addresses through a hierarchy of resolvers and authoritative servers. It is the internet's most abused protocol — and a primary sensor for both attackers and defenders.
What you will learn
- Trace a full resolution from client cache to authoritative server
- Read and query A, AAAA, CNAME, MX and TXT records
- Explain DNS' role in attacks and how defenders use DNS logs
What is this?
DNS (Domain Name System) is a distributed database that maps human-friendly names to machine resources. A recursive resolver walks the delegation chain — root, TLD, authoritative — to answer 'what is the address of shop.example?'. Answers are cached with TTLs. Because every host depends on it and every name resolves through it, DNS is simultaneously a favorite attacker channel (tunnels, C2 fast-flux) and a rich defender signal.
Why do you need it?
- Attackers abuse DNS for command-and-control, exfiltration and phishing; DNS logs reveal those patterns.
- Most incidents start with a lookup — 'which domains did this host query?' is one of the first triage questions.
- Email security (SPF/DKIM/DMARC) and certificate validation all hang off DNS records.
- Knowing consumption (recursion) vs delegation (authoritative) is where a lot of DNS debugging goes wrong.
Mental model
Calling directory assistance
DNS resolution
You ask an operator (recursive resolver) for a business number. They check their notebook (cache), then call the business's regional office (authoritative nameserver) if needed, and hand you back the number. Your call then goes directly to the number.
How it works
- A client asks its configured recursive resolver for example.com's A record.
- The resolver checks its cache; a live answer respecting the TTL is returned without further queries.
- On a miss: resolver queries a root server, which points to the .com TLD servers.
- The resolver queries a .com server, which points to example.com's authoritative nameservers.
- The resolver queries the authoritative nameserver and receives the final answer, caches it, and returns it to the client.
- Record types: A/AAAA (IPv4/IPv6), CNAME (alias), MX (mail), TXT (arbitrary text, used for SPF/DKIM/DMARC and verification).
A full recursive resolution for example.com.
Key commands
dig +short example.comGet the A record the way clients see it.
dig @1.1.1.1 example.comQuery a specific public recursive resolver directly.
dig +trace example.comWalk the delegation chain yourself, root to authoritative.
dig example.com TXT +shortInspect TXT records used for SPF and verification.
In production
- A SOC sees an endpoint resolving a never-before-seen domain; SIEM correlation against a sinkhole/allowlist flags it as a C2 beacon before the connection fully establishes.
- An email security team checks that their domain's SPF/DKIM/DMARC records exist and are correct — missing TXT records mean forgery is trivially possible.
- A security engineer runs a local resolver on the lab network to sinkhole known-bad domains during malware analysis.
Best practices
- Log DNS queries and responses for your zones — passive visibility into every host's name activity.
- Pin high-value records (SPF, MX, AXFR) and alert on changes you didn't make.
- Use TTL deliberately: short TTLs let you respond fast to takedowns; long TTLs reduce load.
Common mistakes
- Confusing recursion (finding the answer) with authority (owning the zone) when debugging 'our DNS is broken'.
- Forgetting TTLs — a changed record can remain cached for hours, so 'we fixed it' still shows stale answers.
- Assuming a DNS query logged by an attacker means a successful connection; many probes are passive.
Debugging tips
- dig +trace first when an answer looks wrong — it shows exactly where the chain breaks.
- Compare your resolver's answer against a public resolver (dig @1.1.1.1) to isolate cache vs authority issues.
- For 'domain resolves but site fails', check whether the A record differs from what the app expects (CNAME chasing, geo DNS).
Security considerations
- DNS is not encrypted by default; DNSSEC validates authenticity, and DoH/DoT protect privacy.
- Zone transfer requests (AXFR) must be locked down — an open AXFR hands an attacker your entire network map.
- DNS tunnels look like innocuous lookups; for example a slow trickle of TXT queries to one domain is a classic exfiltration signal.
Interview checkpoint
Hands-on lab
- Walk the delegation chain from root to authoritative with dig +trace
- Compare your local resolver against public resolvers
- Inspect record types (A, AAAA, CNAME, MX, TXT) that matter to security
Trace a Full DNS Resolution Yourself
25 min · beginner
Quick quiz
Which entity actually knows the final answer for example.com's A record?
A shorter TTL on a DNS record makes changes propagate faster.