What is DNS?
DNS is the internet's phone book. Computers reach each other by IP address, like 203.0.113.10, but people remember names, like www.example.com. Before almost anything happens online, your device asks DNS to turn a name into an address.
No single server knows every name. The work is split into a tree: root servers know who runs each ending such as .com, those servers know who runs each domain, and each domain's own name server knows its addresses. Resolvers walk this tree for you and cache what they learn, which keeps it fast.
Think of it like this. Think of asking a hotel concierge for a restaurant's number. The concierge (the resolver) calls the city directory (root), which gives the number of the district office (.com), which gives the number of the restaurant (authoritative server). The concierge writes it down, so the next guest who asks gets it at once.
Step by step
Full lookup
5 stepsNobody has asked for www.example.com lately, so the resolver walks from the root down to the right name server.
Full lookup
5 stepsNobody has asked for www.example.com lately, so the resolver walks from the root down to the right name server.
- 1
Laptop asks the resolver
One question, one final answer wanted
Your laptop does not search the internet itself. It sends one question to the resolver it got from the network, usually your router or your provider, and sets the flag that says: find it for me.
- 2
Ask a root server
Who handles .com?
The resolver starts at the top. There are 13 root server names, a to m, each answered by hundreds of machines around the world. The root does not know www.example.com, but it knows who runs .com.
- 3
Ask the .com server
Who handles example.com?
The .com servers keep a list of every .com domain and its name servers. They point the resolver at the name servers that example.com's owner chose.
- 4
Ask the name server
The real answer
The authoritative name server holds the zone file for example.com. It answers with the address and sets the AA flag, which means this answer comes from the source, not a copy.
- 5
Answer and cache
Back to the laptop, saved for later
The resolver hands the address to your laptop and keeps every piece it learned. For the next hour it answers this name from memory, and for two days it remembers who runs .com.
Cached answer
2 stepsA few minutes later another device asks for the same name, and the resolver answers from memory.
Cached answer
2 stepsA few minutes later another device asks for the same name, and the resolver answers from memory.
- 1
Phone asks
Same name, different device
Daniel opens the same site on his phone. The phone has never looked it up, so it asks the resolver. Browsers often ask for the IPv4 (A) and IPv6 (AAAA) address at the same time.
- 2
Answer from cache
No trip to root, .com or the name server
The resolver still holds both records from earlier lookups. It answers in a few milliseconds and lowers the TTL by the time that has passed, so the record still expires at the same moment for everyone.
Name not found
3 stepsA typo in the ending (.cmo instead of .com) gets a firm no from the root: NXDOMAIN.
Name not found
3 stepsA typo in the ending (.cmo instead of .com) gets a firm no from the root: NXDOMAIN.
- 1
Typo in the address
www.example.cmo
Omar types the address too fast. The laptop does not know the name is wrong, so it asks the resolver like any other name.
- 2
Root says no
There is no .cmo
The resolver asks a root server. The root holds the full list of top-level domains and .cmo is not on it, so it answers NXDOMAIN (non-existent domain) with its SOA record as proof of who said so.
- 3
Laptop gets the no
The browser shows a not found page
The resolver passes NXDOMAIN to the laptop and remembers it for a while, so the same typo is answered at once next time. The browser shows an error such as DNS_PROBE_FINISHED_NXDOMAIN.
Myths and mix-ups
- There are not only 13 root servers: there are 13 names, each run as many copies around the world using anycast.
- DNS does not only use UDP: answers too big for one UDP reply are fetched again over TCP.
- Changing a DNS record does not need hours to spread; old copies simply live until their TTL runs out.
- Your resolver is not the same as the name server for a domain: one asks questions, the other holds the answers.
- Plain DNS is not private: anyone on the path can read which names you look up.
Try it yourself
Run these on your own computer to see DNS at work.
Look up an address
nslookup www.example.comWorks on Windows, macOS and Linux. Shows which resolver answered.
See the full answer
dig www.example.commacOS and Linux. Look for the flags line, the ANSWER section and the TTL.
Walk the tree yourself
dig +trace www.example.comStarts at the root and follows each referral, just like a resolver does.
Watch the TTL count down
dig +noall +answer www.example.comRun it twice a few seconds apart. The second TTL is lower because it came from cache.
Find a domain's mail servers
nslookup -type=mx example.comMX records tell other servers where to deliver email.
DNS at a glance
- Layer
- Application (7)
- Port
- 53
- Transport
- UDP, and TCP for large answers and zone transfers
- Common records
- A, AAAA, CNAME, MX, NS, TXT, SOA
- Root server names
- 13 (a to m), served by over a thousand machines
- Cache time
- Set per record by its TTL, in seconds
- Defined
- 1987 (RFC 1034 and RFC 1035)
Defined inRFC 1034RFC 1035
Header fields
What DNS puts in its messages, with example values from the stories above.
DNS
- Transaction ID
0x3f1cA random number. The answer must carry the same one, or it is thrown away.- Flags
0x0100 Standard query, recursion desiredRD=1: please do the whole hunt for me and come back with the final answer.- Questions
1- Answer RRs
0- Authority RRs
0- Additional RRs
0- Query
www.example.com, type A, class IN- Authority
com NS a.gtld-servers.net (and 12 more), TTL 172800172800 seconds is two days. The resolver can skip the root for .com names that long.- Additional
a.gtld-servers.net A 192.5.6.30Glue: the address of the next server, so the resolver does not need another lookup to find it.- Answer
www.example.com A 203.0.113.10, TTL 3600TTL 3600 seconds: anyone may cache this answer for one hour.
Test yourself
Which server does your laptop send its DNS question to?
Questions people ask
What is DNS in simple words?
DNS turns website names into IP addresses, the numbers computers use to find each other. It works like a phone book for the internet.
What port does DNS use?
Port 53, mostly over UDP. Large answers and zone transfers use TCP on the same port. Encrypted DNS uses 443 (DNS over HTTPS) or 853 (DNS over TLS).
Why does a DNS change take time to show up?
Resolvers keep copies of records until each record's TTL runs out. Lower the TTL a day before a planned change and the switch will be quick.
What is the difference between a DNS resolver and a name server?
A resolver asks questions for you and caches the answers. An authoritative name server holds the real records for a domain and answers questions about it.
How do I flush my DNS cache?
On Windows run ipconfig /flushdns. On macOS run sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder. Browsers keep a short cache of their own too.
What does DNS_PROBE_FINISHED_NXDOMAIN mean?
The browser asked DNS for the name and was told it does not exist. Check the spelling, or the domain may have expired.