DNS (Domain Name System) translates a host name such as www.example.com into its IP address using a distributed hierarchy of servers (root, TLD and authoritative), contacted by a local (recursive) resolver.
DNS hierarchy
. (root servers)
/ | \
.com .org .in (TLD servers)
| |
example.com ac.in (authoritative servers)
|
www.example.com
Steps in resolving www.example.com
Browser/Host Local DNS resolver
| 1. query ------------------> |
| | 2. ------> Root server
| | 3. <------ "ask .com TLD"
| | 4. ------> .com TLD server
| | 5. <------ "ask ns.example.com"
| | 6. ------> Authoritative server
| | 7. <------ IP = 93.184.x.x
| 8. <------ IP address ------- |
9. Browser connects to the IP
- The user types www.example.com. The host first checks the browser cache, OS cache and hosts file. If not found, the stub resolver sends a query to the local DNS server (ISP or configured resolver, e.g. 8.8.8.8).
- If the local server has no cached answer, it asks a root server.
- The root server does not know the IP but replies with the addresses of the .com TLD servers (a referral).
- The local server queries a .com TLD server.
- The TLD server replies with the address of the authoritative name server for example.com.
- The local server queries the authoritative server.
- The authoritative server returns the A (IPv4) or AAAA (IPv6) record.
- The local server caches the answer for its TTL and returns it to the host.
- The browser opens a connection to that IP address.
Recursive vs iterative. The host-to-local-server query is recursive (the local server must return the final answer). The local server's queries to root, TLD and authoritative servers are iterative (each returns a referral).
Other points: DNS normally uses UDP port 53 (TCP for large responses and zone transfers); caching at every level reduces load and delay; common record types are A, AAAA, CNAME, MX, NS, PTR (reverse lookup).