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.
- Your laptop
- DNS resolver
- Check the memory firstYour laptop to Your laptop
- Query: "What is example.com?"Your laptop to DNS resolver
- Response: "203.0.113.5"DNS resolver to Your laptop
- 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
| Field | Bytes | What it means |
|---|---|---|
| Transaction ID | ab cd | A random number. The answer must repeat it, so the laptop knows which question it belongs to. |
| Flags | 01 00 | Bit pattern 0x0100: this is a query, and "recursion desired" is set, so the resolver should do the full lookup. |
| Question count | 00 01 | 1 question. |
| Answer count | 00 00 | 0 answers. |
| Authority records | 00 00 | Zero here: used when a server points to another server. |
| Extra records | 00 00 | Zero here. |
| Name: "example" | 07 65 78 61 6d 70 6c 65 | Names are sent as labels. Each starts with its length: 07 means "7 letters follow". |
| Name: "com" | 03 63 6f 6d | Length 3, then "com". |
| End of name | 00 | A zero length marks the end of the name. |
| Type | 00 01 | 1 means an A record, which holds an IPv4 address. |
| Class | 00 01 | 1 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
| Field | Bytes | What it means |
|---|---|---|
| Transaction ID | ab cd | A random number. The answer must repeat it, so the laptop knows which question it belongs to. |
| Flags | 81 80 | Bit pattern 0x8180: this is a response, recursion was desired and is available, and there is no error. |
| Question count | 00 01 | 1 question. |
| Answer count | 00 01 | 1 answer. |
| Authority records | 00 00 | Zero here: used when a server points to another server. |
| Extra records | 00 00 | Zero here. |
| Question (repeated) | 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00 00 01 00 01 | The question is copied back: example.com, type A, class IN. |
| Name (pointer) | c0 0c | c0 0c is a pointer meaning "same name as at byte 12", which saves space. |
| Type | 00 01 | 1: an A record. |
| Class | 00 01 | 1: internet. |
| Time to live | 00 00 01 2c | 300 seconds: how long your laptop may keep this answer before asking again. |
| Data length | 00 04 | 4 bytes follow, which is the size of an IPv4 address. |
| Address | cb 00 71 05 | 203.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.
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.