What is DNS and how it works?

What is DNS and how it works

Have you ever heard about DNS and scratched your head what its purpose is?

When you browse the Net, many protocols are running in the background that makes it possible for you to play games, listen to music, send messages, or load web pages. DNS is one of them, and it’s worth knowing more about it if you’re curious how the Internet works.

So, today I’m going to explain to you what DNS is and how it functions. Keep on reading.

What is IP?

Before we talk about DNS, I must explain how computers communicate with one another. They use the Internet Protocol or IP. It’s a set of rules that determines how packets/messages are sent between devices.

The easiest way to understand these packets is to think about them as letters. If you want them to be delivered successfully, you need a sender, a receiver, and a payload. However, instead of street names, computers use IP addresses.

Let me illustrate it.

If you want to open www.google.com, your computer’s IP address (sender) must send a request to Google’s IP (receiver) and asks for the necessary data to show the page (the payload).

Wait a minute.

“I don’t know Google’s IP address,” you say. How are you able to load google.com then?

Well, that’s because we have DNS.

What is DNS?

Back when the Internet was making its first steps, it was possible to connect to a site/computer only if you knew its IP address.

That’s because computers communicate using numbers, not letters. So, a domain name like google.com doesn’t mean anything to a computer.

However, since we’re not robots and can’t memorize such strings of numbers, people started working on a solution.

At first, a text file was created to translate domain names like google.com into IP addresses that are recognizable to computers. However, since the Internet grew rapidly along with the demand for domain names, it was impossible to manage/update the text file.

That’s how DNS came into being. DNS stands for Domain Name System, and it’s something like a phone book, but instead of phone numbers, it contains IP addresses.

Its purpose is to match domain names like google.com or youtube.com into IP addresses so that you don’t have to memorize them.

How does DNS work?

DNS runs in the background and you don’t have to do anything to initialize it. But it’s interesting how it works.

How does DNS work

Credit: computerhope.com

Let’s say that you want to open YouTube. You type www.youtube.com into the browser. The first thing the operating system does is to divide the domain name. The parts of the domain name are called labels. You can easily distinguish these labels because they are separated by dots.

So, in www.youtube.com, we have three labels: www, youtube, and com. These parts for a hierarchy that must be read from right to left. In this case, com is the right-most label, which is called the top- level domain (TLD). Youtube is a subdomain of com, and www is a subdomain of youtube.

When your computer is trying to resolve the IP address, it connects to a root server. This server doesn’t have the IP address, but it points to the name server in charge of the top-level domain. In our case, it would be a “com” name server.

After that, the “com” name server will likely redirect you to another server that holds the information about the IP address.

It might sound complicated, but the structure makes DNS scalable. For example, an “org” name server doesn’t know anything “com” websites and doesn’t need to.

So, each server keeps information about a small number of IP addresses, and the risk of overloading them is insignificant.

What are Recursive Resolvers?

While DNS has many advantages, it also has some shortcomings. For once, the root name server is under a lot of pressure. Every time somebody wants to open a page, the computer contacts the root servers. You can image how many people are browsing the net right now, can’t you?

In addition to this, your device must be able to follow the referrals it gets from the root servers and the other name servers.

That’s why special DNS servers exists. They are called recursive resolvers and take care of the resolving process. These servers are responsible for contacting the name servers and go through all the hoops to get the IP address instead of your computer.

Usually, these recursive resolvers are hosted by:

  • Internet Service Providers (ISP)
  • Google
  • Cloudflare

Your router also functions as a recursive resolver, and your computer will use the resolver chosen by the network administrator. However, you can switch to another resolver, for example, one hosted by Google if you wish to improve your speed.

Recursive resolvers have another advantage. They store frequently requested IP addresses to speed up the resolving process.

For example, when you go to google.com for the first time, the recursive resolver will find the IP address and cache it for future uses. So, when you request it again, it doesn’t have to go to the trouble of resolving again.

The drawback is that IP addresses of domain names can change. In this case, when you request a page that has changed its IP address, the resolver will pull the old one from the cache. As a result, you’ll get an error and won’t be able to load the page.

That’s the reason why IP addresses get deleted. Domain owners can specify the TTL or time-to-live after which the resolver must delete the IP address and start the resolving process anew. However, some resolvers don’t adhere to this rule, and that’s why you might get an error when loading a webpage.

As you can see, DNS makes it possible to visit thousands of webpages without having to remember a single IP address. In addition to this, a custom DNS server can also help you block advertisements or protect yourself from malware. You can try it by downloading PiHole.

What do you think about DNS? Have you ever used a custom DNS server? Share your experience in the comment section.

(Last Updated On: September 11, 2019)
About the author

    Whale Sumo

    Hwang is a self-proclaimed nerd who loves helping people understand complex concepts. He has a passion for crypto and online privacy and enjoys teaching others about the benefits of both. Hwang is an advocate for individual freedom and believes that knowledge is power. When he's not busy sharing his knowledge with the world, Hwang can be found running full marathons or playing video games.