DNS Record Types
DNS records are entries in a zone file that map domain names to various kinds of data. Each record has a type, a name, a value, and a TTL (time-to-live).
A Record (Address)
| Property | Value |
|---|---|
| Maps | Domain → IPv4 address |
| Example | piyushgarg.dev → 1.2.3.4 |
| Use case | Direct IP resolution for a domain or subdomain |
The A record is the most commonly used DNS record. It directly resolves a hostname to an IPv4 address. When a browser queries a domain, the authoritative server typically returns an A record (or a CNAME that eventually resolves to one).
CNAME Record (Canonical Name / Alias)
| Property | Value |
|---|---|
| Maps | Domain → another domain |
| Example | magic.piyushgarg.xyz → google.com |
| Use case | Creating aliases that follow the target’s IP dynamically |
How CNAME Resolution Works
magic.piyushgarg.xyz → CNAME → google.com → A record → 5.6.7.8
- Client asks for
magic.piyushgarg.xyz. - DNS returns a CNAME pointing to
google.com. - Client makes another DNS query for
google.com. google.com’s A record returns5.6.7.8.- Both domains effectively resolve to the same IP.
Why Use CNAME?
| Scenario | Benefit |
|---|---|
| Outsourcing to Vercel / Cloudflare / CDN | Provider changes IP → your alias follows automatically |
| Multiple subdomains pointing to same service | Update target once, all aliases follow |
| Avoid hardcoding IPs | Dynamic resolution; no 2-AM outage when provider migrates |
“If Vercel changes their IP at 2 AM, your CNAME follows it automatically. If you hardcoded an A record, your site is down until you wake up.” — Day 30 CKA Video
Restrictions
- A CNAME cannot coexist with other records on the same name (e.g., you can’t have both a CNAME and an MX record for
mail.example.com). - The root/apex domain (e.g.,
example.com) typically cannot have a CNAME (DNS RFC restriction); use an ALIAS or ANAME record at the apex if your provider supports it.
MX Record (Mail Exchange)
| Property | Value |
|---|---|
| Maps | Domain → mail server(s) |
| Example | somecompany.com → mail.somecompany.com (priority 10) |
| Use case | Receiving email for a custom domain |
MX records tell mail transfer agents (MTAs) where to deliver email for a domain. They include a priority value (lower = preferred). Multiple MX records provide failover.
Used when setting up:
- Google Workspace (G Suite)
- Microsoft 365
- Self-hosted mail servers
NS Record (Name Server)
| Property | Value |
|---|---|
| Maps | Subdomain → authoritative DNS server |
| Example | abc.piyushgarg.xyz → ns.something.com |
| Use case | Delegating a subdomain to a different DNS provider or self-hosted DNS |
How NS Delegation Works
- Parent zone (
piyushgarg.xyz) has an NS record:abc.piyushgarg.xyz→ns.something.com. - Any query for
*.abc.piyushgarg.xyzis forwarded tons.something.com. ns.something.comruns a DNS server on UDP port 53 and responds with the final IP.
“If you want to build your own DNS server, you run a machine with port 53 open and tell your users to add an NS record pointing to you.” — Day 30 CKA Video
TXT Record (Text)
| Property | Value |
|---|---|
| Maps | Domain → arbitrary text string |
| Example | example.com → "v=spf1 include:_spf.google.com ~all" |
| Use case | Domain verification, SPF, DKIM, DMARC, arbitrary metadata |
TXT records are human-readable text entries. Common uses:
- Domain ownership verification (Google Search Console, SSL providers)
- SPF records — specify which mail servers can send email for the domain
- DKIM / DMARC — email authentication and anti-spoofing
SRV Record (Service)
| Property | Value |
|---|---|
| Maps | Service + protocol → hostname + port |
| Example | _sip._tcp.example.com → sipserver.example.com:5060 |
| Use case | Service discovery (SIP, XMPP, LDAP, etc.) |
Less commonly used for web traffic, but important for VoIP, messaging, and internal service discovery.
Record Type Summary
| Record | Maps To | Typical Use |
|---|---|---|
| A | IPv4 address | Direct domain → IP |
| CNAME | Another domain | Aliases, outsourcing, CDNs |
| MX | Mail server | Custom email hosting |
| NS | DNS server | Subdomain delegation |
| TXT | Text string | Verification, SPF, DKIM |
| SRV | Host:port | Service discovery |