DNS Record Types Explained

Tell me, when you type a website address in the browser address bar, how does a browser know which machine (server) have the website hosted?
As all the machines connected to the Internet requires an IP address, we (browser) needs that particular IP address where the website is hosted. Now, we humans are not so good at remembering, particularly numbers (IP address). So we needed a way to give each website a human readable name and then the domain name system (DNS) was created.
What DNS is
DNS is like the phonebook for the Internet, just like you save your friends/families phone number on your phone's contact list (or in physical notebook) using their names and don't usually remember the phone numbers. The same way, DNS maps a website address to an IP address (IPv4 or IPv6). And remember, DNS provides many records, not just the IP address for the website.
Know more about how DNS maps a website to an IP Address or How DNS Resolution Works
Why DNS Records are Needed
Now you ask, why don't we just return the IP address for the website. The problem is, a domain name have many responsibilities and serving a website is one of them. You can also send emails to an email address assiosicated with a domain name. We also have IPv4 and IPv6. To provide specific information for a specific type of query DNS records are introduced.
Commonly used DNS records are A, AAAA, CNAME, MX, TXT and NS records. Apart from these, we have some other records types (e.g SOA,PTR, SRV etc) that are uncommon and used for administrative purposes. We will only discuss the commonly used ones.
What an A Record is
An A (Address) record maps the domain name with an IPv4 address where the website is hosted. When a browser request the website for a domain name, this DNS record helps to find the server IP address and finally resolve.
What an AAAA Record is
AAAA (quad-A) is similar to the A record but it store and returns IPv6 address instead. AAAA record provides the server IP when a browser requests a website through an IPv6 network.
Note: IPv6 is required due to the low availablity of IPv4 addresses and to maintain ever increasing number of network devices on the Internet.
What an CNAME Record is
CNAME (Canonical Name) helps when we want to provide resources from a different hostname (web address) but not from an IP address. This is mainly used to server a website from a differnt address (e.g example.com or test.example.com) on a subdomain of our own domain name (e.g blog.mywebsite.com). Or when we need to serve www version of our website.
To use various third-party services, we usually need to use CNAME as we never know when they will change their IP address and this frees us from this hassle.
What an MX Record is
MX (Mail Exchange) record handles all the incoming emails for a domain. Any emails sent an email address assiocited with the domain name, goes to the hostname mentioned on the MX record. There could be multiple MX record for the same domain name but with different priorities. The one with lowest priority number has the highest priority. Multiple MX records acts as backup when MX record with higher priority fails.
What a TXT Record is
TXT (TEXT) record is a type of DNS record that stores text values. It is mostly used for verification and security purposes, like domain name verification from a third party and email security verification
What an NS Record is
NS (Name Server) record provides the hostname for authoritative nameservers. An authoritative nameserver is a DNS server that host all your DNS records like A, AAAA, CNAME, MX and TXT etc.
A record vs CNAME record
A record stores an IPv4 address and serve that address when a website requested on that domain. But CNAME store another hostname, not an IP address. In the case of CNAME, the provided hostname get resolved again, returns the A record and then resources from that server returned.
NS record vs MX record
NS record tells your DNS resolver (ISP or router) where to find all the DNS records for the domain (the authoritative nameserver). MX record stored on that authoritative name server and used when the domain receives an incoming email.
NS ≠ Web Server
A common misconception beginners get is that the website is hosted on the authoritative nameservers mentioned on the NS record, or the website is hosted on the server where all the DNS records are also hosted, which is not true. Authoritative name server mentioned on the NS records only host the DNS records and returns the IP address mentioned on the A/AAAA records when a web server is requested from the browser, browser then communicate to the server to access the website.




