A Canonical Name (CNAME) record is a DNS entry that maps an alias name to a "true" or canonical domain name. It acts as a pointer, telling the internet that one web address is actually just another name for a different address. You use it to manage subdomains or external services without needing to track individual IP addresses.
What is a CNAME Record?
A CNAME record creates an alias for your domain. In the Domain Name System (DNS), it functions like a scavenger hunt where one clue leads you to another. Instead of providing the final answer (the IP address), the CNAME provides a different domain name that the computer must look up next.
For example, a record might state that blog.example.com is an alias for example.com. The "true name" or destination is the canonical name. This is a primary tool for marketers and web admins to point various services like blogs, shops, or landing pages to a central domain or a third party provider.
Why CNAME Records matter
CNAME records simplify the technical side of managing a web presence. They offer several practical benefits for site owners:
- Efficient updates: If your server IP address changes, you only need to update the A record of the root domain. All subdomains using CNAMEs will automatically follow the new IP.
- Service management: You can point hostnames for specific services like email, FTP, or content delivery networks (CDNs) to a single destination.
- Customer subdomains: Service providers can point unique customer subdomains (customer.service.com) back to a primary root domain (service.com).
- Global reach: You can register domains in different countries and point them all to one primary website for easier management.
- Traffic distribution: CNAMEs help redirect traffic to optimal CDNs based on location or server availability.
How a CNAME Record works
The process of resolving a CNAME involves multiple steps in a DNS query:
- Request: A user types an address like
www.example.cominto their browser. - Lookup: The DNS resolver looks for the record and finds a CNAME pointing to the root domain
example.com. - Restart: The client recognizes the alias and starts a new query specifically for the canonical name (
example.com). - Resolution: The resolver finds the A record for
example.com, which contains the actual IP address. - Connection: The browser uses that IP address to connect to the web server and load the site.
Restrictions and limitations
While versatile, CNAME records have strict rules defined by technical standards to prevent network errors.
No other records allowed
If a CNAME record exists for a specific name, no other DNS records can use that same name. You cannot have an MX record or a TXT record for blog.example.com if you already have a CNAME for it. This is based on [RFC 1034 guidelines for DNS implementations] (IETF), which requires that a name with a CNAME must have no other data present.
Zone apex limitation
A CNAME cannot be placed at the root domain level (the zone apex), such as example.com. This is because the root must have an SOA and NS record, and the "no other records" rule would be violated.
MX and NS record rules Mail exchange (MX) and Name Server (NS) records must never point to a CNAME alias. They must point to an A or AAAA record that leads directly to an IP address.
DNSSEC exception The only exception to the "no other records" rule is when you use DNSSEC. In these cases, security related records like RRSIG or NSEC can coexist with a CNAME.
Best practices
Map subdomains to the root
Point subdomains like shop.example.com or dev.example.com to your root domain. This ensures that if you move your hosting, you only change the IP address in one location (the root A record).
Avoid CNAME chains You can point one CNAME to another CNAME, but it is inefficient. Each extra link in the chain requires an additional DNS lookup, which slows down the site for users. Always point your alias directly to the final canonical name whenever possible.
Use for external services Use CNAMEs when connecting to third party services like HubSpot, Zendesk, or Google Apps. This allows those providers to change their server IPs without you needing to manually update your records.
Common mistakes
Mistake: Pointing a CNAME to an IP address. Fix: CNAME records must only point to domain names. If you need to point a name to an IP, use an A record instead.
Mistake: Creating a CNAME for the root domain. Fix: Use an A record or look for provider specific options like ALIAS or ANAME records to handle the root domain.
Mistake: Putting an MX record on an alias name. Fix: Move the MX record to the canonical domain name or use an A record for the alias instead of a CNAME.
Mistake: Creating an unresolvable loop. Fix: Ensure that Domain A does not point to Domain B while Domain B points back to Domain A.
CNAME vs. A Record and ALIAS Record
| Feature | CNAME Record | A Record | ALIAS/ANAME Record |
|---|---|---|---|
| Maps to | Another Domain Name | IP Address (IPv4) | Another Domain Name |
| Root/Apex use | No | Yes | Yes |
| Coexists with | Nothing (strict) | Other records | Other records |
| Performance | Can be slower (extra lookup) | Fastest | Fast (server side lookup) |
| Standardized | Yes | Yes | Non-standard |
While CNAMEs are a standard part of DNS technical specifications, [expiration of ANAME draft standards in January 2020] (IETF) means that ANAME or ALIAS types are often proprietary implementations by specific DNS providers.
FAQ
Can a CNAME point to a domain in a different DNS zone? Yes. A CNAME can point to any domain name anywhere on the internet. It does not have to be within your own account or local network. This is how many services, such as CDNs and managed hosting, work.
What happens if I search for a TXT record on a CNAME name? If you query a TXT record for a name that has a CNAME, the DNS server will return the CNAME record instead. You will then have to perform a second query on the target domain to find the actual TXT record you need. This is a common point of confusion for verifying domain ownership for marketing tools.
Why does my site feel slow when using CNAMEs? Because a CNAME requires the browser to perform at least two DNS lookups (one for the alias and one for the canonical name), it can add latency. This is especially true if you have a chain of multiple CNAMEs. This delay is noted in [RFC 2181 clarifications on CNAME usage] (IETF) as a reason to avoid unnecessary aliasing.
Does a CNAME change the URL shown in the browser?
No. A CNAME record only points the client to the correct IP address. The web server still sees the original URL requested by the user. For instance, if blog.example.com is a CNAME for example.com, the browser will still display blog.example.com in the address bar.
What is CNAME flattening? CNAME flattening is a non-standard feature offered by some DNS providers. It allows a CNAME to act like an A record by resolving the destination IP address at the DNS server level before responding to the user. This allows you to use CNAME like behavior at the root domain level.