Understanding Domain Name System (DNS)
In this blog, we'll understand what is DNS and why is it a crucial part of the internet infrastructure. We'll also see how DNS enables smooth communication between devices on the internet.
The Domain Name System, also known as DNS, is a crucial part of the internet infrastructure that allows users to access websites and other online services using easily recognizable domain names rather than the IP addresses of the servers hosting these services.
In this blog, we will dive deep into the functioning of DNS including how it works, its components, and its role in enabling smooth communication between devices on the internet.
What are domain names?
Before we dive deeper into understanding about the DNS and how DNS resolution works, let's quickly review what a domain name means.
Domain names are human-readable names that are used to identify and access websites and other online resources on the internet. They are easier to remember and more user-friendly than IP addresses.
Now, you may ask what are IP addresses? An IP Address is nothing but an address of a machine on the internet. It is made up of a sequence of numbers, which looks something like 123.56.8.2
Addresses like these are numerical identifiers used by computers and other devices on the internet to identify each other and therefor, easily communicate with each other.
But remembering such a sequence of numbers, for each website that we want to visit, isn't really feasible for humans. That's where domain names come to our rescue. Domain names are much more human readable and easy to remember for humans.
Domain names typically consist of two or more parts separated by dots, such as "smartutr.com". The part after the last dot indicates the top-level domain (TLD), such as .com, .org, .net, and so on, while the part before the TLD represents the second-level domain, such as "smartutr".
Domain names are registered and managed by organizations called domain name registrars, and they must be unique to ensure that there is no conflict between different websites and resources on the internet.
Since remembering domain names is much easier for us, than the actual IP address, so we give the domain name, of the website that we want to visit, to our web browsers.
The web browser under the hood converts (or resolves) this domain name to the actual IP address of the server using a system called Domain Name System (DNS), which we will talk about in the next sections of this blog.
What is DNS?
The Domain Name System is a hierarchical decentralized naming system for computers, services, or other resources connected to the internet.
The primary function of DNS is to translate human-readable domain names into IP addresses that computers and other devices on the internet can use to identify and communicate with each other.
DNS is a distributed database system that is spread across the internet and is responsible for resolving domain names to IP addresses. The DNS infrastructure comprises of a set of interconnected servers that are responsible for storing and serving up information about domain names.
DNS architecture
To get a better understanding of how does DNS help in identifying IP addresses for any given domain name, we first need to undersand the architecture of DNS.
The DNS architecture can be divided into three main components: the client, the recursive resolver, and the authoritative nameserver.
The DNS Client
A DNS client is any device that is attempting to access a website or other online service using a domain name. For most cases, the client would be your web browser.
Whenever you type any domain name into the address bar of your browser, it acts as a DNS client and communicates with the DNS server to figure out the correct IP address to talk to.
Recursive Resolver
A recursive resolver is a server that receives a query from a dns client.
It performs a series of iterative queries until it obtains the IP address corresponding to the requested domain name.
Recursive resolvers are often operated by internet service providers (ISPs), but there are also many public recursive resolvers available that anyone can use.
Authoritative Nameserver
An authoritative nameserver is a server that holds the authoritative information about a particular domain name.
When a recursive resolver sends a query to an authoritative nameserver, the authoritative nameserver responds with the IP address associated with the requested domain name.
DNS resolution process
Now that we know the basic components of DNS, let's see how these components work together when requested to resolve a domain name.
When a user types a domain name into their browser, the following steps are taken to resolve the domain name to an IP address:
- The client (user's web browser) sends a query to the recursive resolver, asking for the IP address associated with the requested domain name.
- If the recursive resolver has the IP address of the requested domain name in its cache, it returns the IP address to the client. If not, the recursive resolver sends a query to the authoritative nameserver for the domain name.
- The authoritative nameserver receives the query from the recursive resolver and checks its database for the IP address associated with the requested domain name.
- If the authoritative nameserver has the IP address, it returns the IP address to the recursive resolver. If not, the authoritative nameserver sends a referral response to the recursive resolver, providing the IP address of another authoritative nameserver that might have the IP address of the requested domain name.
- The recursive resolver repeats step 3 and step 4 until it obtains the IP address associated with the requested domain name. Once the recursive resolver has the IP address, it stores the information in its cache and returns the IP address to the client.
Understanding DNS Resolution with a simple example
When you type a website address, such as "smartutr.com," into your web browser, the first thing that happens is local cache query. The web browser checks it's own cache and the cache of the OS to see if it already knows the IP address of the given domain name.
If it finds the domain name in local cache, then the DNS resolution finishes right there, without even communicating with the DNS servers. And the browser can start contacting the server using the IP address stored in the local cache.
If your computer doesn't know where to find the website. Then it sends a request to a special type of server called a recursive resolver.
The recursive resolver starts by looking in its own cache to see if it already knows the IP address for "smartutr.com". If it doesn't, it sends a request to a root nameserver.
The root nameserver already knows the addresses of all the nameservers corresponding to each Top Level Domain(TLD) like .com, .net, .in etc.
In our example the TLD is .com so the root nameserver responds with a referral to a TLD (Top Level Domain) nameserver for the .com domain.
The recursive resolver then sends a request to the .com TLD nameserver, which responds with a referral to the authoritative nameserver for "smartutr.com". The authoritative nameserver finally responds with the IP address for "smartutr.com".
The recursive resolver then stores the IP address in its cache and sends it back to your computer, which can then connect to the website.
In short, domain name resolution is the process of translating human-readable domain names into IP addresses that computers can use to connect to websites and other online resources. This process involves multiple servers, starting with a recursive resolver and moving up the hierarchy of servers until the authoritative nameserver for the requested domain provides the IP address.
DNS record types
DNS contains different types of records that store information about a domain name. The following are some of the common DNS record types:
- A record: An A record maps a domain name to an IPv4 address.
- AAAA record: An AAAA record maps a domain name to an IPv6 address.
- MX record: An MX record maps a domain name to a mail server that is responsible for handling email for the domain.
- CNAME record: A CNAME record maps one domain name to another domain name.
- NS record: An NS record specifies the authoritative nameservers for a domain.
- SOA record: An SOA record provides information about the zone that a domain belongs to, including the primary nameserver for the zone.
DNS caching
DNS caching is the process of storing the results of a DNS query in a recursive resolver's cache so that subsequent requests for the same domain name can be served faster. When a recursive resolver receives a query for a domain name, it first checks its cache to see if it has the IP address for the domain name. If the IP address is present in the cache, the resolver returns the cached IP address to the client.
DNS caching is an essential part of DNS, as it reduces the load on authoritative nameservers and improves the performance of DNS queries. However, it can also lead to problems if the cache becomes stale, as the resolver may return an outdated IP address for a domain name.
To prevent stale cache entries, DNS records have a Time to Live (TTL) value, which specifies how long a resolver can cache the record before it expires. When the TTL value for a record expires, the resolver must perform a new query to obtain the current IP address for the domain name.
Conclusion
In conclusion, DNS is a critical component of the internet infrastructure that enables users to access websites and other online services using easily recognizable domain names. It works by translating human-readable domain names into IP addresses that computers and other devices on the internet can use to identify and communicate with each other.
DNS operates through a hierarchical decentralized naming system, comprising a set of interconnected servers that are responsible for storing and serving up information about domain names. DNS resolution involves a series of iterative queries between the client, the recursive resolver, and the authoritative nameserver until the IP address for the requested domain name is obtained.
DNS caching is an essential part of DNS, as it reduces the load on authoritative nameservers and improves the performance of DNS queries. However, it can also lead to problems if the cache becomes stale, as the resolver may return an outdated IP address for a domain name. And we can use things like Time to Live (TTL) values for DNS records to prevent stale cache entries.