How does a CNAME record work?
example.com- Type
CNAME- Name
shop- Target
customers.example.net- TTL
3600
Read it as: shop.example.com is another name for customers.example.net.
The name is short for canonical name: the target is the real (canonical) name, and the record's own name is the alias. With the record above, a browser that opens shop.example.com goes through these steps:
- The resolver asks for the address of
shop.example.com. - The domain's nameservers answer: it is an alias of
customers.example.net. - The resolver asks for the address of
customers.example.netand gets an A or AAAA record. - The browser connects to that address, and still asks for
shop.example.com: the address bar does not change.
The last step is why a CNAME alone does not put a site on the air. The server on the other side has to know the name shop.example.com and have a certificate for it. The gain is that if the address of the target changes, nobody has to edit the alias.
Check a CNAME now
Type a name. You get what the domain's own nameservers publish, the chain to its end with the TTL of each step, what a resolver still has in its cache, the DNS provider, and what looks wrong.
Read-only and free. The name you type is not stored. A few checks per minute per visitor.
CNAME, A or ALIAS: which record do you need?
| Record | Holds | At the root domain | Other records at the same name | Use it when |
|---|---|---|---|---|
| CNAME | Another name | No | None (only DNSSEC records) | A subdomain has to follow a name that somebody else runs |
| A / AAAA | An IPv4 / IPv6 address | Yes | Yes | You know the address and it is yours to change |
| ALIAS, ANAME, flattening | Another name, answered as addresses by the DNS provider | Yes, where the provider offers it | Depends on the provider | The root domain has to follow a name |
| HTTPS (alias mode) | Another name, for web clients that read this record | Yes | Yes | As an addition: not every client uses it |
| Redirect (not DNS) | A web address, sent by a server | Yes | Yes | The address in the browser has to change |
CNAME, A and AAAA are standard DNS records. ALIAS and ANAME are names providers give to their own feature: the provider looks the target up and answers with its addresses. The HTTPS record is in RFC 9460.
What are the rules for a CNAME?
- Alone at its name. If a name has a CNAME, it has no A, AAAA, MX, TXT or any other data. Only the records DNSSEC adds may stand beside it (RFC 1034, 3.6.2; RFC 2181, 10.1; RFC 4035, 2.5).
- One per name. A name has one canonical name; two CNAMEs at the same name are an error (RFC 2181, 10.1).
- The target is a name. Not an IP address, not
https://, no path and no port. - Not at the root of the zone. The root always holds SOA and NS records, so the first rule leaves no room for a CNAME (RFC 1912, 2.4).
- Not as the target of MX or NS. The name in an MX or NS record must have addresses of its own and not be an alias (RFC 2181, 10.3).
- TXT and MX follow it too. Since nothing else lives at the alias, a lookup for its TXT or MX goes on to the target. That is why verification records are usually placed one label below, such as
_verify.shop.example.com.
Can the root domain have a CNAME?
No. example.com itself always has SOA and NS records, and a CNAME cannot share a name with them. Some panels accept the record anyway and then either break the domain's email and nameservers or quietly do something else with it.
What works instead: use a subdomain such as www and redirect the root to it; use an A or AAAA record if the platform gives you fixed addresses; or use the ALIAS, ANAME or CNAME flattening feature of your DNS provider, which answers the root with addresses.
Can a CNAME point to another CNAME?
Yes, and resolvers should follow the chain (RFC 1034, 3.6.2). Each step is another lookup and another place to break, so short is better. The standard sets no maximum; each resolver has its own limit. The checker on this page follows up to 8 steps and says when there are more.
A chain that comes back to a name it has already passed is a loop and never resolves. It usually appears when somebody points www to the platform and the platform's name back to www.
Why does a lookup show addresses instead of the CNAME?
Because something answers with addresses on the record's behalf. On Cloudflare this is what a record marked Proxied (orange cloud) does: the lookup shows Cloudflare's addresses and the CNAME stays hidden behind them. A platform that checks the CNAME by DNS will not find it; set the record to DNS only. Root domains on providers with ALIAS or flattening look the same way.
Why does the old value still appear?
Every DNS answer carries a TTL, in seconds, and a resolver may repeat the answer until it runs out. The same goes for the answer "this name does not exist", for as long as the zone's SOA record says (RFC 2308). So after a change, a resolver can still have the old value, or still say there is nothing.
To tell a wrong record from an old answer, compare the two: what the domain's own nameservers publish, and what a resolver has. The checker shows both, with the seconds that are left in the cache.
What are the common CNAME mistakes?
| What you see | Usual cause | What to do |
|---|---|---|
| The panel refuses the record: "already exists" | Another record at the same name | Find out what the old record does, then decide which one stays |
| Nothing is published | The domain was typed again in the name field, or the wrong panel was edited | Type only the part before the domain, in the panel the nameservers point to |
| The target ends with your own domain | The panel added your domain to a target typed without a final dot | Type the target with a final dot, if the panel accepts one |
| The target does not exist | A typo, or a service that was removed | Copy the target again from the platform, or delete the record |
| Addresses instead of a CNAME | A proxy or flattening is on | On Cloudflare, set the record to DNS only |
| It points to the right place and the site shows an error | The server does not know the name, or has no certificate for it | Finish the domain setup in the platform |
| Email stopped after the change | A CNAME was created at a name that received email | Remove it and restore the MX records of that name |
How to look up a CNAME from a terminal
These ask the resolver your computer uses, which may answer from its cache:
dig shop.example.com CNAME +noall +answer # Linux, macOS
nslookup -type=CNAME shop.example.com # Windows, Linux, macOS
Resolve-DnsName shop.example.com -Type CNAME # PowerShell
To skip the cache, ask the domain's nameservers: find them with dig example.com NS +short and repeat the first command with one of them, as in dig @ns1.example.com shop.example.com CNAME.
Is a forgotten CNAME a risk?
It can be. If a CNAME still points to a service you stopped using, and that service lets anyone claim the name you left, somebody else may put their own content under your domain. Review the CNAMEs of the domain from time to time, and delete the record in the same moment you cancel the service.
Other questions about CNAME
Can a CNAME point to an IP address?
No. The target of a CNAME is always a name. To point a name to an IP address, use an A record for IPv4 or an AAAA record for IPv6.
Is a CNAME the same as a redirect?
No. A CNAME works in the DNS and the address in the browser stays the same. A redirect is sent by a web server and changes the address.
Can I have a CNAME and a TXT record at the same name?
No. A name with a CNAME has no other data. Put the TXT record at another name, usually one label below.
Does the www need a CNAME?
Not necessarily. www can be a CNAME to another name or have its own A and AAAA records. A CNAME is handy when www has to follow a name that may change address.
Does a CNAME affect email?
Only at the name where it is created. A CNAME at shop.example.com does not touch the email of example.com. Never create one at a name that receives email.
Does a wildcard CNAME cover every subdomain?
Only the names that have nothing published. A record at *.example.com does not answer for a name that has any record of its own, nor for the root.
Where do you create a CNAME?
In the panel of whoever hosts the domain's DNS, which is not always where the domain was bought. The nameservers tell; the checker shows them. Step by step, by provider:
- How to add a CNAME at Registro.br
- How to add a CNAME at Hostinger
- How to add a CNAME at Locaweb
- How to add a CNAME at HostGator and KingHost
- How to add a CNAME at Cloudflare
- How to add a CNAME at GoDaddy
- How to add a CNAME at Vercel
- How to add a CNAME at Netlify
- How to add a CNAME at Namecheap
- How to add a CNAME at Porkbun
- How to add a CNAME at Name.com
- How to add a CNAME at Spaceship
- How to add a CNAME at Squarespace Domains
- How to add a CNAME at Wix
- How to add a CNAME at IONOS