How a CNAME works
www.example.com. 300 IN CNAME example.cdn-provider.net.
example.cdn-provider.net. 60 IN A 192.0.2.10
A resolver asking for www.example.com finds the CNAME, then looks up example.cdn-provider.net and returns both. The name on the left of a CNAME has no records of its own: everything comes from the target.
When to use one
CNAMEs suit names that point at a service you don’t control, such as a CDN, a hosted shop or a help desk. When the provider changes its addresses, your record keeps working.
What can go wrong
- CNAME at the apex. Breaks mail and other records for the domain. Use your host’s flattening feature.
- Dangling CNAME. The target no longer exists, often after cancelling a service. Remove the record. Otherwise someone else may be able to claim the target name and serve content on your subdomain.
- Long chains. Each hop is another lookup and another TTL. Point straight at the final target where you can.
Questions
Can the bare domain (example.com) be a CNAME?
No. The zone apex must hold SOA and NS records, and a CNAME cannot exist next to other records. DNS hosts work around this with ALIAS, ANAME or CNAME flattening, which publish the target's addresses as A records.
Can a CNAME and an MX or TXT record share a name?
No. If a name is a CNAME, it can have no other records (except DNSSEC ones). Put the other records on a different name, or replace the CNAME with A/AAAA records.
How many CNAMEs can be chained?
There is no fixed limit in the standard, but resolvers give up after about 8 to 16 steps, and every step adds lookup time. Keep chains short.