DNS and it's Record Types
5Everything is numbers in the Computer’s world, but when we type “www.google.com“ how is it able to understand it where to go? what to look for?
How does this actually work? Let’s understand this today.
What is DNS?
DNS stands for Domain Name System. Okay? but what is it?
Let’s put it this way, it is like a phonebook of web.
We remember names like google.com, masterji.com, chaicode.com but computer’s, they don’t understand alphabets they know numbers, specifically IP addresses and DNS is the one who converts these domain names into an IP address which looks like this “192.168.1.1”.
So would you want to remember these numbers for each and every website? No right, hence DNS is needed.
DNS Records
DNS relies on various record types to direct traffic appropriately. But wait, what are DNS records?
Well, they are just a set of instructions stored for a domain name. Think of a contact saved in your phone, for one contact we store name, number, email, address etc. similarly domain name is equal to contact name and DNS Records are other information saved.
There are many types of DNS Records, let’s go trough them one by one.
NS Record
NS stands for Name Server, think of it as an Authority. NS records tell the Internet where to go to find out a domain's IP Address.
A domain has multiple nameserver records if in case the primary nameserver fails the secondary nameserver will automatically point to the address and all the nameserver for a single domain contains the same copy of information, so if the primary nameserver is updated the secondary nameservers are updated automatically.
Here is an example of a NS Record:

A Record
A stands for Address. A record stores the IP address of the given domain, specifically IPv4 addresses only. For example, the A records for google.com include:
172.217.21.142
172.217.21.143, etc.
Yes there can be many A records for a single domain, but majority only has one A record.
The most common usage of A record is to map the domain name to an IPv4 IP Address. This enables our devices to connect with and load a website, without memorizing and typing in the actual IP address.
Example of an A record:

AAAA Record
Just like an A record, it also matches the domain to an IP address but an IPv6 address instead of IPv4.
The difference between two is that the latest version i.e. IPv6 is longer than IPv4. These addresses have a specified length associated to them, and IPv6 is longer so more addresses possible through Permutations and Combination, and as the internet is running out of IPv4 possible address, IPv6 was introduced to solve that problem.
Here is an example of AAAA record :

CNAME Record
CNAME stands for “Canonical Name” Record. In simple words, it is the name which points to another domain name. A CNAME record is used in place of an A record, when a domain or subdomain is an alias of another domain. All CNAME records must point to a domain, never to an IP Address.
Let’s try and understand this with example:
My name is “Shubham” and let’s say my nickname is “Shubh”, whenever someone calls me by my nickname they still reach “Shubham”. Here nickname doesn’t have any identity it only points to my real name. In a similar way CNAME record works, it does not point to an IP address, it tells you to where to ask next, and next and then you will reach your destination.
Now you might have a doubt why not use just A Name for everything, okay let’s see, take an example website example.com which points to 192.168.1.1, then www.example.com points to 192.168.1.1, then blog.example.com also points to 192.168.1.1. Now everything is working fine but if IP changes and you might easily forget to change all, the unchanged one will not work, this is where CNAME shines.
example.com → 93.184.216.34 www.example.com → example.com blog.example.com → example.com.
Think of it like, A/AAAA names are house address, and CNAME is a sign board, not here go to that house.

MX Record
MX stands for “Mail Exchange”. It tells where should the emails for this domain be delivered and it is managed by MTA (Message Transfer Agent) software. Let’s say I have sent an email, the MTA will send a DNS query to identify the mail server for the email recipients, then it will establish an SMTP (Simple Mail Transfer Protocol) connection with those mail servers, these mail servers can have priority as well, lower priority value is preferred.
TXT Record
TXT records are used for various purposes, domain ownership verification, email security, third-party service validation and records are stored as plain text.
Think of it as proof attached to your domain. They aren’t used for routing traffic but are very important for security purpose.
Two of the most important uses for DNS TXT records are email spam prevention and domain ownership verification. One domain can have many TXT records.
Example of a TXT record :

How DNS works?
You know all the major DNS records type but how do all these come together and make it all work?
Let’s dive in,
When we enter a domain name let’s say www.example.com in our browser a series of steps are triggered in order to resolve this domain name into machine readable IP address:
For a single website:
NS decides who controls DNS
A / AAAA loads the website
CNAME handles alternate names
MX routes emails
TXT handles verification and security
All these records work together to make one domain function properly.