DNS record types explained (A, CNAME, MX, TXT)
DNS records are entries in a domain's zone that map a name to an address or a service; the record type says what kind of answer it is.
- Updated Nov 27, 2026
- Markdown
Pick the right DNS record type for a website, www and email.
What happens when you type a domain
- Your browser asks a resolver where example.com lives.
- The resolver asks the name server that holds the domain records.
- The A record answers with the server address.
- The resolver passes the address back and caches it.
- Now the browser connects straight to your server.
Static diagram
- Your browserexample.com?DNS resolver
- DNS resolveraskName server
- Name serverA 203.0.113.10DNS resolver
- DNS resolver203.0.113.10Your browser
- Your browserGET /Your server
A DNS record maps a name to an answer, and the record type says what kind of answer: A for an IPv4 address, AAAA for IPv6, CNAME for another name, MX for mail, TXT for text and NS for the name servers. A website needs only A (and sometimes AAAA or CNAME); email adds MX and TXT.
A short history#
DNS was designed in the 1980s to replace a single shared hosts file that every machine downloaded, and record types such as A, NS and MX come from that design. Others were added later as needs appeared: AAAA for IPv6, TXT for email policy and verification, and CAA for limiting certificate authorities.
How it works#
A domain’s DNS lives in a zone, which is a list of records served by its authoritative name servers. Every record has a name, a type, a value and a TTL. The name is the label being asked about (example.com, www.example.com, mail.example.com). The type says what kind of answer it is. The TTL says how many seconds a resolver may remember the answer.
When someone visits www.example.com, the browser asks a resolver for a specific type, normally A or AAAA. The resolver finds your name servers (the NS records at the parent zone) and asks them. If the answer is a CNAME, the resolver restarts the lookup with the target name. That is why a CNAME is an alias, not an address.
Two rules cause most confusion. A name that has a CNAME cannot hold any other record type. And the zone apex (the bare domain, written @) must hold the NS and SOA records, so it cannot be a CNAME in standard DNS. Some providers add a non-standard ALIAS, ANAME or flattening feature that behaves like a CNAME at the apex by returning A records.
| Type | Maps a name to | Example use |
|---|---|---|
| A | an IPv4 address | example.com to 203.0.113.10 |
| AAAA | an IPv6 address | the same site over IPv6, 2001:db8::10 |
| CNAME | another name | www to example.com |
| MX | a mail server, with a priority | where email for the domain goes |
| TXT | free text | domain verification, SPF and DKIM |
| NS | a name server | which servers answer for the domain |
| CAA | which CAs may issue certificates | restrict who can issue for the domain |
Comparing the record types for a hostname#
| Need | Use | Why |
|---|---|---|
| Name to a fixed IPv4 address | A | Direct, fast, works at the bare domain |
| Name to another hostname | CNAME | Follows the target if its address changes, but not at the bare domain |
| Bare domain to another hostname | ALIAS or flattening, if offered | Provider feature, not standard DNS |
| Name to a mail server | MX | Carries a priority |
Common misconceptions#
- A CNAME is not a redirect. The visitor’s address bar never changes, because DNS only returns an answer.
- TXT is not only for comments. SPF, DKIM, DMARC and domain verification all live there, and anyone can read it.
- More records do not make a site faster. Extra records add answers to cache and more to keep correct.
- DNS changes are not instant. Old answers live in resolver caches until their TTL expires.
When a record is the wrong tool#
Do not use a CNAME at the bare domain, or on a name that needs other records such as MX. Do not put secrets in TXT records, because DNS answers are public. Do not point an A record at an address that changes often; point a CNAME at a stable name instead.
Check it worked#
Run these on any machine with dig installed (dnsutils on Debian and Ubuntu):
dig +short example.com A
dig +short example.com AAAA
dig +short example.com MX
dig +short example.com TXT
dig +short example.com NSWhat you should see: each command prints only the answers of that type. An empty result means there is no record of that type for that name, which is normal for AAAA or MX on a simple site. For your own domain, dig +short www.example.com CNAME prints a target name if www is an alias.
Which ones do I need for a website?#
Usually an A record for the bare domain and either another A or a CNAME for www. Add AAAA only if the server really listens on that IPv6 address. Add MX and TXT only when you set up email. Add CAA only if you want to limit which certificate authorities can issue for the domain, and if you do, include the one you use (Let’s Encrypt uses letsencrypt.org).
Edge cases and gotchas#
- A CNAME cannot share a name with other records. If
wwwis a CNAME, you cannot also givewwwan MX or TXT record. Some DNS hosts refuse the save, and some accept it and misbehave. - The bare domain cannot be a CNAME. Use an A record, or your provider’s ALIAS or flattening feature if you must follow another hostname.
- A wrong AAAA breaks IPv6 visitors only. IPv4 testing looks fine. Add AAAA only after testing the server’s IPv6 address.
- MX values are hostnames, not IP addresses. The target needs its own A or AAAA record. Priority numbers decide order, and the lowest number is tried first.
- One SPF record per name. Several TXT records on a name are fine in general, but publishing two SPF records (those starting
v=spf1) invalidates SPF. Merge them into one. - Moving DNS hosts drops records you forgot. Copy MX and TXT records before changing name servers, or mail and verification break.
- Long TXT values. Some dashboards split values over 255 characters into several strings. Check how yours does it for DKIM keys.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
Dashboard rejects a CNAME on @ | Apex cannot be a CNAME | Use an A record, or ALIAS/flattening if your host offers it |
| Dashboard rejects a record because of a conflict with a CNAME | Another record exists on the same name | Delete one of them |
| Site works on IPv4 but fails for some users | Wrong or stale AAAA record | Fix or delete the AAAA record |
| Mail bounces or goes to spam | Missing MX, SPF or DKIM | Add the records your mail provider lists, one SPF only |
dig +short example.com MX prints nothing | No MX set | Add the MX records from your mail provider |
| Certificate issuing fails with a CAA error | A CAA record forbids the CA | Add a CAA record for your CA, or remove the restrictive one |
status: NXDOMAIN | The name has no records at all | Check the spelling and the zone |
| A verification TXT record is rejected | The value was pasted with quotes or line breaks | Paste it exactly as given, and check with dig +short TXT |
www works, bare domain gives the registrar page | Only www has a record | Add an A record for @ |
Real-world scenario#
Leo runs a blog on example.com and wants email at his own domain. At the DNS host he already has an A record for @ and a CNAME for www. His mail provider asks for three MX records, a TXT record for SPF and a TXT record with a DKIM key at a selector name.
dig +short example.com MX
dig +short example.com TXT
dig +short selector1._domainkey.example.com TXTThe first dig is empty until he adds the MX records, and then lists them with priorities. The second shows one SPF line, and he checks that there is only one line starting with v=spf1. He also adds a CAA record naming letsencrypt.org, then confirms with dig +short example.com CAA that certificate issuing is still allowed for the CA he uses. The website keeps working throughout, because none of the new records touch the A record. See point a domain at your server for the website half.
Quick reference#
| Type | Looks like | Check |
|---|---|---|
| A | 203.0.113.10 | dig +short example.com A |
| AAAA | 2001:db8::10 | dig +short example.com AAAA |
| CNAME | example.com. | dig +short www.example.com CNAME |
| MX | 10 mail.example.com. | dig +short example.com MX |
| TXT | "v=spf1 ..." | dig +short example.com TXT |
| NS | ns1.example.net. | dig +short example.com NS |
| CAA | 0 issue "letsencrypt.org" | dig +short example.com CAA |
Related lessons#
- Point a domain at your server: the A record in practice
- Check DNS with dig: read every field of the output
- DNS propagation and TTL: how long a record change takes
- Redirect www to the bare domain: where the www CNAME comes in
Next#
Once the name resolves, secure it with HTTPS and Let’s Encrypt.
Check what you learned
Frequently asked questions
Can a CNAME be on the bare domain?
Not in standard DNS, because a bare domain must also hold NS and SOA records. Use an A record there, or your provider's ALIAS or flattening feature.
Why does my email land in spam after I move my website?
Email records (MX, SPF, DKIM) are separate from website records. If you switched DNS hosts and did not copy the TXT and MX records, mail breaks or looks suspicious.
Can I have more than one TXT record on the same name?
Yes, many different TXT records can coexist. But a name should have only one SPF record, so merge SPF rules into a single TXT value.
Which record do I use to send www to another hostname?
A CNAME. It says this name is an alias of another name, and the resolver then looks up the target's address.
Keep going: guides and tutorials
- Self-Hosted Static Site Hosting: Deploy a Folder With Levelrail Self-hosted static site hosting from a plain folder: one deploy command, _redirects, _headers and a custom 404 honored, plus a one command rollback.
- Deploy Next.js on a VPS With Docker, Git Push and HTTPS Deploy a Next.js app to your own VPS with Docker, a health check, HTTPS and rollback. Includes the NEXT_PUBLIC build trap that leaves variables empty.