A CNAME (Canonical Name) record is a type of DNS resource record that maps an alias domain name to a true or canonical domain name. Unlike A or AAAA records, a CNAME record does not point a hostname directly to an IP address; instead, it instructs the DNS resolver to look up another domain name to find the final destination. This indirection makes CNAME records essential for routing subdomains to third-party services, content delivery networks (CDNs), and cloud load balancers without hardcoding infrastructure IPs.
How it works
When a recursive DNS resolver queries a subdomain and encounters a CNAME record, it restarts the resolution process using the target canonical name specified in the record. If that target domain also has a CNAME record, the resolver follows the chain until it reaches an A (IPv4) or AAAA (IPv6) record, returning the resolved IP address to the client.
This abstraction layer simplifies DNS administration. When a hosting provider or CDN changes its underlying server IP addresses, only the provider needs to update the A record on the canonical target. Every subdomain pointing to that target via a CNAME automatically resolves to the new infrastructure without manual intervention from the domain owner.
Example
Suppose you host a documentation portal on a managed platform that provides a default hostname of docs-hosting.provider.net, and you want users to access it at docs.example.com. In your DNS zone file, you add the following record:
docs.example.com. 3600 IN CNAME docs-hosting.provider.net.
You can verify the resolution chain from the command line using dig:
$ dig +short docs.example.com
docs-hosting.provider.net.
203.0.113.42
The output confirms that docs.example.com aliases to docs-hosting.provider.net, which subsequently resolves to the IPv4 address 203.0.113.42.
What matters when choosing a server or hosting
When selecting a DNS provider or hosting platform, support for CNAME flattening (also known as ALIAS or ANAME records) is critical if you plan to host your root domain on cloud infrastructure with dynamic IP addresses. Standard DNS specifications prohibit CNAME records at the zone apex (such as example.com), so providers that offer proprietary flattening resolve the target IP at the authoritative nameserver level and return a standard A record to clients.
Additionally, evaluate how your provider handles Time to Live (TTL) values and anycast DNS routing. Because CNAME resolution requires an extra lookup step when records are uncached, a fast, globally distributed authoritative DNS network minimizes initial connection latency.
Common mistakes
- Placing a CNAME at the zone apex: According to RFC 1034, a CNAME record cannot coexist with any other record type for the same hostname. Because a root domain always requires
NSandSOArecords, adding a CNAME at the apex breaks DNS resolution and can disrupt email delivery. - Pointing MX or NS records to a CNAME: Mail exchange (
MX) and nameserver (NS) records must point directly to hostnames withAorAAAArecords. Pointing them to a CNAME violates DNS standards and frequently causes mail servers to reject or drop messages. - Creating long CNAME chains or loops: Chaining multiple CNAME records together adds unnecessary DNS lookup latency, while circular references cause resolution failures.
FAQ
Can I use a CNAME record for my root domain?
Not with a standard CNAME record, because the root domain (zone apex) already contains mandatory SOA and NS records. To point a root domain to a dynamic cloud endpoint, use a DNS provider that supports CNAME flattening, ALIAS, or ANAME records.
Does a CNAME record affect page load speed?
An uncached CNAME lookup adds a minor delay because the resolver must perform an additional query to find the target IP address. Once cached according to the record's TTL, the performance impact is negligible.
What is the difference between a CNAME record and an HTTP redirect?
A CNAME operates at the DNS layer, meaning the browser's address bar keeps showing the original subdomain while loading content from the target server. An HTTP redirect (such as a 301 or 302 status code) operates at the application layer and explicitly sends the user's browser to a different URL.