What is Domain Name System(DNS) actually

Vidit VatsVidit Vats
7 min read

Ever wondered, How the URL that we type in the Address Bar of the browser, gets interpreted by the Browser? Well this question should arise in mind because at the end of the day, we are working with HTTPS i.e A TCP/IP protocol.

Well its because TCP/IP uses the IP Address to resolve the host and it is essential to map the URL with its corresponding IP Address.

Think of DNS like its a phonebook. Instead of remembering each and every telephone number, you just remember the name of the contact. That’s why it is commonly said that DNS is the “Phonebook” of the Internet.

You might wonder, what is Domain Name then: -

Consider any URL, for example: -

  1. Communication Protocol: The communication protocol that we are using here i.e Protocol used for Request and Response b/w the Browser(Sends Request) and Server(Sends Response)

  2. Domain Name: Its analogous to your Home Address. Basically, the identifier of the website that we want to access.

Steps involved in the Address Mapping: -

  1. The user passes the “Domain Name” or more simply the address of the website they want to access to the browser

  2. Browser then initiates a system call (mainly getaddrinfo() in Linux/Unix systems) to your OS.

  3. Now OS, first checks its local cache to find the IP of the requested domain name. If its present, the corresponding address is returned to the browser and the domain name against its IP is resolved.

  4. If the IP Address is not present in the local cache, the request is then forwarded to a DNS Server which in turn returns the response to the OS. OS then caches the result and sends back the response to the Browser.

  • The above process that we have written above will be understood firmly once we discuss it through diagrams that are coming later in this same blog.

Assignment of Domain Names and Domain Name Space: -

ICANN(Internet Corporation for Assigned Names and Numbers) is a non-profit organisation that governs and maintains the “Domain Namespace”. They have registered certain parties called Registrars, whose job is to allot and sell the requested domain name by the user/host. Users have to pay some charges in order to use the requested domain.

  • Domain Name Space is a tree consisting of different levels. The tree can have only 128 Levels i.e 0 to 127.

Terminologies: -

  1. Label: Each node in the tree has a label i.e a name which is a string of 64 characters. The Root Label is a null string (empty string). DNS requires that the children of a node must have different labels which guarantees the uniqueness of the domain names.

  2. Domain Name: Each node in a tree has a domain name. A full domain name is a sequence of labels separated by dots(.). The domain names are always read from current node to root node. The last ends in a null label which means that last character is a dot.

  3. Domain: - The subtree of a domain name space is called Domain.

Consider the Tree structure of the URL that we have used previously i.e. www.youtube.com : -

Here, “www” is called sub-domain / Third Level Domain, “youtube” is called Second Level Domain, “.com” is called Top Level Domain.

Now the question arises, how this domain name space tree must be stored?

The answer is to make the Root Label as a standalone Node and distribute all the Top-Level-Nodes(.com,.gov,.org etc) as separate Name Servers.

This is done to ensure modularity and each name server can be authoritative i.e. responsible for a sub-domain of itself because DNS allows domains to be divided further into sub-domains.

Below is a diagram that shows the hierarchy of name servers: -

  • Each server here is authoritative in nature i.e they know the addressing mapping that is to be returned.

  • What a server is responsible or has authority over is called a Zone. The server makes a file called Zone File that contains all the information for every node in that zone.

  • For example, “example.com” knows the address mapping for “help.example.com” ,“support.example.com”,“mail.example.com” because the Zone File of “example.com” contains all the information related to help, support and mail.

Role of Root Server: -

  • A root server is a server whose zone consists of Whole Namespace Tree.

  • Root Server does not store any information about domains and delegates its authority to other servers, because it has references to those servers.

  • There are 13 Root Servers present in the world. Actually, they are not physical machines. Each Root Server is replicated among several thousands of physical machines. Understand it like, there are several devices which have the same code running on them as if the actual Root Server would be running.

  • This above point is made possible using Anycast Routing.

Resolution of Addresses: -

  • Mapping a name to an address is called Name-Address Resolution.

  • A host that needs to map an address to a name or name to an address calls a DNS Client called a Resolver.

  • The Resolver accesses the closest DNS server with a mapping request.

  • If server has the information, it satisfies the resolver; otherwise, it either refers the resolver to other servers or asks other servers to provide the information.

  • After resolver receives the mapping, it interprets the response and checks whether mapping is wrong or right.

  • Resolution can be Recursive OR Iterative.

Consider an example that shows address mapping: -

  • To check what is your current DNS Server, run the following command: -

      systemd-resolve --status
    

  • To check the OS-Level Cache Statistics, run the following command: -

      systemd-resolve --statistics
    

Types of Address Resolution Techniques: -

1) Recursive Resolution: -

  • In this scheme, the Recursive Resolver(DNS Resolver) acts as a middleman b/w the DNS Server and the Client requesting the address.

  • Browser first checks its own cache to see whether the mapping is cached in browser or not. If it is not present, the request is forwarded to the OS via a N/W System Call.

  • OS checks its own Cache to find whether the mapping exists or not. If it is not present, the OS sends a DNS Query by wrapping it in a TCP/UDP packet on Port No 53 to the Local Gateway(Home Router). This is the most common scenario in general because my default it is forwarded to ISP’s DNS Server.

  • If you have manually configured the DNS Server settings yourself(For example, Google: 8.8.8.1 OR CloudFlare 1.1.1.1), then the DNS Query is forwarded to those resolvers directly.

  • Similarly, DNS Resolvers too have a cache. They too check whether the mapping exists or not. If not, “Full Recursive Resolution” is done.

One point to be kept in mind is that the ISP Resolver knows the address of all 13 Root Servers.

Consider the following diagram for better understanding: -

  • In above, as the name states, the process is recursive i.e. only one single response consisting of final IP Address is returned.

2) Iterative Resolution: -

  • Here, the ISP Resolver itself queries the Authoritative Name Server for the Address Mapping.

  • This means every name server except Authoritative one returns NS Record of the next name server.

  • Finally, the Client and Authoritative Name Server are in direct communication with each other but only when they traveled across the whole chain (root → TLD → Authoritative).

  • In above, as the name states, the process is iterative i.e. Every intermediary name server involved is processed.

Recursive Resolver in Action: -

Iterative Resolver in Action: -

DNS Records: -

  • DNS Records AKA “Zone Files” reside in the authoritative DNS Server and provide some information about a domain including what IP Address is associated with the domain.

  • These records consists of series of text files written in a special syntax called DNS Syntax.

  • All these records have a TTL(Time-To-Live) field in them to indicate the expiry of the record.

Common Types of DNS Records: -

  1. A Record: - This record provides the IPv4 Address of the requested domain.

  2. AAAA Record: - This record provides the IPv6 Address of the requested domain.

  3. CNAME Record: - This indicates the alias (nick name) of the requested domain.

  4. NS Record: - This stores the name of the Authoritative Name Server.

  5. MX Record: - This indicates the mail servers that are responsible for handling incoming mail requests. Lower Number means Higher Priority and Higher Number means Lower Priority here.

    • When someone sends an email to an address like user@gmail.com, the sending mail server looks up the MX records for gmail.com in DNS to determine where to deliver the message.

Diagram Depicting Some DNS Records: -

0
Subscribe to my newsletter

Read articles from Vidit Vats directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vidit Vats
Vidit Vats