In this guide
How a Domain Name Lookup Actually Works
You type example.com into a browser and hit Enter. Within a fraction of a second, the page loads. What happened in between is a quiet piece of distributed-systems machinery that nearly every developer relies on and very few can explain step by step: the Domain Name System, or DNS.
DNS is the phone book of the internet. Its only job is to answer questions like "what IP address does this name point to?" — but the way it answers is far more interesting than a simple lookup table. There is no central database of every domain on earth. Instead, thousands of servers cooperate to find the answer, starting from almost nothing and narrowing down hop by hop. Understanding that process pays off immediately: when a domain you just pointed at your VPS "isn't working yet," when an SSL certificate request fails its domain check, or when email to your project domain silently bounces, the answer almost always lives somewhere in this chain.
This guide traces one lookup end to end, explains the record types you will actually use, clears up recursion, caching, and TTL, and shows you how to debug all of it with dig — the tool DNS administrators reach for first.
The resolution chain: what happens when you type a URL
A full lookup involves four roles. Keep them distinct, because most confusion about DNS comes from blurring them together.
-
The stub resolver (your machine). Your operating system has a small DNS client, configured with one or more resolver addresses (check
/etc/resolv.confon Linux or your network settings on Windows/macOS). When your browser needsexample.com, the stub resolver sends a single question — "A record for example.com, please" — to a recursive resolver, and sets a flag that says "do all the work for me." It does not talk to any other server. -
The recursive resolver. This is the workhorse, and it is the server your device is configured to use — typically run by your ISP, your college network, or a public service like Cloudflare's
1.1.1.1or Google's8.8.8.8. It does the iterating: it walks down the DNS tree, asking each level where to go next, until it finds an authoritative answer. It also caches everything it learns, so the second question is far faster than the first. -
The root servers. DNS names read right-to-left as a hierarchy. The very top is the root, written as a bare dot. The resolver starts here, asking one of the root servers: "who handles
.com?" The root doesn't know aboutexample.com— it only knows which servers are responsible for top-level domains like.com,.org, and.in. There are 13 root identities (a.root-servers.netthroughm.root-servers.net), each backed by dozens or hundreds of real machines scattered around the world using anycast, so "asking the root" is fast no matter where you are. -
The TLD and authoritative servers. The root answers with a referral: the NS records of the
.comservers, plus their IP addresses ("glue records" so the resolver can actually reach them). The resolver then asks a.comserver: "who handlesexample.com?" and gets another referral — this time to the domain's authoritative nameservers, typically run by the DNS host where the domain's owner manages their records. Finally the resolver asks the authoritative server directly: "what is the A record forexample.com?" The authoritative server answers from its zone file, and the resolver caches the answer and hands it back to your machine.
So the chain is: stub resolver → recursive resolver → root (who runs .com?) → TLD servers (who runs example.com?) → authoritative server (what is its IP?). The resolver asks each level in turn; none of them knew the full answer on their own. The whole round trip usually takes tens of milliseconds, and for popular domains it takes near zero because some layer already cached the answer.
A concrete walkthrough
Here is what the resolver does for the very first query for example.com, assuming completely cold caches:
- Step 1. Your laptop asks its recursive resolver for
example.com's A record. - Step 2. The resolver asks a root server (from a built-in list called root hints): "A record for example.com?" The root replies: "Not my job — ask these
.comservers," and supplies their names and IPs. - Step 3. The resolver asks a
.comserver the same question. It replies: "Ask these nameservers — they are authoritative for example.com," with their IPs. - Step 4. The resolver asks the authoritative server. It answers: "example.com has address 93.184.216.34."
- Step 5. The resolver caches that answer (for however long the record's TTL says), returns it to your laptop, and your laptop caches it too. Your browser then opens a TCP connection to 93.184.216.34.
Notice the pattern: the client recurses (asks once, wants the full answer), the resolver iterates (asks many servers, each answering "here's who to ask next"). Every DNS lookup you have ever made followed some version of this walk.
Record types: the vocabulary of DNS
A zone file is just a list of resource records. Each record has a type, a name, a value, and a TTL. These are the types you will actually touch:
| Type | What it holds | Used for |
|---|---|---|
| A | IPv4 address, e.g. 93.184.216.34 |
Pointing a name at a server (the most common record) |
| AAAA | IPv6 address, e.g. 2606:2800:220:1:248:1893:25c8:1946 |
The IPv6 equivalent of A |
| CNAME | Another hostname, e.g. www.example.com → example.com |
Aliasing one name to another (never an IP directly) |
| MX | Mail server hostname + priority number | Telling the world where to deliver email for the domain |
| TXT | Free-form text | Domain verification (Google, SSL issuers), SPF anti-spam policy |
| NS | Hostname of a nameserver | Delegating a domain or subdomain to a set of authoritative servers |
| SOA | Zone admin info: primary server, contact, serial, timers | One per zone; marks the start of authority and sets default timers |
| SRV | Hostname + port + priority + weight | Locating services (SIP, XMPP, Minecraft servers) — includes a port, unlike MX |
| PTR | A hostname | Reverse DNS: mapping an IP back to a name, used by mail servers to sanity-check senders |
A few practical notes on the important ones:
- A vs AAAA. If you set only an A record, IPv6-only clients can't reach you; if you set only AAAA, most of the internet can't reach you. Real deployments set both.
- CNAME follows a chain. If
blog.example.comis a CNAME forexample.com, the resolver must then resolveexample.comtoo — a second lookup is folded into the first answer. You cannot put a CNAME at the apex (bareexample.com) because the apex must also hold SOA and NS records, and DNS forbids a CNAME sharing a name with any other record. Many DNS hosts offer "CNAME flattening" or ALIAS records that behave like a CNAME but are served as A records — a provider-specific workaround, not standard DNS. - MX never points at an IP. It must point at a hostname that itself resolves via A/AAAA. The priority number (lower = preferred) tells senders which mail server to try first.
- TXT is the Swiss-army knife. Certificate authorities ask you to publish a specific TXT record to prove you control a domain, email systems publish SPF/DKIM policies as TXT records, and services like Google Search Console verify ownership through them.
Recursion vs iteration, precisely
These two words are the source of endless confusion, so let's pin them down:
- Recursion = the client asks one server for the complete answer and waits. Your laptop's stub resolver always recurses — it asks the recursive resolver once and expects a final answer. The name "recursive resolver" comes from this: it accepts recursive queries.
- Iteration = a server answers with its best partial knowledge: either the answer (if it has it) or a referral to the next server down the hierarchy. Root servers, TLD servers, and authoritative servers iterate — they never do the whole walk for you. (Authoritative servers can also refuse recursion entirely; that's why you shouldn't point your laptop at one as its resolver.)
The everyday consequence: when someone says "my DNS is slow," they usually mean their recursive resolver is slow or far away — changing it to 1.1.1.1 or 8.8.8.8 is a common fix, because it changes which resolver does the iterating and caching for you.
TTL and caching: why DNS changes aren't instant
Every DNS record carries a TTL (time to live), in seconds — a promise that says "you may cache this answer for this long." Common values: 300 (5 minutes), 3600 (1 hour), 86400 (1 day). Caching happens at multiple layers:
- Your browser caches DNS briefly.
- Your OS caches (Windows has a DNS cache service; Linux distributions vary; macOS caches aggressively).
- The recursive resolver caches per-record until the TTL expires — this is the big one. A popular resolver may serve your record to thousands of users from cache without ever asking your authoritative server again.
- Some applications (Java's JVM, for example) do their own caching on top.
So when you change an A record, anyone whose resolver cached the old answer keeps seeing the old IP until that cache entry's TTL runs out. There is no such thing as DNS "propagating" across the internet — nothing pushes updates outward. Each resolver simply stops asking once its cached copy expires. This is why the universal advice before moving a site is: lower the TTL to 300 a day or two beforehand, make the change, then raise it again.
Negative caching deserves a mention too: when a resolver learns that a name does not exist (NXDOMAIN) or has no records of the requested type, it caches that failure as well — for a duration taken from the zone's SOA record (RFC 2308). So if you query a subdomain before creating it, some resolvers will remember the "doesn't exist" answer for a while. If you then create the record and it still "doesn't work," negative caching is a likely culprit, and it clears itself when the timer expires.
Debugging with dig: the one tool to learn
dig (domain information groper) is installed by default on macOS and Linux, and ships with Windows 10/11. It queries DNS directly and shows you exactly what the server said — no browser or OS cache in the way (well, it bypasses the OS cache by talking to a resolver itself, which is what you want). Learn these five invocations:
# Basic lookup: A record for a domain
dig example.com A +short
# See the full answer with TTLs and which server answered
dig example.com A
# Check mail routing
dig example.com MX +short
# Ask a specific resolver instead of your default
dig @1.1.1.1 example.com A +short
That last form is the debugging superpower: dig @8.8.8.8 and dig @1.1.1.1 let you compare what different resolvers see, which instantly tells you whether a problem is global or specific to your network's resolver.
For the full resolution chain, dig +trace performs the iteration itself, showing each referral from root to TLD to authoritative server:
dig example.com +trace
The output is long — you will see the root servers listed first, then the .com servers, then the authoritative answer at the end. When a lookup fails, run +trace and watch where the chain breaks: no answer from root means a network problem; a wrong referral at the TLD level means the domain's NS records are misconfigured; no answer at the authoritative level means the zone itself is wrong.
Two older companions: nslookup example.com (interactive-friendly, available everywhere, but its output hides details dig shows) and host example.com (terse one-line answers, great for quick checks). All three only ever query example.com-style real names — use your own domain when debugging your own setup.
DNS and your student projects: three places it matters
1. Pointing a domain at your VPS
You buy a domain from a registrar and rent a VPS with a static IP. To connect them, you log into your DNS host (often the registrar itself, or Cloudflare) and add:
- An A record for the apex (
example.com→ your VPS IPv4). - An AAAA record if your VPS has IPv6.
- Either an A record or a CNAME for
www(www.example.com→example.com).
Within the TTL window, the world resolves your domain to your server. If you front the VPS with Nginx serving multiple apps, the DNS side stays this simple — one A record — and Nginx routes by hostname internally (that's the reverse-proxy pattern, covered in the related guides below).
2. Getting an SSL certificate
Certificate authorities like Let's Encrypt must verify you control the domain before issuing a certificate. The HTTP challenge (placing a file on your web server) is most common, but the DNS-01 challenge works purely through DNS: the CA asks you to publish a TXT record at _acme-challenge.example.com containing a token it gives you. If the token appears in DNS, you must control the domain. This is the only challenge type that can issue wildcard certificates (*.example.com), and it's the method to know when your server isn't publicly reachable over HTTP.
3. Receiving email for your domain
Running contact@example.com needs MX records pointing at whoever handles your mail (Google Workspace, Zoho, or your own mail server), plus TXT records for SPF/DKIM so other servers trust your outgoing mail. The classic student mistake is pointing MX at an IP address — invalid; MX must name a hostname. The second classic mistake is forgetting the matching A record for that hostname.
5 common misconfigurations (and how to recognise them)
-
CNAME at the apex. You set
example.comas a CNAME to your hosting provider's hostname, and your email breaks or the zone refuses to save. Root cause: a CNAME cannot coexist with the apex's mandatory SOA and NS records. Fix: use A/AAAA records at the apex, or your provider's ALIAS/flattened record if they offer one. -
"Propagation" impatience. You changed an A record an hour ago and a friend across town still sees the old site. Root cause: their resolver cached the old record; the old TTL hasn't expired yet. Diagnose with
dig @1.1.1.1 example.comvsdig @8.8.8.8 example.com— different answers from different resolvers = caching, not a broken zone. Prevention: lower TTLs before planned changes. -
The missing trailing dot in zone files. In a raw BIND-style zone file,
wwwmeans "www.example.com." only if written with care — an unqualified name gets the zone origin appended, somail.example.comwritten without its trailing dot becomesmail.example.com.example.com. Managed DNS dashboards hide this from you, but the moment you edit a zone file by hand, the trailing dot is the thing that bites. -
Pointing records at the wrong target type. CNAME to an IP address (invalid — CNAME takes hostnames), MX to an IP (invalid — needs a hostname), or an A record pointing at a hostname instead of an IP. Dashboards often let you save these without complaint; the lookup just silently fails.
digthe record and read what it actually says. -
DNSSEC misconfiguration causing SERVFAIL. DNSSEC adds cryptographic signatures so resolvers can verify answers weren't tampered with. If you enable it at your DNS host but the DS record at your registrar doesn't match (or you move DNS hosts without updating it), validating resolvers reject your entire domain with SERVFAIL — your site vanishes for users of strict resolvers while looking fine to you. Rule: treat DNSSEC as all-or-nothing per domain, and update the DS record at the registrar every time you change DNS providers or re-sign.
FAQ
Why does my DNS change take so long to "propagate"?
Nothing propagates. Your old record had a TTL — say 86400 seconds (24 hours) — and every resolver that looked it up is entitled to keep serving the cached copy until that timer expires. The fix is planning: lower the TTL to 300 well before a migration, change the record, then raise the TTL back. And when diagnosing, compare multiple resolvers with dig @1.1.1.1 vs dig @8.8.8.8 to confirm it's caching, not a broken zone.
Can I use a CNAME for my root domain (example.com without www)?
Not in standard DNS. A CNAME cannot share its name with any other record, and the apex must carry SOA and NS records. Use A/AAAA records at the apex. Some providers offer ALIAS or "CNAME flattening" records that accept a hostname at the apex and serve resolved A records — convenient, but provider-specific.
Why does my site resolve on my phone but not on my laptop?
Different networks, different recursive resolvers, different caches. Your phone's carrier resolver may have already expired the old TTL while your home ISP's resolver hasn't — or your laptop's OS is serving a stale local cache (try ipconfig /flushdns on Windows). Query both resolvers explicitly with dig @<resolver-ip> to see who holds what.
What's the difference between a registrar, a DNS host, and a nameserver?
The registrar is the company you pay yearly to own the domain name. The DNS host is where you edit the zone's records (often the registrar, often Cloudflare). The nameservers are the actual servers answering queries for your domain — their hostnames are listed in NS records at the parent zone (e.g. .com) and must match what your DNS host serves. When these three disagree about who's authoritative, lookups break in confusing, intermittent ways.
Does DNS encrypt anything?
Classic DNS is plaintext UDP on port 53 — anyone on the path can see and tamper with queries. DNS-over-TLS (port 853) and DNS-over-HTTPS (port 443) encrypt the link between your device and your recursive resolver, which stops local snooping but doesn't change anything about the resolver-to-authoritative path. Encryption also doesn't authenticate the data — that's DNSSEC's job, and it's a separate layer.
Limitations and edge cases
- DNS was not designed to be secure. Classic DNS has no authentication: responses can be spoofed by anyone positioned to answer faster than the real server (cache poisoning, famously demonstrated by Dan Kaminsky in 2008). DNSSEC fixes authentication but not privacy; DoH/DoT fix privacy on the first hop but not authentication. Adoption of both remains partial.
- TTL is a promise, not a control. Some resolvers and ISPs cap or override TTLs — ignoring very low values, or clamping very high ones. You cannot force the whole internet to forget a record faster than the slowest cache.
- Round-robin DNS is not load balancing. Publishing multiple A records for one name rotates answers across clients, but there's no health checking: a dead server keeps receiving its share of traffic until you remove its record (and caches expire). Real load balancing needs a health-checked layer — a load balancer or anycast.
- Anycast complicates "where" questions. Root servers and big public resolvers use anycast, so "which server answered" depends on your network location. Debugging with
digshows you an answer path, not the answer path every user takes. - Captive portals and split-horizon DNS. College and hotel networks intercept DNS to show login pages, and corporate networks answer internal names differently from the public internet (split-horizon). If your domain resolves to a private IP on one network and a public IP on another, that's usually deliberate split-horizon — not a misconfiguration.
- DNS doesn't reach end to end. Your authoritative server can be perfect and users can still get wrong answers from a misbehaving middlebox, a poisoned cache, or a resolver that filters responses. When
dig +tracefrom your machine shows the right chain but the browser fails, suspect the local resolver or network —dig @1.1.1.1is the five-second test.