How does DNS resolve a domain name to an IP address?
MediumConceptDNS, HTTP & HTTPS
Answer
DNS (Domain Name System) translates names such as www.example.com into IP addresses. It is a distributed, hierarchical database: root servers point to top-level domain (TLD) servers such as .com, TLD servers point to each domain's authoritative servers, and authoritative servers hold the actual records.
- Your device sends the query to a recursive resolver, run by the ISP or a public service such as 8.8.8.8, which does the work on its behalf. The resolver queries root, TLD and authoritative servers iteratively, each one referring it to the next.
- Every answer is cached for its TTL (time to live) in the browser, the operating system and the resolver, so most lookups are answered from a cache within milliseconds.
- CDNs (content delivery networks) use DNS to return the address of a server close to the user.
Example: Looking up www.example.com with empty caches:
1. Browser and OS caches miss -> ask the recursive resolver
2. Resolver -> root server -> "ask the .com TLD servers"
3. Resolver -> .com TLD server -> "ask ns1.example.com"
4. Resolver -> ns1.example.com -> "www.example.com A 203.0.113.10 TTL 3600"
5. Resolver caches it for 1 hour and returns 203.0.113.10 to the browser