Skip to main content

Command Palette

Search for a command to run...

DNS Record Types Explained

Published
4 min readView as Markdown

What is DNS?

Imagine you want to call your friend, you pick up your phone and type the name of the friend in the caller app, and you basically get his actual number, and you call him. Similarly, computers don’t know what is google.com or hashnode.com, they only know a series of numbers which is called IP address. Through this IP address the internet connects to the site you want to visit.

So, this is where DNS comes into picture and is considered the ‘phonebook of the internet websites’. Every time you want to visit any site DNS tracks the ip address of the website with the help of DNS records. Consider DNS as ‘Whom should I talk to next’, remember this and you will be fine.

Why DNS records are needed

Since humans can’t remember every ip of every website someone has to keep a database where every ip is mapped to its url. DNS records are the instructions which tells the DNS which ip to use. ‘If the user wants to visit the website, give them this IP. If the user wants to mail, give them this ip’.

Now lets look at some of the common DNS records in detail

NS Record: The Authority

The NameServer Record tells the Internet that a particular provider contains your IP address, so go and ask them. It acts as a pointer that tells the internet that this site is on that authoritative server.

‘A’ & ‘AAAA’ Records: The Physical Address

A record holds the actual ipv4 address whereas AAAA record holds the ipv6 address of the website. It tells the internet go at this exact address.

IPv4 is 32-bit IP address. Ex: 192.168.1.1

IPv6 is 128-bit IP address. Ex: 2001:0db8:85a3::8a2e:0370

Why IPv6 was introduced because in the early days that ipv4 ips got exhausted and 4.3 billion ips which seemed to be a huge number didn’t last very long. Another reason was engineers decided to fix the problems we had with IPv4.

CNAME Record: The Alias

It is the canonical name that points one name to another name. You buy a domain name xyz.dev and you want that www.xyz.dev leads to your portfolio and blog.xyz.dev also lead to your portfolio. So we will assign cname www and blog to xyz.dev.

TypeName / HostTarget / Points toTTL
CNAMEblogxyz.devAuto / 3600
CNAMEwwwxyz.devAuto / 3600

MX Record: The Mail Slot

This record holds the address of the mail server you want your mail to go to.

Priority Matters: MX record contains a priority value like 10, 20 and so on, these tell if one server is down go to the mail server who has next lowest priority.

No IPs allowed: Only mail servers like mail.google.com can me mapped to MX record not IPs.

TXT Record: The Sticky Note

This record helps you prove your ownership of the domain. You can add security notes in the record which can be read by humans as well as machines. For humans, it is like a sticky note, and for machines, it is like the proof of ownership so that emails can’t be spammed.

example.comrecord type:value:TTL
@TXT"v=spf1 include:_spf.google.com ~all"32600

This value states that only Google can send me emails.

example.comrecord type:value:TTL
@TXT"google-site-verification=rXOxyZounnZfe_7589Fduf..."32600

This value tells that you own this domain.

How all DNS records work together for one website

Imagine you own a domain named abc.com. Now we will see how each of these records helps the internet to reach this domain.

NS: This record tells the internet that this domain is hosted on a particular provider eg. Cloudfare.

A and AAAA: This record tells the exact IP of the domain to the internet.

CNAME: This record makes sure that if someone types www.abc.com they end up to abc.com.

MX: This record tells the internet on which mail server the mail should be sent.

TXT: This record proves the ownership of your domain on the internet and stops you from get spammed with emails.

Conclusion

DNS records are very crucial when maintaining a website. When you buy a domain you also get access to these records. These records are generally present in the Domain’s registrar dashboard. If your site is not working make sure your A record is properly setup.