DNS Records Explained
Tags: domainnamesystem, domainnameserver, domain, dns
Published: 2019-06-13 20:07:28

_Cross-posted from : <https://www.andeshchogle.com/blog/post/dns-records-explained/>_


#### 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 **D**omain **N**ame **S**ystem.

<br>

#### 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.

<br>

#### DNS RECORDS
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

<br>

#### 1. A RECORD (Address Record)
As we saw above, an A Record is a mapping between a domain name and an IP address;

For Example,

|   Domain Name    |   IP Address   |
| :--------------: | :------------: |
|  www.google.com  | 216.58.203.164 |
|  www.gmail.com   | 172.217.163.37 |
| www.facebook.com | 157.240.24.35  |

<br>

#### 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.

<br>

#### 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     |
| :-------------: | :---------: | :-------------: |
| bar.example.com |    CNAME    | foo.example.com |
| foo.example.com |      A      | 216.58.203.164  |

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 216.58.203.164

<br>

#### 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          |
| :---------: | :---------: | :-----------------------: |
| example.com |     MX      | server1.mymailservers.com |
| example.com |     MX      | server2.mymailservers.com |

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 contact@example.com from cooluser@gmail.com, 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.

<br>

#### 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.

<br>

#### REFERENCES

1: https://en.m.wikipedia.org/wiki/List_of_DNS_record_types

2: https://tools.ietf.org/html/rfc1034