We all have been hearing this term “DNS” since the early days of our exposure to the Internet. I remember the first time I heard this term was when I was setting an IPV4 Address for my machine on our Hostel WiFi(yes, I was late!). This post will go through major concepts of DNS which will be useful for making your Networking concepts stronger or just reinforce your understanding about the topic.
Domain Name System(DNS) is analogous to the Address book of the internet. Imagine if you had to remember each person in your contact list by their phone number. That is a painful thought right there! Similarly, humans are not expected to remember the IP Address(Internet Protocol Address) of each website they want to visit. I want to type google(dot)com in my browser and it should just take me there. DNS is responsible for translating the domain names to IP Addresses so that whoever(browsers, programs interacting through Http, etc.) is accessing that domain can successfully do so.
All the devices connected to the Internet has a unique IP Address through which they are reachable. This is also the case with your favorite websites. So if you try to access google(dot)com it has to do through its IP Address which DNS will provide.
A diagram that depicts the flow of a request for DNS
The above diagram depicts the flow of a request from a DNS Name Resolution perspective, which we will try to decipher with the steps mentioned below. The numbers on the diagram represent a sequence of steps. We’re not going into the Networking Stack and Firewalls and everything, we’re gonna look at this purely from DNS perspective. Here’s a great post on that part if you’re interested.
The list of things on a broad level that happens when you try to access say www(dot)google(dot)com are as follows.
You type google(dot)com in a browser. It first goes to the DNS Server of your ISP. It returns with IP Address if it has that information. If the ISP DNS doesn’t have that address with it, it sends you back a reply with a Root DNS that might have that information.
Root DNS has information about which servers would hold information about your top-level domain. Your top-level domain would be .com, .org, .info etc. Root DNS returns the address of Top-level DNS which you will query further in the next step.
Now you will contact Top-level DNS querying it with google(dot)com. Top-level DNS would know where google(dot)com is but not where www(dot)google(dot)com is. www is just another subdomain to your main domain. It will return with the address of google(dot)com Second-level DNS which holds information about all subdomains of google(dot)com.
You will hit Second-level DNS Server with www(dot)google(dot)com and it will return you. the answer for www(dot)google(dot)com. This is what they call an Authoritative DNS Server. This one holds the DNS Resource records and is the source of truth.
Now when you hit the IP address you received, your ISP DNS server will cache the result so next time you hit the same domain, this whole trip won’t happen and will save time.
This system is not centralized and it is highly distributed. This whole process is called Name Resolution.
An interesting command which you can use on any Unix based system to find out the IP Address of a domain is nslookup. You can use it like
nslookup google.com.
Let’s look at some pointers on DNS Caching. DNS Caching is useful because servers that are closer to requesting clients can respond to DNS lookup requests faster than the actual Authoritative servers which hold the source-of-truth records. If a record you’re looking for is cached somewhere closer to your geographical location, then it can respond to it quickly without additional lookups.
Now, a natural question to ask is what are all the places can DNS lookups can be cached? Can it be cached on my browser itself? Or on another server? Let’s try to see what are all the locations where DNS records can be cached. We will go in order of closest to the farthest location where records are cached.
Browser
Yes! Modern web browsers can cache DNS records for a certain amount of time. Browser is one of the closest contact points when you access a domain and caching it in the browser helps. It is the first location that is checked for the requested record. In Chrome, you can go to chrome://net-internals/#dns to see the status of your DNS cache.
Operating System DNS Cache
Operating System caches DNS records. If browser cache doesn’t have it, the next and final local stop is OS-level cache.
Internet Service Provider(ISP) level DNS Cache
After your machine’s OS reverts that it doesn’t have the record you requested in its cache, the next stop is the ISP DNS Cache. Once your request reaches this layer, and ISP doesn’t have the record, it follows the whole flow we discussed earlier and when it gets the address, it caches it.
One important thing which is to be noted here is that you can override your local DNS entries in /etc/hosts file of your machine. Any mapping entry of domain to IP address added there will override the actual address of that domain.
DNS Servers will create “DNS Records” to provide information on a domain or hostname. Till now, we kind of assumed that a mapping between IP Address and a human-readable domain name is all that is there to DNS Records. We will explore what different kinds of DNS Records are there and how are they different and useful in their way.
There are other kinds of records like TXT Records, SRV Records, etc. which you can explore. The most important ones which you will need are discussed above.
To summarise, we covered what is DNS, what happens when you make a request, in the sense of DNS, what is DNS Cache, and what are different types of DNS Records. For any queries or suggestions, please reach out to me on LinkedIn or Email.
computers, dns, internet, networking, tech, technology — Jul 25, 2020
Made with ❤ and at Earth.