DNS Records Explained
# CHAPTER 6
DNS Records Explained
1. Introduction
When you purchase a domain name, you are given access to a DNS management dashboard (your Authoritative Nameserver). This dashboard is blank. You must program it by writing DNS Records (Resource Records). These records are simple, single-line text instructions that tell the global internet exactly where your website files live, which server handles your emails, and how to verify your identity. In this chapter, we will define the most critical DNS records, understand their structural differences, and learn how to configure them for a production environment.2. Learning Objectives
By the end of this chapter, you will be able to:- Configure an A Record and an AAAA Record for IP routing.
- Differentiate between an A Record and a CNAME alias.
- Explain how MX records direct email traffic.
- Understand the security and verification purpose of TXT records.
- Identify the role of NS and PTR records.
3. Core Routing Records (A, AAAA, CNAME)
A Record (Address Record): The most fundamental record on the internet. It maps a domain name directly to an IPv4 address.-
*Example Config:*
Type: A|Name: @|Value: 192.168.1.10
@ symbol is shorthand for the "root" or "naked" domain, e.g., mywebsite.com without www).*
AAAA Record (Quad-A Record): Exactly the same as an A Record, but it maps the domain to an IPv6 address.
CNAME Record (Canonical Name): A CNAME does *not* point to an IP address. It points a domain name to *another domain name*. It acts as an alias.
-
*Example Config:*
Type: CNAME|Name: www|Value: mywebsite.com
www, and your IP address changes, you have to update two A Records. If you point www to the root via CNAME, you only ever update the root A Record, and the CNAME automatically follows!)*
4. Email and Security Records (MX, TXT)
MX Record (Mail Exchange): If someone emailscontact@mywebsite.com, the internet looks specifically for the MX record. It points to the mail server responsible for accepting your emails (like Google Workspace or Microsoft 365). MX records use a "Priority" number; the internet will try the lowest number first (e.g., Priority 10) and fallback to Priority 20 if the first server is offline.
-
*Example Config:*
Type: MX|Name: @|Value: smtp.google.com|Priority: 10
TXT Record (Text Record): Originally designed for humans to leave readable notes, TXT records are now heavily used by machines for verification. When you sign up for Google Search Console, Google will ask you to add a specific TXT record containing a random code. Once you add it, Google scans your DNS. If it sees the code, it proves mathematically that you are the true owner of the domain.
5. Infrastructure Records (NS, PTR)
NS Record (Nameserver): These records dictate which Authoritative Nameservers hold the *other* records for a domain. If you buy a domain on GoDaddy but want to use Cloudflare to manage it, you change the NS records on GoDaddy to point to Cloudflare's servers.PTR Record (Pointer Record): The exact opposite of an A Record. Instead of translating a Name to an IP, it translates an IP back to a Name. (We will cover this deeply in Chapter 15).
6. Record Comparison Table
| Record Type | Purpose | Value Example |
|---|---|---|
| A | Maps domain to IPv4 | 203.0.113.50 |
| AAAA | Maps domain to IPv6 | 2001:0db8::8a2e |
| CNAME | Aliases a domain to another domain | mywebsite.com |
| MX | Routes inbound email | mail.google.com |
| TXT | Text strings for verification/security | google-site-verification=XYZ123 |
| NS | Delegates DNS authority | ns1.cloudflare.com |
7. Command Examples
You can query specific record types usingdig.
8. Best Practices
-
Never CNAME the Root Domain: Due to the strict rules of the DNS protocol (RFC 1034), you cannot place a CNAME record on the apex/root domain (
mywebsite.com). CNAMEs can only be used on subdomains (likewww.mywebsite.comorblog.mywebsite.com). The root domain *must* use an A Record.
9. Common Mistakes
- Confusing Web Hosting with Email Hosting: Beginners often assume that if they point their A Record to a web server (like AWS), their emails will automatically go there too. Web traffic (A Record) and Email traffic (MX Record) are completely independent. You must configure them separately.
10. Mini Project: Configure Basic DNS for a Website
Let's conceptualize setting up a new startup domain:mystartup.com.
-
1.
The Web Server: You rent a DigitalOcean server with IP
104.20.50.1.
-
2.
The Email: You buy Google Workspace for
@mystartup.comemails.
- 3. The Configuration:
-
Create an A Record named
@pointing to104.20.50.1.
-
Create a CNAME named
wwwpointing tomystartup.com.
-
Create an MX Record named
@pointing tosmtp.google.com.
11. Practice Exercises
- 1. If your company migrates its website to an entirely new cloud provider with a new IPv4 address, which specific DNS record must you update?
-
2.
Why is it advantageous to use a CNAME record for subdomains (like
blog,shop,portal) instead of multiple A Records?
12. MCQs with Answers
Which DNS record type is exclusively responsible for routing inbound electronic mail to the correct server?
Which of the following is an invalid configuration according to fundamental DNS RFC rules?
13. Interview Questions
- Q: Explain the mechanical difference between an A Record and a CNAME Record.
- Q: A client wants to verify domain ownership with a third-party service (like AWS or Google Search Console) without changing their web traffic or email flow. Which DNS record type should they use?
- Q: Walk me through the purpose of the Priority number in an MX Record.