loading...
Hyvor Talk

DNS Demystified ūüí™

supunkavinda profile image 01010011 01110101 01110000 Originally published at talk.hyvor.com „ÉĽ7 min read

DNS stands for Domain Name System. Because of the numerous options/features of DNS, it's easy to get confused. Let's demystify DNS!

Table of Content

  1. What is DNS?
  2. How DNS works?
  3. What is DNS Caching?
  4. DNS Records
  5. FAQ

Servers

What is DNS?

DNS converts a hostname (example.com) to an IP Address (93.184.216.34)

When you connect your computer to the internet it gets a unique number that identifies it on the internet. This is called Internet Protocol Address, or IP Address in short. These IP addresses can be in IPv4(192.62.9.1) or more complex IPv6 (2001:0db8:85a3:0000:0000:8a2e:0370:7334) formats.

However, humans are more capable of remembering meaningful (or not) names than numbers. For example, which one is easier for you? facebook.com or 192.161.82.254? When you have multiple websites, it makes much harder to remember numbers. Therefore, we use names (called hostnames) to access the websites on the internet.

Examples: google.com, facebook.com, wikipedia.com, en.wikipedia.com

After you enter a hostname (example.com) in your web browser, the browser has no idea where the server of example.com is. Then, the browser connects to the Domain Name System (DNS), which translates a hostname to an IP address, to find the actual IP address of the server.

DNS is a large collection of servers and databases that works in a procedure which is called DNS protocol.

A Simple Representation of How DNS Works

How DNS Works?

Even the above image shows it in two steps, the actual Domain Name System includes multiple steps and different types of servers specialized in certain tasks. First, let's see the types of servers and why they are there.

The Domain Name System mainly comprises 4 types of servers.

  1. DNS Recursor -- A person who is finding a book in a library
  2. Root Nameserver -- A corridor in the library
  3. Top-Level Domain (TLD) Nameserver -- A rack in that corridor named the book's category.
  4. Authoritative Nameserver -- The book

After we find the book, we can find the IP address of our hostname there. However, this library scene is an analogous situation not identical. Let's see what each server's responsibilities are.

Server 1: DNS Recursor

DNS recursive resolver

Source: Cloudflare

The first thing out from your computer but in the Domain Name System is the DNS Recursor (or Resolver). When we request example.com in the browser, the browser needs a way to find the IP address of it. So, it asks for help from the DNS Recursor.

The DNS Recursor is provided by your Internet Service Provider. However, it doesn't have any idea of the IP address of the given hostname. It will recursively send requests to other servers to find the exact IP.

You have an address of a person abroad and need to find him. First, you go to his country. Then, his province. Then, his district. Then, his town. Then, his street. Finally, his house.

The same logic is here. DNS Recursor needs to find the IP (person) of the hostname (address).

  • It first asks a¬†Root Nameserver¬†and will get the address of the TLD Nameserver.
  • It then asks the¬†TLD Nameserver¬†and will get the address of the authoritative nameserver.
  • It finally asks the¬†Authoritative Nameserver¬†and will get the actual IP of the server of the hostname. Yay!¬†ūüéČ

Server 2: Root Nameserver

DNS root nameserver

Source: Cloudflare

There are only 13 Root Nameservers in the world (source) and all 13 are known to all the recursive nameservers. These ones too don't know what is the IP address of the hostname we are finding. (Shame? No.) It knows one invaluable thing: where the data regarding the hostname's Top-Level Domain is saved.

For instance, if the hostname is example.com, the root nameserver sends back the address of the Top-Level Nameserver of all the .com domains.

Server 3: TLD Nameserver

DNS TLD nameserver

Source: Cloudflare

A TLD Nameserver maintains the data of all the domains of a specific Top-Level Domain, such as .com, .org, .io, etc. When the DNS Recursor requests the information of example.com, for example, the TLD Nameserver will return the address of the Authoritative Nameserver. (Don't worry it's the last step)

Server 4: Authoritative Nameserver

DNS authoritative nameserver

Source: Cloudflare

An Authoritative Nameserver is responsible to maintain information about a single domain. When the DNS Recursor requests example.com's IP address from its Authoritative Nameserver, it will run DNS Lookup to find the IP address. In this process, it will look for A or CNAME records (More on that later). If found, it returns the IP address of the hostname.

