Pointer Walk

DNS: Turning Names into Addresses

You type a name and the internet needs a number. Four servers are asked in turn, and the answer is remembered so the next lookup is instant.

NetworkingBeginner9 min read

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

A lookup nobody has made recentlyInteractive
Your computer
Resolver
Root
.com
example.com

Your browser needs the address for example.com.

  1. 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.

  2. The resolver asks a root server

    The root does not know the answer. It knows who runs .com.

  3. The resolver asks a .com server

    It does not know the address either. It knows which name servers the owner of example.com has registered.

  4. 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.

The same lookup, rememberedInteractive
Your computer
Resolver
remembers: example.com
Root
.com
example.com

Your browser needs the address for example.com.

Caching happens in several places, checked in this order:

  1. Your browser.
  2. Your operating system.
  3. Your home router.
  4. 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:

TypeHoldsExample use
AAn IPv4 addressexample.com → 203.0.113.10
AAAAAn IPv6 addressThe same, for the newer address format
CNAMEAnother name to look upwww.example.com → example.com
MXThe mail server for the domainWhere email for @example.com should go
TXTFree textProving you own the domain, email anti-spam settings
NSThe domain's name serversUsed 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.
A lookup nobody has made recentlyInteractive
Lookup
Your computer
Resolver
Root
.com
example.com

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.

Your progress

Check your progress

0%

  1. Read the page50% of this page

    When you have gone through the page and its animations, tick it off.

  2. Take the quiz50% of this page

    7 questions, from easy to hard. Take it as often as you like: the questions change, and only your best score counts.

Saved on this device only. See all your progress