Networking
DNS — Domain Name System
Almost every other page in this domain starts from an IP
address already in hand. DNS is the step before that step — the lookup that turns a name a human
can remember (example.com) into the numeric address IP
actually needs, run automatically, invisibly, before nearly every connection on the internet.
- What it is
- The distributed lookup system that translates human-readable domain names into IP addresses.
- Mental model
- A phonebook: you know a name, DNS looks up the number — except the phonebook is split across thousands of independently-run servers instead of one big book.
- Key numbers
- Port 53; mostly UDP (falls back to TCP for large responses).
- Reach for it when
- Never directly — it runs automatically the instant any application connects to something by name instead of by raw IP address.
Why names instead of just addresses
An IP address can change — a server gets migrated, a site moves to a new host, a home internet connection gets a new address from its ISP. A domain name stays stable through all of that, as long as its DNS records are updated to point at the current address. Names are also simply easier for a human to remember, type, and trust than a string of numbers.
The domain hierarchy
A domain name reads right to left as a hierarchy, most general to most specific — the opposite direction from how it's typically read aloud:
- Root
- The unnamed top of the entire system — represented by the invisible trailing dot in
example.com.. - TLD (Top-Level Domain)
.com,.org,.io— the first real level, managed by a registry for each one.- Domain
exampleinexample.com— registered by an individual or organization.- Subdomain
wwworapiinwww.example.com— created freely by whoever controls the domain, no registration needed.
Resolving a name, hop by hop
Looking up a name for the first time is a chain of "who do I ask next" hops, each server referring the resolver one level further down the hierarchy:
Record types
- A
- Maps a name to an IPv4 address.
- AAAA
- Maps a name to an IPv6 address.
- CNAME
- An alias — points one name at another name, which is then resolved in turn.
- MX
- Which server handles email for this domain — the record SMTP looks up before delivering a message.
- TXT
- Arbitrary text — commonly used for domain ownership verification and, notably, the SPF/DKIM records SMTP's own gotchas mention as the fix for outbound mail landing in spam.
- NS
- Which servers are authoritative for this domain — the record a TLD server hands back to point the resolver at the right place.
Caching and TTL
Every DNS record carries a TTL (Time To Live) — how many seconds a resolver is allowed to keep reusing that answer before asking again. This is why most lookups are fast: the four-hop chain above only happens once per TTL window, not on every single request. It's also why changing a DNS record isn't instant — every resolver that already cached the old answer keeps serving it until that cached copy's TTL expires, which is why DNS changes are described as "propagating" rather than taking effect immediately.
Real-world applications
- Every web and app connection — a browser, an IoT device's cloud check-in, an API client — all resolve a name before opening a single TCP or UDP connection.
- CDN geo-routing — a CDN can return a different IP address depending on where the resolver's request came from, routing users to the nearest data center without the application knowing anything changed.
- Service discovery — some systems use DNS itself (including special record types like SRV) as a lightweight way for services to find each other by name rather than hardcoded IPs.
- Load balancing via DNS — returning multiple A records for one name lets clients spread load across several servers before any smarter load balancer is even involved.
Gotchas
- "The internet is down" is extremely often actually "DNS is down" — a device that can successfully
pinga raw IP address but can't reach anything by name has a DNS problem, not a connectivity problem; this is one of the first things worth checking. - A DNS record change doesn't take effect everywhere at once — a low TTL set before a planned change (so old caches expire quickly) is a standard practice ahead of migrating a service to a new address.
- DNS queries are, by default, neither encrypted nor authenticated — DNS spoofing/cache poisoning (tricking a resolver into caching a wrong answer) is a real attack class; DNS-over-HTTPS (DoH) and DNS-over-TLS (DoT) exist specifically to close the unencrypted-query gap, layering DNS on top of TLS.