Note: If you find any issues in the post, let me know in the comments section
This is a short post how DNS works. Prefer more comical learning, then go here - https://howdns.works/
So what happens when you type in a website address? User entered address https://vedhavyas.com. Browser needs to resolve this address to an public IP address.
- Browser cache
- Browser check its local cache for an IP address that maps to given website address
- If found, call the IP address to serve the request. Job done.
- If not found? Move to next step
- OS cache
- Browser asks os to resolve an IP from the address
- OS checks its cache. If found, let browser know about it
- Browser will save the ip to its cache and request is served
- If not found? Move to resolver
- Resolver cache
- OS will then ask the resolver for resolve the Address
- Resolver is your internet service provider resolver. This is how your ISP can track your internet activity. ISP such as ACT may even block the site by not resolving the address.
- So, how can you unblock it? You can use a different resolver instead of your ISP resolver. I prefer DNSCrypt. It provides a wide range of DNS resolvers to pick from.
- Now back to resolving request. Resolver will check its cache for the IP address. If found, return back to browser and request is served.
- If not found? Move to root name servers
- Root Name servers cache
- Every resolver should know at least one root name servers
- There are 13 root name servers around the world.
- Now root name server will search its cache for IP. If found, give it resolver
- If not found, it give resolvers the address of the Top Level Domain of the address to talk to. In our case its “.com” TLD, one of the largest TLD’s
- TLD cache
- If TLD has IP info of the address, gives it back to resolver
- If not, TLD will provide address of the name servers of the domain “Vedhavyas.com”
- In our case, TLD will provide the following name server address
- alex.ns.cloudflare.com
- cass.ns.cloudflare.com
- But how would TLD would know the name server address?
- Domain registrar. Whenever you buy a domain from a domain registrar, They communicate the name server details with the TLD
- My Domain registrar here is namecheap.com. This is where I provide them the custom name servers of cloudflare.com
- Else, namecheap.com will provide their own name servers
- Whats happens if the name server is a subdomain of the website we have asked for? Wouldn’t that be an infinite loop?
- Well, TLD provides name server address along with their IPs.
- So that resolver can directly talk to name server since those addresses are already resolved
- Why multiple name servers?
- Just in case one goes down :p
- Name Servers
- Name servers should know the IP address of the website, given website owner provided necessary details
- If not preset, then you will see a sad smiley on your browser saying failed to resolve the address.
- In our case, I have provided cloudflare.com required IP address of my website. Sometimes there can be multiple IP addresses as well. Just to in case ;p
- My IP address are “192.30.252.153”, “192.30.252.154”. These are IP addresses of GitHub.com server where my website is hosted
- Return
- Now resolver will cache all the necessary info during this trip to about any further trips
- The IP address is given to your browser and the website is served.