A DNS CNAME record (Canonical Name record) creates an alias from one domain name to another. Rather than storing an IP address directly, a CNAME points to a target hostname — the "canonical" name — and DNS resolvers follow that pointer to find the actual address. This indirection makes CNAME records ideal for subdomains that need to track another hostname automatically.
What Is a CNAME Record?
When a resolver queries a CNAME record, it receives a target domain name instead of an IP address. The resolver then performs a second lookup for that target, following the chain until it reaches an A or AAAA record. From the user's perspective, the process is transparent — it looks like a single domain lookup.
CNAME records are useful when a hostname's IP address changes frequently or is controlled by a third party. Instead of tracking IP updates manually, you maintain a single CNAME that always points to the vendor's hostname, and they handle the IP management.
CNAME Record Syntax
; CNAME record syntax
; NAME TTL CLASS TYPE TARGET (canonical name)
www.example.com. 3600 IN CNAME example.com.
shop.example.com. 3600 IN CNAME stores.shopify.com.
cdn.example.com. 300 IN CNAME example.cdn.cloudflare.net.The RDATA field of a CNAME record is always a fully qualified domain name (FQDN) — another hostname rather than an IP address. Resolvers follow this name to reach the eventual A or AAAA record.
How CNAME Resolution Works
The resolution process for a CNAME follows a chain of lookups:
- Client asks: "What is the IP address of
www.example.com?" - Resolver finds a CNAME record:
www.example.com → example.com. - Resolver then queries for the A record of
example.com. - Resolver returns the IP address to the client along with the full CNAME chain.
; Example resolution chain
www.example.com. 3600 IN CNAME example.com.
example.com. 3600 IN A 203.0.113.10
; What the resolver returns to the client:
; www.example.com → example.com → 203.0.113.10CNAME Chains
A CNAME can point to another CNAME, creating a chain. While technically valid, chains longer than two or three hops add latency and are considered poor practice. Some resolvers and DNS providers enforce limits on chain depth (typically 8–10 hops) to prevent infinite loops.
; CNAME chain (avoid when possible)
www.example.com. 300 IN CNAME alias.example.com.
alias.example.com. 300 IN CNAME server.example.net.
server.example.net. 300 IN A 198.51.100.5CNAME Restrictions
CNAME records come with two important restrictions that trip up many DNS administrators:
Rule 1: CNAMEs Cannot Coexist with Other Record Types
A CNAME record must be the only record at a given name (with the exception of DNSSEC records like RRSIG). You cannot have a CNAME and an MX record at the same name, for example. This is defined in RFC 1034 and enforced by most authoritative DNS servers.
Rule 2: CNAMEs Cannot Be Used at the Root Domain (Zone Apex)
The root domain (also called the apex) — example.com without any subdomain — cannot have a CNAME record. The apex must have an SOA record and NS records, and those cannot coexist with a CNAME. This is a hard requirement of the DNS specification.
To work around this, many DNS providers offer a proprietary feature called ALIAS, ANAME, or CNAME flattening that behaves like a CNAME at the apex but publishes A/AAAA records to resolvers. Check whether your DNS provider supports this feature if you need root-domain aliasing.
CNAME vs. A Record Comparison
| Feature | A Record | CNAME Record |
|---|---|---|
| Points to | IPv4 address | Another hostname |
| Usable at root domain | Yes | No (use ALIAS/ANAME instead) |
| Can coexist with MX | Yes | No |
| IP update required? | Yes, when IP changes | No — follows target automatically |
| Resolution speed | One lookup | Two or more lookups |
| Best for | Root domain, fixed IPs | Subdomains tracking CDNs, SaaS |
Common CNAME Use Cases
www Subdomain
The most common CNAME use case is pointing www.example.com to the root domainexample.com. This ensures the www version always follows wherever the root resolves, without maintaining two separate A records.
CDN Integration
Content delivery networks (CDNs) like Cloudflare, Fastly, and Akamai ask you to create a CNAME pointing your subdomain to their edge hostname. When the CDN updates its IP addresses (for routing optimization or failover), your DNS automatically follows without any changes on your end.
; CDN CNAME example
static.example.com. 300 IN CNAME example.cdn-provider.net.SaaS Custom Domains
SaaS platforms (Shopify, HubSpot, Zendesk, GitHub Pages) routinely ask customers to create a CNAME so they can serve content from a custom domain. The provider controls the target hostname and can update its infrastructure without requiring any action from their customers.
How to Check a CNAME Record
Use the ShowDNS DNS Lookup tool to query CNAME records. Select CNAME as the record type, enter the hostname, and the tool returns the current canonical target and TTL. You can also use dig on the command line:
; Query a CNAME record with dig
dig www.example.com CNAME
;; ANSWER SECTION:
www.example.com. 3600 IN CNAME example.com.Frequently Asked Questions
Can I use a CNAME for my root domain?
No — the DNS specification (RFC 1034) prohibits CNAME records at the zone apex because the root domain must carry SOA and NS records, which cannot coexist with a CNAME. Some DNS providers offer an ALIAS or ANAME record type that behaves like a CNAME for the root domain, resolving the target and publishing A/AAAA records to clients. Check your DNS provider's documentation for this feature.
Why can't a CNAME coexist with an MX record?
RFC 1034 states that if a CNAME is present at a name, no other data should exist at that name. This is because a CNAME instructs the resolver to treat the name as an alias — having an MX record at the same name would be contradictory. If you need email (MX) and a web alias at the same hostname, use an A record for the web server and keep MX records alongside it.
What is the difference between CNAME and ALIAS/ANAME?
CNAME is a standard DNS record type defined in the original DNS RFCs. ALIAS (also called ANAME or CNAME flattening) is a non-standard extension invented by DNS providers to allow CNAME-like behavior at the zone apex. From the client's perspective, an ALIAS record appears as a normal A or AAAA record. The resolution happens server-side at the authoritative nameserver rather than at the recursive resolver.
How many CNAME hops are allowed?
The DNS specification does not set a strict limit, but most resolvers and DNS implementations enforce a practical maximum of 8 to 10 hops to prevent infinite loops. In practice, you should never create chains longer than two or three records. Longer chains increase latency and are harder to debug.
Does a CNAME affect email delivery?
If you place a CNAME at a hostname that also receives email (has MX records), it will break mail delivery because a CNAME cannot coexist with MX records. For mail-receiving hostnames, always use A records rather than CNAMEs. Subdomains used purely for web traffic (like www orcdn) are safe to CNAME since they have no MX records.