How DNS works?

DNS(Domain Name System) saves you from memorizing long IP addresses for different domains. It maintains records which maps these IP addresses into human-friendly names. For example, 172.64.146.196 the IP for ChatGPT’s server but you don’t need to remember the IP**** you can simply type chat.com which gets mapped to the respective IP address.
Above diagram shows a high level overview of how DNS works, but there’s a lot going on under the hood. In this article we will understand how the flow goes from the domain request to actual repsonse from the server.
Few components of DNS that you need to know before we actually understand the flow:
DNS Resolver
It is a DNS server responsible to provide IP of requested domain to your OS.
Your ISP manages these DNS Resolvers and provides you services to resolve your domain names to a specific IP address.
Your OS have the IP address of DNS Resolver(obtained via DHCP) which is by default the IP of DNS provided by your ISP. But you can configure it manually to use any third party DNS like the one provided by google(8.8.8.8) or cloudfare(1.1.1.1).
Google’s DNS Resolver has a unique IP address - 8.8.8.8, but that doesn’t mean there is physically one server reponsible to handle all the requests. Google hosts multiple DNS, It uses anycast to recieve request on the same IP, but your request actually goes to the DNS hosted nearest to you.
Some popular DNS tools - BIND, UNBOUND, dnsmasq, etc.
Root DNS [.]
These are the root DNS servers which holds addresses for the TLDs(Top Level Domain Servers).
There are around 13 Root DNS(virtually, there may be many more physically) A-M maintained by different orgzanizations -
- You DNS resolver holds a list of these Root DNS servers.
New Root DNS servers are rarely added and their IPs remain almost constant.
Top Level DNS (TLD) [.com, .org, .net…]
These DNS servers holds records for Authoritative DNS servers.
They are also maintained by different organizations like .com and .net are managed by Verisign, .org by Public Interest Registry (PIR), .in by NIXI (India), etc.
They fall into 3 major types:
gTLDs (Generic): .com, .net, .org, etc.
ccTLDs (Country Code): .in, .us, .uk, etc.
Sponsored/Brand TLDs: .edu, .gov, etc.
If a new TLD needs to be added for eg. .dev, an application needs to be submitted to ICANN which reviews and accepts it. Then it gets forwarded to IANA, which updates it into root zone file and propagates to all Root DNS operators. Similary, a request is submitted to IANA when a new TLD server is added for an existing domain.
Authoritative DNS [google.com, chat.com,…]
These are the servers which actually holds the IP addresses of your domains.
They are usually maintained by your domain registrar like goDaddy, DigitalOcean, Namecheap, etc.
If you register a domain via a registrar, it provides you a Authoritative DNS server which keeps the IPs of your domain. It also registers your domain with TLD servers. You can manually add or update DNS records for your domain or subdomains. These records may take some time to propagate due to TTL set in the DNS Resolvers. DNS Resolvers keeps using the old cached IPs until a specific amount of time(TTL) after which a new request is made.
So, when you type chat.com in your browser, following things go on in your system:
Browser looks for the IP corresponding to chat.com in it’s cache, if not found, it asks the OS for the IP.
OS looks into its cache, if IP isn’t present in the cache it looks for the IP of DNS Resolver in config provided via DHCP and forwards the request.
Now DNS Resolver looks for the IP in it’s cache, failing which it picks IP of a Root DNS server from named.root file configured inside it and redirects the request to Root DNS server.
Root DNS looks for the Top Level domain records and returns a list of IP addresses corresponding to TLD servers for that particular domain(.com).
DNS Resolver gets the list of TLDs, it then sends the request to the nearest TLD.
TLD looks into its records and sends the IPs of authoritative servers holding records of the targeted domain(chat.com).
DNS Resolver gets the list of Authoritative server and sends the request to get actual IP.
Authoritative server looks into its records to get the IP of domain requested and returns it to DNS Resolver.
DNS Resolver then returns it to your OS which in turn gives it to browser and browser sends request to the intended IP.
Browser recieves the response and displays it.
Subscribe to my newsletter
Read articles from Payal Rathee directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
