What Is a CNAME Record? Alias Records Explained

A CNAME record creates an alias from one domain name to another. Instead of pointing to an IP address, it points to a hostname that the resolver then looks up separately.


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

text
; 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:

  1. Client asks: "What is the IP address of www.example.com?"
  2. Resolver finds a CNAME record: www.example.com → example.com.
  3. Resolver then queries for the A record of example.com.
  4. Resolver returns the IP address to the client along with the full CNAME chain.
text
; 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.10

CNAME 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.

text
; 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.5
Keep CNAME chains shortEach hop in a CNAME chain requires an additional DNS query. Long chains increase resolution latency and can cause failures if any link in the chain is slow or unavailable. Always aim for a direct CNAME pointing to a hostname with an A record.

CNAME 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.

CNAME conflict with MX and TXT recordsA common mistake is creating a CNAME for a name that also has MX records for email. This is invalid and will cause mail delivery failures. If you need both a web alias and email on the same name, use an A record instead of a CNAME.

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

FeatureA RecordCNAME Record
Points toIPv4 addressAnother hostname
Usable at root domainYesNo (use ALIAS/ANAME instead)
Can coexist with MXYesNo
IP update required?Yes, when IP changesNo — follows target automatically
Resolution speedOne lookupTwo or more lookups
Best forRoot domain, fixed IPsSubdomains 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.

text
; 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:

text
; 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.

Related Articles