Let's sum it up...

  • You type example.com on your browser.
  • Your browser requests the IP address from the DNS Recursor (or Resolver)
  • The Recursor sends requests to the following step by step to find the address of the next one.
    • Root Nameserver
    • TLD Nameserver
  • Finally, the request to the Authoritative Nameserver of the domain will return the IP address of the requested hostname to the DNS Recursor to the browser.

Now, your browser will render and display the website!¬†ūü홬†(If the website was found)

What is DNS Caching?

You call your mom every day. It's much easier when you save her number at the top of your phone's favorite numbers list rather than searching for it every time you need it. Right?

The concept of DNS caching is similar to that. The meaning of Caching is temporarily saving data in an easily-accessible location to retrieve easily without processing, mainly to improve performances. DNS caching involves the DNS, and it can be done at any of the DNS servers, at the user's OS or even at the user's browser. The nearer the cached data to the user's browser the faster it can be retrieved. (Logical right?)

Note: NDNS data is only cached for a predefined amount of time which is called TTL (Time To Live).

Example DNS Resolving with Caching:

  • You request example.com from the browser.
  • The browser checks its cache for the DNS data.
    • If found, it terminates the DNS resolving and sends the request directly to the IP address.
    • If not, it asks for it from the DNS Recursor.
  • The DNS Recursor checks its cache for the DNS data of the requested domain.
    • If found, it terminates the DNS resolving and sends the IP address back to the browser without further requests.
    • If not, continues the DNS resolving process...
  • ......

You can understand that the request only reaches the Authoritative server rarely (unless the domain is new).

DNS Records

Have you ever set up your own domain for a website? Then, you must have been confused at this point: DNS Records.

Let's be practical. Suppose that you just bought your dream domain. The company where you bought the domain will (and must) provide you the facility to change the nameserver address of the domain. By default, they are usually pointed to a nameserver managed by that company itself. However, you can use a custom nameserver or a free service like Cloudflare. This process is called pointing your domain to nameservers. It isn't a new kind of nameserver but what we learned previously as "Authoritative Nameserver".

Then, you will get a web-based DNS record manager which is usually called DNS Zone where you can add/remove/edit DNS records for your newly bought domain.

The details of the domain are saved in these DNS records. It's like a file stack of an investigation -- it contains much information about your domain.

Adding a DNS Record

Once you are in the DNS Zone of your domain, you can add a DNS record with the following data

  • Type -- one of the DNS Record types (below 5 or any other)
  • Host -- Use¬†@¬†for the root domain. Or, use a subdomain like¬†www,¬†blog.
  • Value -- Depends on the type.
  • TTL (optional) -- Time-to-live. Recommended to use Auto.
  • Priority (only for MX records) -- Set the priority (Don't worry. Your email service will give that)

Types of DNS Records

While there is a bunch of DNS records, here are the most common ones.

Record Type Stands For Description
A Address Map a hostname to IPv4. The value should be an IP address.
AAAA Address Same as A with the exception of using IPv6.
CNAME Canonical Name Map a hostname to another hostname. If the server doesn't have a static IP, this can be useful. Commonly used to forward www to @. You can also forward to an external domain (blog to my-blog.herukodns.com)
MX Mail Exchange Direct mail to an email server. You can set priority to choose which one to use first.
TXT Text Store a note/value. Frequently used to verify your website.

FAQ

Q: Why such a complex process? Can't we have only one database?
There are more than 0.3 billion domain names registered. Having all of the data and resolving hostnames from one server isn't practical. Therefore, in 1983, Paul Mockapetris invented the DNS. It's a type of decentralizing for the ease of data handling and speed.

Q: What is the difference between domain and hostname?
Hostnames: example.com, blog.example.com, shop.example.com. Domain: only example.com. Got it? Learn more here.

Q: Why does it take time to see DNS record changes?
It's because of DNS caching. Try clearing the DNS cache of your browser and OS. If it doesn't work yet, I have to say, you have to practice a little patience¬†ūüėČ.

In this article, we discussed what is DNS, how DNS works, DNS caching, and DNS records. If you have any questions to ask, please comment below.

Thank you!

Originally Published on Hyvor Talk Blog. Hyvor Talk is a commenting platform for blogs. We also help our users to grow by sharing tips and blog posts.

Hyvor Talk

Hyvor Talk is a commenting platform for websites.

Discussion

markdown guide
 

So keeping TTL short is good and bad. Good in a sense if you need to change the DNS it resolve faster but bad in a sense once resolve your caching get cleared soon. Thanks for the clarification.

 
 

Can you explain little bit more about DNS records. I don't get it!