Before understanding how DNS works, we need to first know what is IP address. The IP address is a specific address given to any device on the internet, anything like your mobile phone, laptop, servers everything which is connected to any sort of intranet or internet will have its own IP address. When you connect your Laptop to a WIFI router, the router will assign a specific IP to your Laptop and will use it to further identify the Laptop. Just like your laptop, every website hosted on the internet will also have a specific IP address assigned to it.
The DNS also is known as the domain name system, connects the URL to an IP page. When you search for a domain like www.thebytewise.com the DNS sends a query over the internet to match the domain with its corresponding IP address. It's because of the DNS, that you are able to type in the URL (Domain name/hostname) of a website and get to your favorite site, otherwise, you would have to type in the IP address to access that particular website. But here it is the domain name system that does it for you.
Let's take another example of your phone, when you want to call your friend at midnight to talk about your boring life, you first open up the phonebook app and search for you friend's name and then use it to make a call. But what if you didn't have the phonebook app, then you would have to remember each one of your friend's numbers to contact them. Just like the phonebook app on your phone DNS acts like the phonebook of the internet, it matches the domain name/hostname to the IP address linked to it and then takes you to that website.
How exactly do DNS works?
Nameservers actually stored the DNS records which are the actual file that defines the link between a domain and the IP address it is connected to. As we already know the URL of the website is changed to an IP address before accessing it. So there is a server somewhere in the world where all the IP addresses are stored?? Ummm... NO that will be pretty dumb. They are actually distributed over the whole internet. It's not a single server.
The process of loading a page involves 4 DNS servers
DNS recursor/DNS recursive resolver The DNS recursor is a server that is designed to take queries from the client's machine using applications like a web browser.
Root nameserver The root server is the first step towards resolving (translating) the URL of the page to an IP address.
TLD nameserver also known as the Top Level Domain nameserver, is the next step in the search for a specific IP. This nameserver host the last part of a hostname (URL) that is the .com part.
Authoritative nameserver/the domain's nameserver is the last step in the search for that IP address. It has access to the requested record, it will return the IP address for the requested hostname (URL) back to the DNS Recursor that made the initial request.
To sum up, the process of loading a website can be divided into 8 steps.
The user types ‘www.thebyetwise.com’ into a web browser and the query travels into the Internet and is received by a DNS recursive resolver.
The resolver then queries a DNS root nameserver (.).
The root server then responds to the resolver with the address of a Top Level Domain (TLD) DNS server (the .com part or .net), which stores the information for its domains. When searching for thebytewise.com, the request is pointed toward the .com TLD.
The resolver then makes a request to the .com TLD.
The TLD server then responds with the IP address of the domain’s nameserver, thebytewise.com.
Lastly, the recursive resolver sends a query to the domain’s nameserver.
The IP address for thebytewise.com is then returned to the resolver from the nameserver.
The DNS resolver then responds to the web browser with the IP address of the domain requested initially.