DNS Explained: How a Domain Name Becomes an IP
DNS resolves a name to an address through a chain of servers. Learn the record types, the caching, the TTL, and how to debug a lookup.
By Velloreth
What DNS does
DNS maps a name to an address.
blog.example.com → 203.0.113.10
Without it, a user would type an IP address, and a change of host would break every link.
It is a distributed database, with no single server holding every record. The answer is assembled through a hierarchy.
The resolution chain
Browser
│
├─ 1. Local cache (OS, browser)
│
├─ 2. Recursive resolver (your ISP or 1.1.1.1)
│ │
│ ├─ 3. Root server → "ask the .com server"
│ ├─ 4. TLD server → "ask example.com's nameserver"
│ └─ 5. Authoritative → "203.0.113.10"
│
└─ 6. Answer cached for the TTL
The recursive resolver does the work on your behalf, and it caches the answer.
The root servers know where each top-level domain is.
The TLD servers know which nameservers are authoritative for a domain.
The authoritative nameserver holds the actual records.
A typical lookup is one query, because the resolver has the answer cached. A cold lookup is four.
The record types
| Type | Purpose |
|---|---|
A | Name → IPv4 address |
AAAA | Name → IPv6 address |
CNAME | Name → another name |
MX | Mail server |
TXT | Arbitrary text, used for verification and SPF |
NS | The authoritative nameservers |
SOA | The zone’s metadata |
CAA | Which certificate authorities may issue a certificate |
SRV | A service location |
An A record is the one that serves a website.
A CNAME is an alias. It cannot coexist with another record at the same name, which is why the apex of a domain usually cannot be a CNAME.
A TXT record is used for a domain verification and for an email policy such as SPF and DKIM.
The TTL
The TTL is the number of seconds a resolver may cache the answer.
blog.example.com. 300 IN A 203.0.113.10
A low TTL (300 seconds) means a change propagates in five minutes, and it produces more queries.
A high TTL (86400 seconds) means fewer queries and a slower change.
The practical approach: use a moderate TTL such as 3600, and lower it to 300 a day before a planned migration, then raise it again.
A DNS change is not instant. The old answer is cached until its TTL expires, which is why a migration is planned rather than done at the last minute.
Caching layers
The browser caches a resolved address for a short time.
The operating system caches it, and the TTL applies.
The recursive resolver caches it, and this is the layer that matters most.
A CDN may resolve the name to a nearby edge address, which is why the same name can return a different address in a different country.
Flushing the local cache:
# macOS
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
# Linux (systemd)
sudo resolvectl flush-caches
# Windows
ipconfig /flushdns
Debugging a lookup
# The basic lookup
dig blog.example.com
# A specific record type
dig blog.example.com MX
# A specific resolver
dig @1.1.1.1 blog.example.com
# The full chain
dig +trace blog.example.com
# A short answer
dig +short blog.example.com
dig +trace shows the whole chain from the root, which is the fastest way to find where a delegation is wrong.
nslookup is the older tool, and it is available on Windows.
The ANSWER SECTION shows the record and its TTL, which tells you how long the answer will be cached.
Common problems
A change is not visible. The old answer is cached. Check the TTL, and query the authoritative nameserver directly.
dig @ns1.example.com blog.example.com
If the authoritative server has the new answer, the problem is a cache, not the record.
A CNAME at the apex. Most providers do not allow it, because the apex must have an SOA and NS records. Use an ALIAS or a flattened CNAME if the provider supports it.
A missing AAAA record. A site with an AAAA record but no IPv6 service is unreachable over IPv6, which is worse than having no AAAA record at all.
A wildcard that is too broad. A * record catches a typo and serves the site at a name that should not exist.
A dangling CNAME. A CNAME to a name that no longer exists is a takeover risk, because an attacker can claim the target.
DNS and email
The same records that route a website also route email, and the two are often confused because they share a zone. An MX record names the mail server for a domain, and a TXT record carries the policy that says which servers are allowed to send on its behalf. SPF lists the permitted senders, DKIM publishes a public key that signs a message, and DMARC says what to do with a message that fails both. A domain that publishes a website but no email policy is a common source of spoofed mail, and the fix is three TXT records rather than a change to the hosting. The practical point is that a DNS change for a website and a DNS change for email are separate records in the same zone, so a migration that moves the A record should leave the MX and TXT records alone, and a migration that moves the nameservers should copy them first.
Practical guidance
- Use a moderate TTL, and lower it before a migration.
- Query the authoritative server to confirm a record.
- Use
dig +traceto find a delegation problem. - Do not put a CNAME at the apex.
- Add an AAAA record only if IPv6 works.
- Avoid a broad wildcard.
- Remove a dangling CNAME.
- Flush the local cache when debugging.
- Remember a change is bounded by the TTL.
For the related guides, see how-cdns-actually-work and http-status-codes-explained. For the broader context, cloudflare-pages-vs-github-pages-vs-vercel-netlify and create-ssh-key-add-to-github.
Quotable summary
DNS resolves a human-readable name to an IP address through a hierarchy of servers, with a recursive resolver doing the work and caching the answer. An A record maps a name to an IPv4 address and an AAAA record maps it to an IPv6 address, while a CNAME aliases one name to another and cannot coexist with other records at the same name. The TTL controls how long a resolver caches the answer, which determines how fast a change propagates, so a DNS change is not instant because the old answer is cached until its TTL expires. To debug a lookup, query the authoritative nameserver directly, because if it has the new answer the problem is a cache rather than the record, and use dig +trace to find where a delegation is wrong.