Names, time and addressesApplicationRFC 1035

DNS: names to addresses

How example.com becomes an IP address your computer can connect to.

Ports and use: UDP and TCP 53

In one sentenceDNS is the internet's phone book: you give it a name, and it gives back the number to call.

Think of it like thisYou know your friend's name, not their phone number. DNS looks it up in the contacts for you.

Watch it happen

4 steps and 2 byte-by-byte decodes. Use the buttons or the arrow keys. Hover or focus a field to find its bytes.

  1. Your laptop
  2. DNS resolver
  1. Check the memory firstYour laptop to Your laptop
  2. Query: "What is example.com?"Your laptop to DNS resolver
  3. Response: "203.0.113.5"DNS resolver to Your laptop
  4. Connect and cacheYour laptop to Your laptop

Step 1 of 4 Check the memory first

Your laptop

Your browser and operating system check their caches. If example.com was looked up recently, they stop here.

Step 2 of 4 Query: "What is example.com?"

Your laptop → DNS resolver

Not cached, so your laptop sends a small UDP datagram to the resolver, usually run by your ISP or a public service.

DNS query 29 bytes

ab cd 01 00 00 01 00 00 00 00 00 00 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 00 01 00 01

FieldBytesWhat it means
Transaction IDab cdA random number. The answer must repeat it, so the laptop knows which question it belongs to.
Flags01 00Bit pattern 0x0100: this is a query, and "recursion desired" is set, so the resolver should do the full lookup.
Question count00 011 question.
Answer count00 000 answers.
Authority records00 00Zero here: used when a server points to another server.
Extra records00 00Zero here.
Name: "example"07 65 78 61 6d 70 6c 65Names are sent as labels. Each starts with its length: 07 means "7 letters follow".
Name: "com"03 63 6f 6dLength 3, then "com".
End of name00A zero length marks the end of the name.
Type00 011 means an A record, which holds an IPv4 address.
Class00 011 means the internet (IN). It is almost always 1.

Step 3 of 4 Response: "203.0.113.5"

DNS resolver → Your laptop

The resolver asks other DNS servers if it does not already know, then returns the answer with a time to live.

DNS response 45 bytes

ab cd 81 80 00 01 00 01 00 00 00 00 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 00 01 00 01 c0 0c 00 01 00 01 00 00 01 2c 00 04 cb 00 71 05

FieldBytesWhat it means
Transaction IDab cdA random number. The answer must repeat it, so the laptop knows which question it belongs to.
Flags81 80Bit pattern 0x8180: this is a response, recursion was desired and is available, and there is no error.
Question count00 011 question.
Answer count00 011 answer.
Authority records00 00Zero here: used when a server points to another server.
Extra records00 00Zero here.
Question (repeated)07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 00 01 00 01The question is copied back: example.com, type A, class IN.
Name (pointer)c0 0cc0 0c is a pointer meaning "same name as at byte 12", which saves space.
Type00 011: an A record.
Class00 011: internet.
Time to live00 00 01 2c300 seconds: how long your laptop may keep this answer before asking again.
Data length00 044 bytes follow, which is the size of an IPv4 address.
Addresscb 00 71 05203.0.113.5: the answer.

Step 4 of 4 Connect and cache

Your laptop

Your laptop saves the answer until its time to live runs out, then opens a TCP connection to 203.0.113.5.

Where you meet it

  • Every time you open a website, send an email or use an app, a DNS lookup happens first.
  • Moving a website to a new server: you change the DNS record and wait for the time to live to pass.
  • Email delivery: MX records say which servers accept mail for a domain.

Common mistakes

  • Changing a DNS record and expecting every user to see it at once. Caches keep the old answer until the time to live ends.
  • Blaming "the internet is down" when only DNS is failing: pinging an IP address works, names do not.
  • Forgetting that DNS is usually unencrypted, so others on the network can see which names you look up. DNS over HTTPS hides them.
  • Setting a very low time to live everywhere, which increases load and delay.

Try it yourself

Run these on your own computer and compare the output with the lesson above.

  • dig example.com A +noall +answerShows the answer and its time to live.
  • nslookup example.comWorks on Windows, macOS and Linux.
  • dig +trace example.comFollows the lookup from the root servers down.

Back to Network Lab

Addresses and values in the examples are made up for teaching (the 203.0.113.x range is reserved for documentation). Real traffic carries more options and details. Check the standard named above for the full rules.