Skip to main content

Command Palette

Search for a command to run...

Basics of DNS

Published
3 min readView as Markdown

DNS stands for domain name system and you can call it an internet phonebook.

Any device connected to the internet has IP address, which is given by the internet service provider, server from where we want to access the data also has an IP address. There are two types of IP addresses: IPv4 and IPv6. IPv4 is the older version and has 4 sets of numbers separated by decimals like 123.234.34.456 while IPv6 is the newer version which uses alpha-numeric characters separated by colons example, 123:ab:45.

Since IP addresses were difficult to remember DNS servers would have a domain name for every website and we were not required to remember the IP addresses of the websites we wanted to use!

user → DNS → user IP address → server → user (data received).

NS Record :

NS stands for name server, it acts as a manager, it does not contain the information the user is looking for but list of servers who have those websites that can answer users’ questions. In simpler words, NS records knows all the DNS records for the domain.

A Record :

Full form for A record will be address record and as the name suggests, it locates where the website is located on the internet. It converts the human readable website name to a numerical IP address, it specifically works for IPv4 addresses.

Example, you type the domain name on your browser, your computer asks for the IP address, then A record for that website will be found that points to a specific IPv4 address, your browser uses that IP address to connect to the server and load the required website.

AAAA Record :

Also known as quad-A is meant for IPv6 address records. Works similarly to A records.

CNAME Record :

Stands for Canonical Name, a type of DNS record that acts as an alias. If there are two websites with the same name, the CNAME record will point to another domain but not to the IP address.

Example, a website www.ansh.com has a CNAME ansh.com (without www). This means when a DNS server will look for www.ansh.com, it also look for ansh.com and return ansh.com’s IP address via its A record. Here, we would say that ansh.com is the canonical name of www.ansh.com.

Not to confuse working of CNAME with A, it is very simple, A will provide with the IP address whereas CNAME will provide with another name.

MX Record :

Mail Exchanger record is a type of DNS record that is specific for the mail servers, it is responsible for receiving mail on behalf of the domain name. It ensures that the mails reach the correct mailboxes. It is not meant for websites.

TXT Record :

Text record is a type of DNS record that allows to store plain texts for systems to read. Verifying Google or Github etc. to confirm that you own the domain. It also authorises mail servers to prevent spams (email security checks).

HOW ALL DNS RECORDS WORK TOGETHER FOR ONE WEBSITE?

Browser will ask DNS for the website → NS record will answer → A or AAAA will provide the website address → MX acts as a mail server → TXT will be there for verification and security → CNAME will play a role if there is any alias.

The browser gets the IP address and connects the user to the server and the website loads.

Learning the difference between types of DNS records can be tricky so here is a mnemonic: A Cute Mailman Needs Text 😁

DNS records work like an actual office where NS is the building manager, A/AAAA record is the address, CNAME is the nickname, MX is the post office and TXT is verification.