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)

PropertyValue
MapsDomain → IPv4 address
Examplepiyushgarg.dev1.2.3.4
Use caseDirect 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)

PropertyValue
MapsDomain → another domain
Examplemagic.piyushgarg.xyzgoogle.com
Use caseCreating aliases that follow the target’s IP dynamically

How CNAME Resolution Works

magic.piyushgarg.xyz  → CNAME → google.com  → A record → 5.6.7.8
  1. Client asks for magic.piyushgarg.xyz.
  2. DNS returns a CNAME pointing to google.com.
  3. Client makes another DNS query for google.com.
  4. google.com’s A record returns 5.6.7.8.
  5. Both domains effectively resolve to the same IP.

Why Use CNAME?

ScenarioBenefit
Outsourcing to Vercel / Cloudflare / CDNProvider changes IP → your alias follows automatically
Multiple subdomains pointing to same serviceUpdate target once, all aliases follow
Avoid hardcoding IPsDynamic 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)

PropertyValue
MapsDomain → mail server(s)
Examplesomecompany.commail.somecompany.com (priority 10)
Use caseReceiving 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)

PropertyValue
MapsSubdomain → authoritative DNS server
Exampleabc.piyushgarg.xyzns.something.com
Use caseDelegating a subdomain to a different DNS provider or self-hosted DNS

How NS Delegation Works

  1. Parent zone (piyushgarg.xyz) has an NS record: abc.piyushgarg.xyzns.something.com.
  2. Any query for *.abc.piyushgarg.xyz is forwarded to ns.something.com.
  3. ns.something.com runs 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)

PropertyValue
MapsDomain → arbitrary text string
Exampleexample.com"v=spf1 include:_spf.google.com ~all"
Use caseDomain 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)

PropertyValue
MapsService + protocol → hostname + port
Example_sip._tcp.example.comsipserver.example.com:5060
Use caseService discovery (SIP, XMPP, LDAP, etc.)

Less commonly used for web traffic, but important for VoIP, messaging, and internal service discovery.


Record Type Summary

RecordMaps ToTypical Use
AIPv4 addressDirect domain → IP
CNAMEAnother domainAliases, outsourcing, CDNs
MXMail serverCustom email hosting
NSDNS serverSubdomain delegation
TXTText stringVerification, SPF, DKIM
SRVHost:portService discovery

Source