WHAT IS DNS
When you enter a website URL in your browser’s address bar, you are greeted with the pages from that website. Have you ever wondered where those pages come from? They come from a server somewhere on the internet. When you enter a link in the browser’s address bar, what you are really doing is requesting that server to send you those pages.
There are millions of such servers running on the internet. So how does your browser know which server to send that request to? This is where DNS comes into picture. DNS stands for Domain Name System.
THE DOMAIN NAME SYSTEM
Every server on the internet has a specific string of numbers assigned to it, known as that server’s IP address. But these IP address being just seemingly random strings or numbers are hard to memorize. Therefore there is a system which maps these IP addresses to easy-to-remember names. Such names are called Domain Names (e.g. www.google.com). These mappings are stored on special servers known as Domain Name Servers.
So whenever you request a website using its domain name, your browser contacts the Domain Name Server and fetches the IP address mapped to that domain name. It then sends the web page request to that IP address.
The mapping between a domain name and an IP address that we saw above is known as an A Record (or, Address Record)
There are many kinds of mappings that do more than just create a relationship between a domain name and an IP address. We will explore them in the following sections
1. A RECORD (Address Record)
As we saw above, an A Record is a mapping between a domain name and an IP address;
|Domain Name||IP Address|
2. AAAA RECORD (IPv6 Address Record)
An IP address has two flavors: IPv4 and IPv6. An IPv4 is a 32 bit (4 bytes) representation of a server’s address. But as you can imagine, the numbers represented by just 4 bytes is not enough to address all the servers on the internet - an ever increasing number. IPv6 resolves this issue by representing the addresses in 128 bits (16 bytes).
An AAAA Record is a mapping between a domain name and its IPv6 address.
3. CNAME RECORD (Canonical Name Record)
A CNAME record represents a mapping between two domain names. This is to say that one domain name is just an alias (a canonical name) of another domain name. So when Domain Name Server receives a request to resolve a domain name into an IP address, and if that domain name is a CNAME record mapping to another domain name, the DNS system continues the IP resolution process from that second canonical domain.
|Domain Name||Record Type||Mapping|
Now when you request the IP address (i.e. the A record) of bar.example.com, the DNS system sees that it has a CNAME record associated with it with a value of foo.example.com. So it continues its search for IP address from foo.example.com and returns 18.104.22.168
4. MX RECORD (Mail Exchange Record)
An MX Record specifies which mail servers will accept/process email messages sent to users on that domain name
For example (simplified for understanding),
|Domain Name||Record Type||Mapping|
In the above example, you are specifying that there are two mail servers (i.e. server1.mymailservers.com and server2.mymailservers.com) which will accept email messages on behalf of example.com domain. So if I send an email to email@example.com from firstname.lastname@example.org, the Gmail’s mail server does a DNS lookup for example.com’s MX records and finds server1.mymailservers.com and server2.mymailservers.com and sends the email message to them.
5. OTHER TYPES OF RECORDS
There are many other types of DNS records used for a lot of different scenarios - NS, PTR, SOA, SRV, TXT, URI, etc.