DNS Record Types
A, AAAA, CNAME, MX, TXT, SRV, and more
Record Type Reference
DNS is more than name-to-IP mapping. Each record type serves a specific purpose in the DNS ecosystem. Here is a comprehensive reference.
| Type | Name | Purpose | Example Value |
|---|---|---|---|
A |
Address | Maps name to IPv4 address | 93.184.216.34 |
AAAA |
IPv6 Address | Maps name to IPv6 address | 2606:2800:220:1:248:1893:25c8:1946 |
CNAME |
Canonical Name | Alias one name to another | www.example.com -> example.com |
MX |
Mail Exchange | Mail routing (priority + hostname) | 10 mail.example.com |
TXT |
Text | Arbitrary text data | "v=spf1 include:_spf.google.com ~all" |
SRV |
Service | Service discovery (priority, weight, port, target) | 10 60 5060 sip.example.com |
NS |
Name Server | Delegates zone to nameservers | ns1.example.com |
SOA |
Start of Authority | Zone metadata (primary NS, serial, timers) | ns1.example.com admin.example.com 2024010101 ... |
PTR |
Pointer | Reverse DNS (IP to name) | 34.216.184.93.in-addr.arpa -> example.com |
CAA |
Certificate Authority Authorization | Which CAs may issue certs for domain | 0 issue "letsencrypt.org" |
A and AAAA Records
The most fundamental record types. A maps a name to an IPv4 address; AAAA maps to IPv6. A single name can have multiple A/AAAA records (round-robin DNS for basic load distribution).
$ dig example.com A +short
93.184.216.34
$ dig example.com AAAA +short
2606:2800:220:1:248:1893:25c8:1946
$ dig example.com A
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 86400 IN A 93.184.216.34
Multiple A Records (Round-Robin)
Multiple A records for the same name are returned in varying order. The client typically uses the first one. This provides basic load distribution but is not a load balancer — it has no health checking, session persistence, or weighted distribution.
api.example.com. 300 IN A 10.0.1.10
api.example.com. 300 IN A 10.0.1.11
api.example.com. 300 IN A 10.0.1.12Note
Happy Eyeballs (RFC 8305): Modern clients (browsers, curl) resolve both A and AAAA simultaneously and race the connections. If IPv6 connects faster, it wins. This is why you should publish both record types when IPv6 is available.
CNAME Records
CNAME (Canonical Name) creates an alias from one domain name to another. The resolver follows the CNAME chain to find the final A/AAAA record.
$ dig www.example.com
;; ANSWER SECTION:
www.example.com. 3600 IN CNAME example.com.
example.com. 86400 IN A 93.184.216.34
CNAME Rules and Restrictions
- Exclusive: A CNAME record cannot coexist with any other record type at the same name. If
www.example.comis a CNAME, you cannot also have an A, MX, or TXT record there. - No CNAME at zone apex:
example.com(the bare domain) must have NS and SOA records. Since CNAME is exclusive, you cannot put a CNAME at the apex. This is a hard constraint in the DNS spec. - CNAME targets should be FQDNs: Always use the fully qualified domain name (ending with
.) to avoid ambiguity. - CNAME chains: A CNAME can point to another CNAME, but avoid long chains — each hop adds latency. Most resolvers limit chain depth (typically 8-16).
Warning
Zone apex CNAME — the #1 DNS gotcha: You cannot put a CNAME on example.com (bare domain) per RFC. Many DNS providers offer proprietary workarounds: ALIAS (Route 53, DNSimple), ANAME (Azure DNS), or CNAME flattening (Cloudflare). These resolve the CNAME server-side and return an A record to the client. If your DNS provider doesn't support this, you must use A records at the apex.
Common CNAME Pattern: CDN Integration
# Point www to your CDN
www.example.com. 300 IN CNAME d1234.cloudfront.net.
# Or to a load balancer
api.example.com. 300 IN CNAME my-alb-123456.us-east-1.elb.amazonaws.com.Tip
AWS ALB/NLB: AWS load balancers provide a DNS name, not a static IP. You must use a CNAME (or ALIAS at apex). The ALB's IP addresses change over time, so hardcoding them in A records will eventually break.
MX Records
MX (Mail Exchange) records tell mail servers where to deliver email for a domain. They include a priority (lower = preferred) and a mail server hostname.
$ dig example.com MX +short
10 mail1.example.com.
20 mail2.example.com.
30 mail3.backup-mx.com.
MX Priority and Failover
- Priority 10 — primary mail server. All mail tries here first.
- Priority 20 — secondary. Used if priority 10 is unreachable.
- Priority 30 — tertiary. Could be an external backup MX service.
- Equal priorities = mail is distributed (load sharing). The sending MTA picks randomly among equal-priority servers.
- MX targets must be hostnames, not IPs. The target must itself have an A/AAAA record. MX targets must not be CNAMEs (per RFC 2181).
Note
Google Workspace / O365 MX: When using hosted email, you set MX records to the provider's mail servers (e.g., 1 aspmx.l.google.com for Google Workspace). The provider then handles routing, spam filtering, etc.
TXT Records
TXT records hold arbitrary text strings. Originally for human-readable notes, they are now critical infrastructure for email authentication and domain verification.
$ dig example.com TXT +short
"v=spf1 include:_spf.google.com ~all"
"google-site-verification=abc123..."
"MS=ms12345678"
Email Authentication via TXT Records
SPF (Sender Policy Framework)
Declares which IP addresses/servers are authorized to send email for your domain.
example.com. 3600 IN TXT
"v=spf1
include:_spf.google.com
include:amazonses.com
ip4:203.0.113.0/24
-all"include:— allow the included domain's SPF serversip4:/ip6:— allow specific IPs-all— hard fail everything else (~all= soft fail)
DKIM (DomainKeys Identified Mail)
Published as a TXT record at selector._domainkey.example.com. Contains a public key used to verify email signatures.
google._domainkey.example.com. TXT
"v=DKIM1; k=rsa; p=MIGfMA0GCS..."- The sending mail server signs the message with a private key
- The receiving server looks up the DKIM TXT record to get the public key and verify the signature
DMARC (Domain-based Message Authentication)
Published at _dmarc.example.com. Tells receiving mail servers what to do when SPF and DKIM checks fail.
_dmarc.example.com. TXT "v=DMARC1;
p=reject; // reject emails that fail both SPF and DKIM
rua=mailto:dmarc-reports@example.com; // aggregate reports
ruf=mailto:dmarc-forensics@example.com; // forensic reports
pct=100"Warning
SPF lookup limit: SPF evaluation is limited to 10 DNS lookups (including nested include: lookups). Exceeding this causes a permanent error (permerror), which many receivers treat as a fail. Common when using multiple SaaS services that each require their own include:. Solution: SPF flattening tools, or consolidating sends through fewer services.
Domain Verification via TXT Records
Services like Google Search Console, AWS SES, Stripe, and many SaaS platforms verify domain ownership by asking you to create a specific TXT record. This proves you control the domain's DNS.
# Google verification
example.com. TXT "google-site-verification=dEvXyZaBcDeFgHiJkLmNoPq..."
# AWS SES domain verification
_amazonses.example.com. TXT "abc123def456..."
# Let's Encrypt DNS-01 challenge
_acme-challenge.example.com. TXT "gfj9Xq...Rg85nM"SRV Records
SRV records enable service discovery via DNS. They specify the host and port for a given service, with priority and weight for load balancing and failover.
SRV Record Format
_service._proto.name. TTL IN SRV priority weight port target
# Example: SIP service over TCP
_sip._tcp.example.com. 3600 IN SRV 10 60 5060 sip1.example.com.
_sip._tcp.example.com. 3600 IN SRV 10 40 5060 sip2.example.com.
_sip._tcp.example.com. 3600 IN SRV 20 0 5060 sip-backup.example.com.- Priority: Lower = preferred (like MX). Priority 10 servers are tried before priority 20.
- Weight: Among records with the same priority, higher weight gets more traffic. 60/40 split means ~60% to sip1, ~40% to sip2.
- Port: The TCP/UDP port the service runs on. This is what makes SRV powerful — you don't need well-known ports.
- Target: The hostname providing the service (must have A/AAAA records).
$ dig _sip._tcp.example.com SRV +short
10 60 5060 sip1.example.com.
10 40 5060 sip2.example.com.
20 0 5060 sip-backup.example.com.
SRV in Kubernetes and Service Meshes
Kubernetes Headless Services
When you create a headless Service (clusterIP: None), CoreDNS creates SRV records for pod discovery:
# SRV record for a headless service
_http._tcp.my-service.default.svc.cluster.local. SRV 0 33 8080 pod-abc.my-service.default.svc.cluster.local.
_http._tcp.my-service.default.svc.cluster.local. SRV 0 33 8080 pod-def.my-service.default.svc.cluster.local.
_http._tcp.my-service.default.svc.cluster.local. SRV 0 33 8080 pod-ghi.my-service.default.svc.cluster.local.Clients (like gRPC) can use SRV records for client-side load balancing across all pod endpoints, bypassing the kube-proxy iptables/IPVS layer.
Note
Also used by: Consul (service discovery), LDAP/Active Directory (_ldap._tcp.dc._msdcs.example.com), XMPP, Minecraft (game server discovery), and CalDAV/CardDAV (_caldavs._tcp.example.com).
NS Records
NS (Name Server) records delegate authority for a zone to specific nameservers. They appear at every delegation point in the DNS hierarchy.
$ dig example.com NS +short
ns1.example.com.
ns2.example.com.
$ dig example.com NS
;; ANSWER SECTION:
example.com. 172800 IN NS ns1.example.com.
example.com. 172800 IN NS ns2.example.com.
NS Record Details
- Minimum 2 NS records: For redundancy. Most registrars require at least 2 nameservers on different networks.
- Delegation: NS records at the parent zone (e.g.,
.com) tell resolvers where to find the authoritative servers. NS records at the child zone (e.g.,example.com) are the "authoritative" copy. - Subdomain delegation: You can delegate subdomains to different nameservers:
internal.example.com. NS ns1.internal-dns.example.com.— useful for splitting DNS management between teams. - High TTL: NS records typically have very long TTLs (172800 = 2 days) since nameserver changes are rare and critical.
SOA Records
Every DNS zone has exactly one SOA (Start of Authority) record. It contains zone metadata essential for DNS operations, especially zone transfers between primary and secondary nameservers.
$ dig example.com SOA
;; ANSWER SECTION:
example.com. 3600 IN SOA ns1.example.com. admin.example.com. (
2024031501 ; serial number
7200 ; refresh (2 hours)
3600 ; retry (1 hour)
1209600 ; expire (14 days)
300 ; minimum TTL (5 min) )
| Field | Example | Meaning |
|---|---|---|
| Primary NS | ns1.example.com. |
The primary nameserver (MNAME) |
| Admin email | admin.example.com. |
Contact email (admin@example.com — first dot replaces @) |
| Serial | 2024031501 |
Version number. Secondaries compare this to decide if they need a zone transfer. Convention: YYYYMMDDNN |
| Refresh | 7200 |
How often secondaries check for updates |
| Retry | 3600 |
Retry interval if refresh fails |
| Expire | 1209600 |
If secondary can't reach primary for this long, stop serving the zone |
| Minimum TTL | 300 |
TTL for negative responses (NXDOMAIN caching) |
Tip
Serial number discipline: If you manage DNS zones via configuration files (BIND zone files), always increment the serial number when making changes. Forgetting to increment means secondaries won't pick up the change. Managed DNS providers (Route 53, Cloudflare) handle this automatically.
PTR Records (Reverse DNS)
PTR records provide reverse DNS — mapping an IP address back to a hostname. The lookup is done in special reverse zones.
Octets are reversed and appended to .in-addr.arpa:
# IP: 93.184.216.34
# Reverse zone: 34.216.184.93.in-addr.arpa
$ dig -x 93.184.216.34 +short
example.com.The -x flag is shorthand that constructs the reverse query automatically.
Each hex nibble is reversed and separated by dots:
# IP: 2001:db8::1
# Expanded: 2001:0db8:0000:...0001
# Reverse:
1.0.0.0.0.0.0.0...8.b.d.0.1.0.0.2
.ip6.arpa
$ dig -x 2001:db8::1 +shortWhy Reverse DNS Matters
- Email delivery: Many mail servers reject email from IPs without valid PTR records (or where PTR doesn't match the sending domain). Critical for email reputation.
- Logging: Tools like
tcpdump, web server logs, and SIEM systems use reverse DNS to annotate IPs with hostnames. - SSH:
UseDNS yesin sshd_config triggers PTR lookups, causing slow logins if reverse DNS isn't configured. - Cloud providers: AWS, GCP, Azure all provide mechanisms to set PTR records for your public IPs. For EC2 Elastic IPs, use the
ec2:CreateTagsAPI or request via support.
CAA Records
CAA (Certificate Authority Authorization) records specify which Certificate Authorities are allowed to issue TLS certificates for your domain. CAs are required to check CAA records before issuance (since September 2017).
$ dig example.com CAA +short
0 issue "letsencrypt.org"
0 issuewild "letsencrypt.org"
0 iodef "mailto:security@example.com"
| Tag | Meaning | Example |
|---|---|---|
issue |
Authorize a CA to issue certs for this domain | 0 issue "letsencrypt.org" |
issuewild |
Authorize a CA to issue wildcard certs | 0 issuewild "digicert.com" |
iodef |
Report violations to this email/URL | 0 iodef "mailto:security@example.com" |
Tip
Defense in depth: CAA records prevent unauthorized certificate issuance (e.g., if an attacker gains control of DNS validation for a different CA). Combined with Certificate Transparency (CT) log monitoring, CAA provides strong protection against mis-issuance.
Note
Inheritance: CAA records are inherited by subdomains. If example.com has CAA records but api.example.com doesn't, the parent's CAA policy applies. To override for a subdomain, add CAA records directly on it.
Practical DNS Patterns
Pattern 1: CNAME for CDN
Routing traffic through a CDN
# Point www to CloudFront distribution
www.example.com. 300 IN CNAME d1234abcd.cloudfront.net.
# Apex uses ALIAS/ANAME (provider-specific, not standard DNS)
example.com. 60 IN ALIAS d1234abcd.cloudfront.net.
# Static assets subdomain to S3 via CloudFront
assets.example.com. 3600 IN CNAME d5678efgh.cloudfront.net.Pattern 2: Email Authentication Stack
Complete SPF + DKIM + DMARC setup
# SPF: authorize Google Workspace + SES to send
example.com. TXT "v=spf1 include:_spf.google.com include:amazonses.com -all"
# DKIM: Google Workspace selector
google._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIGfMA0GCS..."
# DKIM: Amazon SES selector
abcdef._domainkey.example.com. CNAME abcdef.dkim.amazonses.com.
# DMARC: reject unauthenticated mail, send reports
_dmarc.example.com. TXT "v=DMARC1; p=reject; rua=mailto:dmarc@example.com"Pattern 3: SRV for Service Discovery
Consul, K8s, and LDAP service discovery
# Consul service discovery
_web._tcp.service.consul. SRV 1 1 8080 web-01.node.dc1.consul.
_web._tcp.service.consul. SRV 1 1 8080 web-02.node.dc1.consul.
# K8s headless service (created automatically by CoreDNS)
_http._tcp.my-svc.default.svc.cluster.local. SRV 0 50 80 10-244-0-5.my-svc.default.svc.cluster.local.
# Active Directory domain controller discovery
_ldap._tcp.dc._msdcs.example.com. SRV 0 100 389 dc1.example.com.Pattern 4: CAA for Certificate Policy
Restricting certificate issuance
# Only Let's Encrypt can issue certs
example.com. CAA 0 issue "letsencrypt.org"
example.com. CAA 0 issuewild "letsencrypt.org"
example.com. CAA 0 iodef "mailto:security@example.com"
# Allow Let's Encrypt for regular certs, DigiCert for wildcards
example.com. CAA 0 issue "letsencrypt.org"
example.com. CAA 0 issuewild "digicert.com"
# Block ALL certificate issuance (paranoid mode)
example.com. CAA 0 issue ";"Common DNS Gotchas
Warning
CNAME at zone apex: You cannot put a CNAME on example.com (the bare domain). NS and SOA records must exist there, and CNAME is exclusive. Use your provider's ALIAS/ANAME feature, or use A records with your load balancer's static IPs.
Warning
TTL planning for migrations: If you're migrating DNS records (e.g., changing the A record for api.example.com), lower the TTL days in advance. If the current TTL is 3600 (1 hour), clients may use stale cached records for up to 1 hour after the change. Pre-lower to 60s well before the cutover.
Warning
CNAME + other records: You cannot have a CNAME and any other record at the same name. Common mistake: adding a TXT record (for domain verification) at a name that already has a CNAME. The CNAME must be removed, or the verification TXT must go at a different name.
Warning
MX targets must not be CNAMEs: Per RFC 2181, MX records must point to A/AAAA names, not CNAMEs. While some implementations tolerate this, it's non-compliant and can cause delivery failures.
Tip
Testing changes: Always verify DNS changes with dig @ns1.your-provider.com example.com A (query the authoritative server directly) before waiting for propagation. This confirms the change is live at the source, independent of caching.