TwiceToldby Develoker
ConceptsSystem designLabsCheat sheetsAbout

Develoker makes free tools for learning to build software. TwiceTold explains each idea twice, as an everyday analogy and the real thing; CloudArch lets you design cloud systems and put load on them.

About ยท Labs ยท Cheat sheets ยท Learning paths

All concepts ยท web ยท networking

DNS

The internet's directory. DNS turns names like www.shop.com into IP addresses by asking a chain of servers (root, top-level domain, authoritative) and caching every answer for a set time.

10 min3 animations

๐Ÿ–จ๏ธ Cheat sheet

Names and street numbers

You remember shops by name. But a letter can only be delivered to a street number. So when you want to visit www.shop.com, you ring the operator and ask for its number.

The operator doesn't have every number in the world. They know who to ask: head office knows which desk handles names ending in .com, that desk knows where the shop's own book is, and the shop's book has the real answer. The operator brings it back to you.

Resolving a name

Computers connect to IP addresses (93.184.216.34, or IPv6 like 2606:2800::1), not names. The Domain Name System maps one to the other, and it is split by the dots in a name, read from the right:

  1. Your device asks a recursive resolver (from your ISP, or a public one like 1.1.1.1 or 8.8.8.8).
  2. The resolver asks a root server, which refers it to the servers for the top-level domain (.com).
  3. The TLD server refers it to the authoritative nameservers for shop.com.
  4. The authoritative server returns the actual record.

Each step is a small UDP message on port 53. The resolver does the legwork, so your device asks one question and gets one answer.

Looking up a name5 steps
๐Ÿง’You๐Ÿ‘ฉโ€๐Ÿ’ผOperator๐Ÿ›๏ธHead office๐Ÿ—‚๏ธThe .com desk๐Ÿ“–Shop's own book
Press play and watch it happen!

Writing it down

Ringing around takes time, so the operator writes every answer down with a "good for one hour" note. Anyone else asking for the same shop gets the answer straight away. Your own phone keeps a little list too.

The catch: if the shop moves, people with old notes keep going to the old address until their hour is up.

Caching and TTLs

Every record carries a TTL (time to live) in seconds. Resolvers, operating systems and browsers all cache answers until the TTL runs out, which is why most lookups take a millisecond rather than tens of milliseconds.

It's also why DNS changes "propagate" slowly: nobody is told about a change, caches simply expire. Before moving a site, lower the TTL (say to 60 seconds) a day ahead, make the change, then raise it again.

Remembering answers5 steps
๐Ÿง’You๐Ÿ‘งYour neighbour๐Ÿ‘ฉโ€๐Ÿ’ผOperator๐Ÿ“–Shop's own book
Press play and watch it happen!

Different lines in the book

The shop's book has more than one kind of line: the street number, a nickname that says "look under this other name instead", where its post should go, and a notes column.

Record types

TypeHoldsExample
A / AAAAIPv4 / IPv6 addressshop.com โ†’ 93.184.216.34
CNAMEAn alias to another namewww.shop.com โ†’ shop.cdn.net
MXMail servers, with prioritiesshop.com โ†’ 10 mail.shop.com
TXTFree text: verification, SPF, DKIM, DMARCv=spf1 include:mail.net -all
NSAuthoritative nameservers for a zoneshop.com โ†’ ns1.host.net

CDNs often use CNAMEs, and their nameservers answer with an address near the person asking, which is how one name can lead people in different countries to different servers.

Kinds of records4 steps
๐Ÿง’You๐Ÿ“ฌPostman๐Ÿ‘ฉโ€๐Ÿ’ผOperator๐ŸฌBranch shop๐Ÿ“ฎShop's mailroom
Press play and watch it happen!
๐Ÿ”ง Going deeper

Security: classic DNS is unencrypted and unauthenticated, so anyone on the network path can see or forge answers. DNSSEC signs records so resolvers can check they're genuine; DNS over HTTPS (DoH) and DNS over TLS (DoT) encrypt the questions between your device and the resolver.

Debugging: dig www.shop.com shows the answer and its TTL; dig +trace www.shop.com walks the chain from the root, step by step.

๐Ÿงฉ Quick quiz

Quick quiz! 3 questions about DNS, told the same way as the story.
  1. The operator doesn't have every number in the world. Who do they ask first?
  2. The shop moves to a new street number. Why do some people keep going to the old one?
  3. A line in the shop's book says "look under this other name instead". What kind of line is it?
Answer every question to check.Passing marks DNS as done.
Got the hang of DNS? Mark it as done, and your paths show how far youโ€™ve got.

Saved in this browser.

๐ŸŒ How the web talksStep 1 of 5

Next on the path โ†’๐Ÿ“ฎ HTTP

๐Ÿ‘‰ Read next

  • ๐Ÿ“ฎHTTPOrdering from a shop by letter: you send a form, and the shop replies with a numbered slip.
  • ๐ŸชงAmazon Route 53The city information kiosk that tells visitors which branch of your shop to go to, following your rules.