DEV Community

Cover image for Lost on the Internet? DNS Knows the Way.
Kunal
Kunal

Posted on

Lost on the Internet? DNS Knows the Way.

You type Facebook.com

Your browser doesn't know about facebook by its name

It needs an IP address to find anything on the internet

So, In this blog we will look how that URL converts into IP , But first we will discuss :

  • What DNS is (explained in very simple terms)
  • Why DNS records are needed
  • What an NS Record is (who is responsible for a domain)
  • What an A Record is (domain β†’ IPv4 address)
  • What an AAAA Record is (domain β†’ IPv6 address)
  • What a CNAME Record is (one name pointing to another name)
  • What an MX Record is (how emails find your mail server)
  • What a TXT Record is (extra information and verification)
  • How all DNS records work together for one website

DNS : Domain Name System

Think of a phonebook

That contains all your family and friend contacts by name with their phone number

If you want to call your friend you just check their phone number in the phonebook and call them.

πŸ‘‰ DNS stands for Domain name system it translate domain names to IP addresses so the browser can load internet resources.

Domain Name                     IP Address
www.google.com  --------------> 142.250.72.206
Enter fullscreen mode Exit fullscreen mode

You can also just copy the above IP it will opens google.

Why DNS records are needed ?

DNS servers are needed for :

  • Eliminates the need for humans to memorize IP addresses
    (So just you have to write the domain name and it will convert it in IP for you )

  • DNS tells your browser where to go on internet.

  • DNS lets a website keep the same name even if the IP changes in the background.

You can reach any website with their IP but its hard to memorize all the IP addresses. So , DNS just helps you to get to your desired website with Domain name.

So far we have seen that what DNS is and Why DNS servers are needed .
But DNS works using records. Lets see what these records are


NS : Name Server Record

Have you ever brought a domain ( eg www.example.com ) ?

If yes then your setup might look like :

Code hosted on : Vercel / Netlify
Domain bought from : Hostinger / Cloudflare

  1. What is the name server in here ?

When you buy a domain from Hostinger , it comes with Hostinger nameservers like:

ns1.dnsparking.com

ns2.dnsparking.com
Enter fullscreen mode Exit fullscreen mode

πŸ‘‰ Name server records tell the internet where to go to find out a domains IP Address.

Also tells the internet which servers ( eg -> ns1.dnsparking.com ) are responsible for answering DNS queries for a domain.

A domain often has multiple NS records if one goes down or unavailable, DNS queries can go to another one.


A : Address Record

Let's take the same example:

Website hosted on : Vercel / Hostinger / Netlify
Domain bought from : Hostinger / Cloudflare

So when you want to add a DNS to your website:

  1. You deploy your project, to your hosting platform that gives you an address (IP or DNS target) that points to your website.

vercel

This means this IP ( 84.32.84.32 ) address points to your web page that is hosted on Vercel.

  1. Now, you just have to add this IP to the A record on your Hostinger.

A

It added the desired domain name with the IP so that the browser can get it

πŸ‘‰ A record stands for "address record" that indicates the IP address of a given domain.

A records only hold IPv4 addresses. If a website has an IPv6 address, it will instead use an AAAA record

You can also host your website on hostinger or any other platform i used examples that most developers use for hosting.


AAAA Records

DNS AAAA records are the same as A records

AAAA records holds IPv6 addresses instead of IPv4 addresses. It also indicates the IP address of a given domain.

Why do we need this record if we have an A record?

Because the internet is running out of IPv4 addresses

IPv4 Address                    IPv6 Address
142.250.72.206               2606:4700:4700::1001. 
Enter fullscreen mode Exit fullscreen mode

You get the point both A and AAAA records indicates the IPs. Means you have to just point a IP to your website it will merge your domain name with the IP.

Now what if i tell you, You can also point a domain to another domain.


CNAME : Canonical Name Record

CNAME means one name pointing to another name .

Sometimes your hosting platform ( Vercel , Netlify ) Don't give a fixed IP address
Instead, they give you another domain name

my-project.vercel.app
Enter fullscreen mode Exit fullscreen mode

This is not an IP; it's a Domain name

How it works

  1. You deploy your project on Vercel
  2. Vercel gives you a deploy link ( like my-project.vercel.app )
  3. In your domain provider (Hostinger) , you add a CNAME

CNAME

Now let's suppose you want to access ( www.example.com )

DNS says go to my-project.vercel.app
Website loads

Platforms like Netlify , Vercel usually prefer CNAME because their IPs can change behind the scene.


MX : Mail Exchange Record

So far , we have seen that browser needs DNS to search for a website on the internet.
But DNS is not for website only
It also helps email to reach the right place

When you send an email to someone :

hello@gmail.com
Enter fullscreen mode Exit fullscreen mode

Did you notice something about the email?
gmail.com is a domain.

So, the internet needs to know which server should receive email for this domain.

πŸ‘‰ MX record decide which mail server receives email, just like A record decide where website go

Mail servers :- Google ( gmail ) , Microsoft ( outlook ) 
Enter fullscreen mode Exit fullscreen mode

TXT : Text Record

Have you ever seen an important mail landing in the spam folder?

That happens when mail servers are not sure if the email is trusted or not

That where TXT record comes in.

πŸ‘‰ TXT records help mail server to verify that this email is really sent from this domain or not.

So when DNS checks these TXT records

  • Trusted emails go to your inbox

  • Untrusted emails go to spam

Now lets see How all these DNS records work together for one website .


How all DNS records work together for one website

When you type a website name on your browser , DNS doesn't use just one record.

1. NS record
First, DNS checks who is responsible for this domain ?
(Meaning which name server should answer)

2. A / AAAA record
Then, DNS finds where the website lives.
It return the IP that points to the website.

3. CNAME ( if use )
If the domain points to another domain.
DNS follows the name until it finds the IP

4. MX Records
If someone sends an email to this domain
DNS uses MX records to find the mail server.

5. TXT Records
Finally, TXT records provide extra information and security.

NS decides who answers, A/AAAA decide where the website is, CNAME redirects names, MX handles emails, and TXT adds verification and trust.


Thanks for reading ! if enjoyed this blog , you can read more on this πŸ‘‡

Top comments (0)