Skip to main content

Command Palette

Search for a command to run...

DNS Record Types Explained

Get Clarity about Domain Name System and how to host a website

Updated
5 min readView as Markdown

What is DNS ?

Let us first understand about DNS servers and why we use it.

Why to use DNS servers?

If you ever created a website and you want a Domain Name for it you use some popular services like Namecheap, GoDaddy, Google Domains, etc. And then you select a Host for your website to publish it online. This Hosting services gives you an IP address for your Server.

Server serves your website to client and each Server has at least one IP address. With help of your Domain Name browser gets the Server’s IP address.

This IP address is mapped with your Domain Name, which is stored in a DNS server. If you buy a domain name from any services like GoDaddy they automatically give you a DNS server, but you can also change your DNS server to other services like Cloudflare, its your choice what DNS server you want to choose and from where you want to buy Domain Name.

You always need a Domain Name.

You need a Server to host your website

You need DNS server to map your Domain Name and your Server’s IP address

In Short ~

By using your Domain Name, browser gets the IP address of Server which serves your website.

To provide the IP address of Server which is linked to your Domain name is the job of DNS SERVER !

How DNS server works Internally ?

Authoritative DNS servers stores this mapping between Domain Name ←→ IP address of Server in form of DNS records.

What is DNS Records ?

DNS records are rules that define how a domain behaves such as IP mapping, mail servers, verification, redirection, etc.

Definition form IBM docs

A Domain Name System (DNS) record is a set of instructions used to connect domain names with internet protocol (IP) addresses within DNS servers.

What are this set or instructions or Rules ?

There are different types of DNS records such as

  1. NS Record

  2. A Record

  3. AAAA Record

  4. CNAME Record

  5. MX Record

  6. TXT Record

Now lets see one by one about these records.

NS Record

NAME SERVER Record is a type of DNS record that stores which DNS servers are authoritative for your domain.

For example-

myBestWebsite.comns1.cloudflare.com

so ns1.cloudflare.com will provide me IP address of myBestWebsite.com in form of A Record (if IP is in IPv4) or in AAAA Record (if IP is in IPv6)

A Record

A Record is type of DNS Record which stores the IPv4 address of your Web’s Server.

For example - 193.52.34.10

To check A Record for a domain you can do by this linux command -

nslookup -type=A chaicode.com

krish@krish-Inspiron-3584:~$ nslookup -type=A chaicode.com
Server:        127.0.0.53
Address:    127.0.0.53#53

Non-authoritative answer:
Name:    chaicode.com
Address: 104.21.16.156
Name:    chaicode.com
Address: 172.67.213.172

AAAA Record

AAAA Record is type of DNS Record which stores the IPv6 address of your Web’s Server.

For example - 2001:0db8:85a3::8a2e:0370:7334

We introduced AAAA records to support IPv6 addresses.
Because IPv4 addresses are running out, IPv6 provides a much larger address space for the internet’s growth.

To check AAAA Record for a domain you can do by this linux command-

nslookup -type=AAAA chaicode.com

krish@krish-Inspiron-3584:~$ nslookup -type=AAAA chaicode.com
Server:        127.0.0.53
Address:    127.0.0.53#53

Non-authoritative answer:
Name:    chaicode.com
Address: 64:ff9b::ac43:d5ac
Name:    chaicode.com
Address: 64:ff9b::6815:109c

CName Record

If you use CName record you don’t map your Domain Name directly to Website Server’s IP address, instead you map it with a canonical name and that canonical name is mapped with IP address.

For example -

www.wikipedia.org → Domain Name

dyna.wikimedia.org→ CName

so www.wikipedia.orgdyna.wikimedia.org→ IP address

Proof-

krish@krish-Inspiron-3584:~$ nslookup -type=CName www.wikipedia.com
Server:        127.0.0.53
Address:    127.0.0.53#53

Non-authoritative answer:
www.wikipedia.com    canonical name = ncredir-lb.wikimedia.org.

Authoritative answers can be found from:

We introduced CName Record because

If you wanted to change IP address you don’t have to change the domain name of your website.

MX Record

MX record stores the information of the mail server that is responsible for receiving emails for a domain.

For example - You can check MX record of any mail address such as team@chaicode.com using ns-lookup command by linux

krish@krish-Inspiron-3584:~$ nslookup -type=MX chaicode.com
Server:        127.0.0.53
Address:    127.0.0.53#53

Non-authoritative answer:
chaicode.com    mail exchanger = 5 alt2.aspmx.l.google.com.
chaicode.com    mail exchanger = 1 aspmx.l.google.com.
chaicode.com    mail exchanger = 10 alt3.aspmx.l.google.com.
chaicode.com    mail exchanger = 10 alt4.aspmx.l.google.com.
chaicode.com    mail exchanger = 5 alt1.aspmx.l.google.com.

So they are using google’s server to store the emails

TXT Record

A TXT record is used to store text information about your domain that other services can read and verify.

what other services verify ?

  1. Domain ownership verification

  2. Email security

For example - TXT Record for domain chaicode is

krish@krish-Inspiron-3584:~$ nslookup -type=TXT chaicode.com 
Server: 127.0.0.53 
Address: 127.0.0.53#53

Non-authoritative answer: 
chaicode.com text = "google-site-verification=xvyWAw6Vt-EhY2ZbgAF7NiEx6iVxuypQyRlfyGedE5A" 
chaicode.com text = "v=spf1 include:dc-aa8e722993._spfm.chaicode.com ~all"

Authoritative answers can be found from:

Here "google-site-verification=xvyWAw6Vt-EhY2ZbgAF7NiEx6iVxuypQyRlfyGedE5A" Gives verification about Domain ownership

"v=spf1 include:dc-aa8e722993._spfm.chaicode.com ~all" Is used for Email security to prevent spam emails


Real life

Lets host our first website which is a Todo app

Step 1

Lets get a domain name for our website from Hostinger

Domain name → www.todoApp.com

Step 2

Now lets see a hosting partner to host our website

we will choose AWS EC2 to host our Todo App

We Got a Ip of our Website’s Server !

IP address → 192.38.13.5

Step 3

We are choosing Hostinger for our DNS provider so our NS record is of hostinger !

Now we map our domain name www.todoApp.com with a CName todoApp.com using Hostinger

and then map this CName with our IP address 192.38.13.5 as A Record

todoApp.com → A → 192.38.13.5 

www.todoApp.com → CNAME → todoApp.com

Step 4

We have set TXT Record in Hostinger for Domain ownership verification and Email security

Step 5

now we Wait for DNS propagation which Takes 5 minutes to 24 hours. Check our website status by nslookup todoApp.com and nslookup www.todoApp.com and then our first website is Live !