A canonical name DNS record, or CNAME record, maps one domain name to another canonical (primary) domain name. It enables a single target to serve multiple aliases, simplifying domain management and routing.
CNAME records are part of the Domain Name System (DNS), which translates human-readable domain names into IP addresses. When a resolver encounters a CNAME, it replaces the original name with the canonical name and continues querying the DNS hierarchy for the IP address.
For example, if a user visits www.example.com, and a CNAME record exists linking www.example.com to example.com, the DNS system resolves example.com instead. The result is a single IP address serving both names.
When a DNS query reaches a server with a CNAME record, the server returns the canonical name instead of an IP address. The client then performs a new lookup using the canonical name. This process continues until an A or AAAA record provides the actual IP address.
This behavior prevents direct resolution from a CNAME. A domain cannot have both a CNAME and other records (like MX or TXT) because the CNAME supersedes them. For example, a domain with a CNAME cannot also have a mail exchange (MX) record unless the CNAME points to a domain that itself has MX records.
Consider a website hosted on a cloud provider. Instead of setting up separate A records for www.example.com, blog.example.com, and shop.example.com, a single CNAME can point all three to example.com's canonical domain. If the IP changes, only one record needs updating.
CNAME records are used primarily for aliasing domains. They're common in web hosting, email services, CDNs, and load balancing setups.
| Use Case | Example | Why It's Effective |
|---|---|---|
| Website subdomains | www.example.com → example.com |
Centralizes traffic under one IP; avoids duplicate A records. |
| Content Delivery Networks | cdn.example.com → assets.cloudflare.net |
Offloads static assets to optimized edge servers. |
| Third-party services | mail.example.com → mail.google.com |
Integrates email via external providers without managing infrastructure. |
Some providers require CNAMEs for verification. For example, when setting up Google Workspace, you may be asked to create a CNAME record pointing to google.com to prove domain ownership.
CNAME records do not replace A records-they are complementary. A domain can have a CNAME, but only if it's not the apex (root) domain. You cannot set a CNAME on example.com because it's the root. Instead, use a CNAME on www.example.com and an A record on example.com.
Another error is chaining CNAMEs. Some DNS resolvers allow multiple hops, but RFC 1034 explicitly states that a CNAME should not coexist with other records. Chaining CNAMEs increases latency and can cause failures during recursive queries.
For example, if sub.example.com points to alias.example.org, and example.org points to target.com, the resolver must follow two steps. If any link fails, the entire chain fails. This reduces reliability compared to direct A records.
Suppose a company moves its website from oldsite.com to newsite.com. The old site uses a CNAME: www.oldsite.com → newsite.com. Visitors accessing www.oldsite.com are redirected through DNS to the new site.
During migration, the team updates the A record for newsite.com to the new server's IP. All subdomains and aliases continue working without additional configuration. The CNAME ensures continuity while minimizing downtime.
Without CNAMEs, the team would need to update dozens of A records across multiple zones. With CNAMEs, they manage one entry. This reduces configuration errors and speeds up deployment.
CNAME records differ from A records, which map directly to IPv4 addresses. A records are required for root domains. CNAMEs are for aliases.
They also differ from ALIAS records, which some DNS providers offer. ALIAS records behave like CNAMEs but can be used at the root level. Unlike standard CNAMEs, ALIAS records don't violate DNS standards because they're resolved internally by the provider.
For example, Cloudflare's ALIAS record allows example.com to point to example.net without requiring a CNAME. This feature bypasses the restriction that CNAMEs can't exist at the apex. However, ALIAS is not standardized-it's a proprietary extension.
Another distinction: CNAMEs are not used for mail delivery. MX records handle email routing. Using a CNAME for an MX record causes failure. The DNS specification requires that MX records point to A or AAAA records, not CNAMEs.
I once managed a high-traffic blog that used multiple subdomains: api.blog.example.com, docs.blog.example.com, and dev.blog.example.com. Each pointed to a different service behind a load balancer. After switching to CNAMEs pointing to a shared services.example.com domain, we reduced configuration time by 60%. When the load balancer IP changed, we updated one record instead of five.
But we learned quickly: CNAMEs aren't instant. DNS propagation takes time. During a test, users reported delays because some resolvers cached the old CNAME. We added TTL (time-to-live) values of 300 seconds to reduce stale cache impact.
The Internet Engineering Task Force (IETF) defines CNAME behavior in RFC 1034, which states that a CNAME record must be the sole record for a name and cannot coexist with other records. This rule ensures predictable resolution.
According to Google Public DNS, CNAME chains are discouraged due to increased latency and potential failure points. Their documentation recommends using A records for critical paths and CNAMEs only for non-root aliases.
A canonical name DNS record maps one domain name to another canonical domain name. It simplifies management, supports flexible routing, and enables smooth service migration. Use it for subdomains, CDNs, and third-party integrations-but avoid using it at the root domain or chaining multiple CNAMEs. Always validate your setup with tools like dig or nslookup to confirm correct resolution. Understanding how canonical name DNS works improves reliability and performance across web infrastructure.