…Or one answer to the famous “what happens when you type an URL in your browser address bar and hit the Enter key” question.
Finally I thought I might as well figure this out and take some note, then I made the charming graph above with https://app.diagrams.net/ (sorry I still typed draw.io in my browser address bar and watched it redirected).
So, what exactly happened after I hit the Enter key?
- My browser looks at its DNS cache to see if it’d been there before and knew the IP address mapped to it. Let’s say it didn’t.
- My computer also looks into its local DNS cache to see if it knows an IP address mapped to that domain. Nope.
- My home router comes in to try its local DNS cache. Still no luck.
- We go out to ask my ISP’s DNS server if that domain is in its cache. Sorry it is not there, but that recursive DNS server can help us resolve it.
- The resolver goes to ask the root name servers about the domain name, let’s say it is example.com
- Root name servers know all the TLD (top level domain) name servers. Since we came with a .com domain, it forwards our query to one TLD name server that handles .com domains.
- The .com TLD name server knows the authoritative name server who stores DNS record for the domain example.com so it forwards the query ahead.
- The authoritative name server respond with an A record (address record which is an IP address) mapped to the domain name.
- The IP address was then passed all the way back to our browser, each one in between who has a DNS cache will cache it on the way so next time when we or someone else asks about example.com, the answer comes faster.
- Browser opens a TCP/IP connection to the IP address, which is the address of the server hosting example.com, then sends an HTTP request. If the server is up and running, it sends back HTTP responses to our browser.
That’s the DNS lookup journey in the unfortunate case where the record is not available in any middle stop’s DNS cache.
Of course, it can get more complicated if there was DNS redirect in play. At step 8, the authoritative name server might see an Alias record or a CNAME record (canonical name) mapped to the queried domain.
In the case of an Alias record, the authoritative name server goes on to chase down the mapped domain name until it can get back an IP address for you.
In the case of a CNAME record, the authoritative name server simply respond with the mapped “canonical name”. Say we asked for foo.example.com and it’s a CNAME record which points to the canonical name bar.example.com, we will get back the latter and then start another DNS lookup journey with it.