Names are for people
Computers on the internet reach each other by number. Every server has an IP address such as 203.0.113.10. People are bad at remembering numbers, and a site may change its number at any time, so we use names instead: example.com.
Something has to translate. Every time you open a site, send an email or start an app, the first thing your device does is ask: what is the address for this name?
The system that answers is the Domain Name System, DNS. It is often called the phone book of the internet. It is a phone book with no single copy, spread over millions of servers, that answers billions of questions a second.
Nobody has the whole book
No single server knows every name. Instead the knowledge is split up along the dots in the name, read from right to left.
www.example.com is three levels:
.com: the top-level domain. One organisation keeps the list of every name ending in.com.example: registered by its owner within.com.www: decided by that owner.
Each level only needs to know who is responsible for the level below it.
A lookup, step by step
Your browser needs the address for example.com.
Your computer asks a resolver
A resolver is a server that does the legwork for you. Your internet provider runs one, and so do several public services.
The resolver asks a root server
The root does not know the answer. It knows who runs
.com.The resolver asks a .com server
It does not know the address either. It knows which name servers the owner of
example.comhas registered.The resolver asks example.com's name server
This server holds the real records. It is called authoritative for the domain, and it gives the answer.
Three referrals, each one a level closer, and then the answer.
Why it is fast: everyone remembers
Asking four servers for every web request would be slow. So answers are cached at every level.
Each answer carries a time to live (TTL): the number of seconds it may be remembered. Until that runs out, nobody asks again.
Your browser needs the address for example.com.
Caching happens in several places, checked in this order:
- Your browser.
- Your operating system.
- Your home router.
- The resolver, which serves thousands of people and so has usually seen the name already.
Most lookups never get past the first two. The full walk to the root happens only when a name is new to everybody.
Example
Why changing DNS takes a while to spread
You move your site to a new server and update the record. Some visitors reach the new server immediately. Others go to the old one for hours.
Nothing is spreading slowly. The old answer is sitting in caches all over the world, each with its own countdown. Every cache switches when its copy expires.
That is why people lower the TTL to a minute or so a day before a planned move.
The kinds of record
A name can hold more than an address. The common record types:
| Type | Holds | Example use |
|---|---|---|
| A | An IPv4 address | example.com → 203.0.113.10 |
| AAAA | An IPv6 address | The same, for the newer address format |
| CNAME | Another name to look up | www.example.com → example.com |
| MX | The mail server for the domain | Where email for @example.com should go |
| TXT | Free text | Proving you own the domain, email anti-spam settings |
| NS | The domain's name servers | Used in the referrals above |
When DNS breaks
DNS is so basic that when it fails, everything seems to fail. Sites are "down" although their servers are running perfectly, because nobody can find their address. Engineers have a rueful saying for mysterious outages: it is always DNS.
Two more things worth knowing:
- Classic DNS is not private. The question "what is the address of this site?" travels unencrypted, so your network can see which names you look up even when the visits themselves use HTTPS. Newer options send DNS questions over an encrypted connection.
- DNS can spread load. One name can return several addresses, or different addresses to different parts of the world. That is one of the simplest forms of load balancing.
Your browser needs the address for example.com.
Key takeaways
- DNS translates names into IP addresses.
- No server knows everything. A resolver asks the root, then the top-level domain, then the domain's own name server.
- Each answer has a time to live and is cached by browsers, operating systems and resolvers.
- Because of caching, most lookups are instant, and changes take time to reach everyone.
- Records come in types: A and AAAA for addresses, CNAME for aliases, MX for mail.