DNS record types explained: A, AAAA, CNAME, MX and TXT
A and AAAA point a name at an IP, CNAME creates an alias, MX receives email and TXT holds SPF and DKIM. Examples and the mistakes that break sites and email.
The site loads, but since yesterday no email has arrived. Nobody touched the mail server; someone just "pointed the domain at the new landing page" by creating a CNAME at the root, and the MX record that lived there stopped counting. Almost every incident like this lives in the same place: the domain's DNS records table, where each line looks harmless until you know what each type does and which combinations the standard forbids.
This post is a map of the DNS record types you'll find in your panel: A, AAAA, CNAME, MX and TXT in detail, NS and CAA in the summary. For the step-by-step of pointing a domain at your hosting, the practical sibling is how to point a domain to your hosting; for the path a query takes to reach its answer, how a DNS query works. All dig output below was generated in an Alpine container with BIND 9.20, querying the 1.1.1.1 resolver.
DNS record types: the summary
A DNS zone is a spreadsheet. Each row has a name (the subdomain, or @ for the root), a type, a value and a TTL (how long the answer may be cached). The type decides what the value means:
| Type | Points to | Typical use |
|---|---|---|
| A | An IPv4 address | Website, API, any service over IPv4 |
| AAAA | An IPv6 address | The same, over IPv6 |
| CNAME | Another name | Subdomain that follows a third-party service (CDN, store, blog) |
| MX | Mail server name + priority | Receiving the domain's email |
| TXT | Free text | SPF, DKIM, DMARC, domain verification |
| NS | Names of the authoritative servers | Delegating the zone (or a subdomain) |
| CAA | Authorized certificate authorities | Restricting who may issue SSL certificates |
NS and CAA are rarely edited day to day. NS defines who answers for the whole zone, and the difference between changing nameservers and editing the zone is in nameserver vs DNS zone. CAA lists which authorities may issue certificates for the domain (github.com authorizes DigiCert, GlobalSign, Let's Encrypt and Sectigo, for example); it matters when you issue an SSL certificate.
Difference between an A record and a CNAME
It's the most searched question, so it comes first. An A record points a name straight at an IP. A CNAME points a name at another name, and the resolver follows that other name until it reaches an A or AAAA. Use A when you control the IP (your server, your VPS). Use CNAME when the target belongs to a third party that may change IPs without telling you: CDN, e-commerce platform, GitHub Pages. If the provider's IP changes, the CNAME stays correct; an A record copied from their panel goes stale.
dig shows the chain:
$ dig www.github.com A +noall +answer
www.github.com. 2956 IN CNAME github.com.
github.com. 20 IN A 4.228.31.150
You asked for an A record for www.github.com, and the answer came in two lines: the CNAME and the A of the canonical name. Look at the TTLs: the alias may be cached for almost an hour, the target's IP for 20 seconds. Each record has its own.
A record: the name becomes an IPv4
The A record (for address) links a name to an IPv4 address:
@ A 192.0.2.10
www A 192.0.2.10
The first line resolves the root (example.com), the second resolves www.example.com. They're two different names: configuring only one leaves the other down. Several A records on the same name are allowed and the client picks among them, which gives you simple load balancing; example.com currently answers with two:
$ dig example.com A +short
104.20.23.154
172.66.147.243
AAAA record: the IPv6 version
AAAA does the same job for IPv6, in the 2001:db8::1 format. The four-letter name comes from the size: an IPv6 address is 128 bits, four times IPv4's 32. The difference between the two protocols is covered in IPv4 vs IPv6.
@ AAAA 2001:db8::1
www AAAA 2001:db8::1
You don't choose between A and AAAA: you publish both when the server has IPv6, and the client decides. And if there's no AAAA? It doesn't get slower. The resolver immediately answers that the name exists but has no record of that type (an empty "NODATA" answer), and the client carries on over IPv4. github.com, one of the most visited sites in the world, publishes no AAAA:
$ dig github.com AAAA
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43333
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
NOERROR with zero answers. Browsers that implement Happy Eyeballs (RFC 8305) fire the A and AAAA queries in parallel and use whatever exists; IPv6-only networks reach IPv4-only sites through DNS64/NAT64 (RFC 6147). The real cost of not publishing AAAA is missing out on native IPv6, not slowness. The mistake that actually takes sites down is the opposite: a stale AAAA pointing at a server that no longer exists.
CNAME record: an alias for another name
shop CNAME shops.platform.com.
blog CNAME myblog.blog-service.com.
Two rules trip everyone up:
- A name with a CNAME cannot have any other record. No A, MX or TXT at the same name (the only exception is DNSSEC records such as RRSIG and NSEC, which accompany the CNAME in a signed zone). This comes from RFC 1034 and was reinforced in RFC 2181.
- Because of rule 1, the domain root cannot be a CNAME. The root must carry SOA and NS records, and those can't coexist with a CNAME. That's exactly what broke the email in the opening: the CNAME at the root "won" over the MX.
To point the root at a service that only gives you a name, there are proprietary workarounds that resolve on the DNS provider's side and return a plain A record: ALIAS or ANAME, depending on the provider, and Cloudflare's CNAME flattening, which accepts a CNAME at the root in the panel and answers with the target's IPs. That's how many people point the root at a CDN without breaking the standard.
MX record: where email goes
MX (mail exchange) has nothing to do with the website. It says which servers receive email for the domain, each with a priority (the lower number is tried first):
$ dig gmail.com MX +short
5 gmail-smtp-in.l.google.com.
10 alt1.gmail-smtp-in.l.google.com.
20 alt2.gmail-smtp-in.l.google.com.
30 alt3.gmail-smtp-in.l.google.com.
40 alt4.gmail-smtp-in.l.google.com.
(I sorted them by priority; dig returns them in any order.) Three rules for an MX value:
- It's a name, never an IP. Some panels accept an IP, but delivery breaks.
- That name needs its own A or AAAA record.
- That name must not be a CNAME. RFC 2181 (section 10.3) says the name used in an MX or NS record must not be an alias; it has to point straight at addresses. Plenty of mail servers will follow the CNAME anyway, but then you're relying on tolerance, not the standard.
And a domain that does not receive email can say so explicitly with a "null MX" (RFC 7505): an MX with priority 0 pointing at .. That's what example.com publishes:
$ dig example.com MX +short
0 .
TXT record: SPF, DKIM and DMARC
MX only says where to deliver. Proving that an email sent in your domain's name is legitimate is the job of three TXT records:
- SPF lives at the root and lists who may send email for the domain. Example for Google Workspace users:
v=spf1 include:_spf.google.com ~all. A rule that breaks many setups: there can be only one SPF record per name; twov=spf1records make the check return a permanent error (RFC 7208). When you add a new service, edit the existing SPF instead of creating another. The standard also caps at ten the DNS lookups an SPF record may trigger (eachincludecounts). - DKIM lives at
selector._domainkey.yourdomain.comand publishes the public key that verifies the signature added to each email. Your email provider gives you the selector and the value. - DMARC lives at
_dmarc.yourdomain.comand says what to do when SPF and DKIM fail, and where to send reports.
Gmail's, queried just now:
$ dig gmail.com TXT +short | grep spf
"v=spf1 redirect=_spf.google.com"
$ dig _dmarc.gmail.com TXT +short
"v=DMARC1; p=none; sp=quarantine; rua=mailto:mailauth-reports@google.com"
The same dig gmail.com TXT returns four more domain-verification lines (Yahoo, GlobalSign and one with no prefix). TXT is the drawer where every service asks you to prove you own the domain, and it's normal to pile up several on the same name; only SPF can't be duplicated.
How to check a record: dig and nslookup
The panel shows what you saved; dig shows what the world receives. The commands I use most to check record types:
dig example.com MX +short # mail servers and priorities
dig example.com TXT +short # SPF and verifications
dig _dmarc.example.com TXT +short # DMARC policy
dig www.example.com A +noall +answer # shows the CNAME chain and TTLs
dig example.com CAA +short # who may issue certificates
dig example.com MX @1.1.1.1 # ask a specific resolver
On Windows, without dig, nslookup covers the basics:
> nslookup -type=mx gmail.com 1.1.1.1
Non-authoritative answer:
gmail.com mail exchanger = 40 alt4.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 30 alt3.gmail-smtp-in.l.google.com.
gmail.com mail exchanger = 5 gmail-smtp-in.l.google.com.
...
"Non-authoritative answer" means it came from a resolver's cache, not from the zone's server. If the result doesn't match the panel, the reason is usually TTL (the old value is still cached) or you're editing a zone that isn't the active one, because the nameservers point somewhere else. To check a freshly made change, including asking the TLD directly, the commands are in the guide on how to point a domain to your hosting.
The most common mistakes in practice
- A CNAME coexisting with other records, especially at the root. The number-one cause of "the email vanished."
- MX pointing at an IP or a CNAME. MX always points at a name with its own A or AAAA.
- Two SPF records. Merge everything into a single
v=spf1. - Forgetting the trailing dot on values that want a full name (
example.com.). Without it, some panels append the domain again and you end up withexample.com.example.com. - A forgotten AAAA pointing at an old server after a migration.
- Expecting changes to be instant. Resolvers keep the answer for the TTL. Lower the TTL a day before a planned migration.
Frequently asked questions
Can I use a CNAME on the domain root?
Under the standard, no: the root needs SOA and NS, and a CNAME can't coexist with any other record. Use A/AAAA records with the service's IPs, or your DNS provider's feature that handles it on their side (ALIAS, ANAME or Cloudflare's CNAME flattening), which returns a plain A record to whoever asks.
Do I need AAAA if I already have A?
It's not mandatory, and not having AAAA doesn't make resolution slower: the resolver answers right away that there's no IPv6 and the client uses IPv4. Publish AAAA when the server actually has working IPv6. What you should never have is an AAAA pointing at an address that doesn't respond.
Which DNS record is used for email?
MX says which servers receive email for the domain. For the email you send to land in the inbox, the TXT records come in: SPF (who may send), DKIM (the key that verifies the signature) and DMARC (what to do when both fail). Without MX you receive nothing; without SPF, DKIM and DMARC, what you send tends to land in spam.
Why did I change DNS and it still hasn't updated?
Because of TTL. Every resolver that already had the old answer keeps it cached until the TTL expires. If it was 24 hours, it can take up to a day for everyone to see the new value. Use dig against different resolvers to see who has updated, and lower the TTL before the next change.
Each record type has exactly one job
A and AAAA tie the name to an IP, CNAME creates an alias for another name, MX says where to deliver email, TXT carries the proofs (SPF, DKIM, DMARC and verifications), NS delegates the zone and CAA restricts who issues certificates. Remember the constraints the standard imposes: nothing coexists with a CNAME, the root can't be a CNAME, MX points at a name with its own address (never an IP, never a CNAME), and there's only one SPF per name. With that, and dig at hand, "the site won't load" and "the email never arrives" become one wrong line in a table.
The editorial content ends here. If the A record is going to point at a server in your home or office, the value is the connection's public IP, not the 192.168.x.x of the local network. The Quick Tools What is my IP tool shows that IP, whether it's IPv4 or IPv6, and the provider and ASN announcing it. It doesn't look up DNS records; for that, use dig.
- 01 CPU Cores vs. Threads: What Actually Changes in Practice Understand the difference between CPU cores and threads and what actually changes for performance, multitasking, gaming, and development.
- 02 MIT, Apache, and GPL Licenses: Practical Differences for Developers MIT, Apache 2.0, and GPL are not the same thing. Understand permissive vs copyleft, patent protection, and compatibility before shipping code to production.