Workspace

DNS: from a name to an address

3 day streakD

DNS: from a name to an address

Before any connection, a name must become an address. Learn the resolution chain, why caches make DNS fast and stale at once, and what HTTPS records add in 2026.

BasicsLesson 3 of 716 min

The Domain Name System is a distributed database that maps names such as api.example.com to records such as IP addresses. No single server holds everything. Authority is delegated down a tree: the root knows who runs .com, the .com servers know who runs example.com, and example.com's own servers answer for its names.

Figure 3.1

One lookup, four servers, many caches

How a name is resolvedThe program asks the stub resolver, which asks a recursive resolver. On a cold cache, the recursive resolver asks a root server, then the .com servers, then the domain authoritative server, and returns the address, caching every answer for its TTL.Your programgetaddrinfo()Stub resolverOS cacheRecursive resolverISP or 1.1.1.1 · big cacheRoot servers“ask .com”.com servers“ask ns1.dnshost.net”AuthoritativeA 203.0.113.7 · TTL 300123456Steps 3–5 happen only on a cold cache. Warm lookups stop at step 2 or earlier.
Your program asks a stub resolver, which asks a recursive resolver. On a cold cache, the recursive resolver walks the tree: root, then the top-level domain, then the authoritative server. Every answer is cached for its TTL, so most lookups never leave the first or second box.

Record types you will meet

TypeHoldsExample
A / AAAAIPv4 / IPv6 addressapi.example.com A 203.0.113.7
CNAMEAn alias to another namewww CNAME example.cdn.net
MXMail serversexample.com MX 10 mail.example.com
TXTFree text, often verification"v=spf1 include:_spf.example.net ~all"
NSWhich servers are authoritativeexample.com NS ns1.dnshost.net
HTTPS / SVCBConnection hints: ALPN protocols, ports, address hintsHTTPS 1 . alpn="h3,h2"

Caching and TTLs

Every record carries a time to live in seconds. Resolvers cache the answer for that long. A TTL of 300 means a change can take up to five minutes to be seen by everyone, and longer when software ignores TTLs. Low TTLs make failover faster but send more queries; high TTLs are cheaper and slower to change.

dig.shShell
# Ask your configured resolver; note the TTL column and the query time
dig api.example.com

# Walk the delegation from the root yourself
dig +trace api.example.com

# See whether a site advertises HTTP/3 through an HTTPS record
dig cloudflare.com HTTPS +short

Run dig twice. The second answer usually shows a lower TTL and a query time near 0 ms: it came from cache.

Worked exampleWhat a cold lookup costs
Stub → recursive resolver
1 round trip to your ISP or a public resolver, ~10 ms
Recursive → root (often cached)
0 to 1 round trip
Recursive → .com servers (often cached)
0 to 1 round trip, ~20 ms
Recursive → authoritative
1 round trip, 20 to 100 ms

A cold lookup can add 50 to 150 ms before the first TCP packet. A warm one costs almost nothing, which is why a harness should reuse connections and let the OS cache.

Go deeperPrivate and modern DNS: DoH, DoT and HTTPS records

Classic DNS travels over unencrypted UDP port 53, so anyone on the path can see and alter which names you look up. DNS over TLS (port 853) and DNS over HTTPS wrap queries in encryption. Browsers commonly use DoH to a trusted resolver.

HTTPS records let a site advertise how to connect before the first packet: supported protocols such as h3, alternative ports, IP hints and keys for Encrypted Client Hello. A browser that sees alpn="h3" can try HTTP/3 on the very first connection instead of learning it from an Alt-Svc header after a TCP connection (Module 5).

Where you will meet it

Failover

Moving traffic to a standby region by changing DNS takes effect only as caches expire. Teams lower TTLs before planned migrations.

Service discovery

Kubernetes gives every service a DNS name. Misconfigured search domains can turn one lookup into five failed queries first.

Outage pattern

When a large DNS provider fails, sites that are perfectly healthy become unreachable, because nobody can find their address.

Words to know

Stub resolver
The small resolver in your OS that forwards questions to a recursive resolver.
Recursive resolver
A server that finds answers on your behalf by walking the DNS tree and caching results.
Authoritative server
A server that holds the true records for a domain.
TTL (DNS)
How long, in seconds, a record may be cached.

Check yourself

Answer out loud before you open each one.

What does a recursive resolver do on a cold cache?

It walks the delegation: root servers, then the top-level domain's servers, then the domain's authoritative servers, caching each answer.

Why might a DNS change take a long time to be seen?

Resolvers cache records for their TTL, and some clients cache longer than the TTL.

What does an HTTPS DNS record add?

Connection hints before connecting, such as supported protocols including HTTP/3, ports and address hints.

Try it

Run dig +trace on a domain you use daily. Count the servers involved, then run plain dig twice and compare the query times.

A good place to start

Explore a pattern

A little guidance

Start with a pattern, read through a problem, and mark it solved when the idea clicks. Save anything you want to revisit.

New tutorials are added one at a time. Your bookmarks and solved checkmarks stay in this browser.

Explore the roadmap