CNAME record at a glance

FieldValue
Type code5
Defined inRFC 1035; rules clarified in RFC 2181, section 10
ValueOne hostname, such as example-com.cdn.example.net.
Allowed at the apexNo, because the apex must hold SOA and NS records
Can share a name withNothing except DNSSEC records (RRSIG, NSEC)

Here is how a CNAME record looks in a zone file:

www.example.com.   3600  IN  CNAME  example-com.cdn.example.net.
shop.example.com.  3600  IN  CNAME  stores.saas-vendor.example.

The trailing dot marks the target as a fully qualified name. Without it, many zone file tools append your zone, producing a target such as example-com.cdn.example.net.example.com.

How resolvers follow a CNAME

Say a browser asks for the A record of www.example.com. The resolver finds a CNAME there instead, restarts the lookup at the target, and returns both: the CNAME and the target's A records. One query from the client, but the resolver may need extra lookups, especially when the target lives in another provider's zone.

Targets can themselves be CNAMEs, forming a chain. Resolvers cap chain length to avoid loops, and each hop adds a lookup the first time, so keep chains short. A CNAME to a name that does not exist produces an NXDOMAIN answer for your alias.

Where a CNAME cannot go

Because a CNAME means "this name is really that one", the name cannot also hold its own data. That rule has three practical effects:

  • No CNAME at the zone apex. example.com must have SOA and NS records, so it cannot be a CNAME. Providers offer ALIAS, ANAME or "CNAME flattening" to fill the gap; CNAME at the zone apex explains how they work.
  • No CNAME next to MX or TXT. If mail.example.com is a CNAME, you cannot also publish TXT there.
  • MX and NS targets must not be CNAMEs. RFC 2181 section 10.3 forbids it, and some mail servers refuse delivery when they meet one.

Dangling CNAMEs

A CNAME keeps pointing at its target after you stop using the service. If the target is a cloud or SaaS name that someone else can register, such as a deleted storage bucket or app hostname, they can claim it and serve content on your subdomain. Remove CNAMEs when you retire a service. Dangling DNS and subdomain takeover covers detection and cleanup.

How to look up a CNAME record

Each tool below sends the query to your default resolver unless you name a server. Swap in your own domain for example.com, and add a public resolver such as 1.1.1.1 to compare answers with what your network sees.

dig (macOS, Linux, WSL)

CommandWhat it does
dig www.example.com CNAMEOnly the CNAME record, not what it points to
dig +short www.example.comThe chain: each alias target, then the final addresses
dig +noall +answer www.example.com AThe CNAME lines and the A records at the end of the chain
dig @ns1.example.com www.example.com CNAME +norecurseThe CNAME exactly as your authoritative server publishes it

nslookup (Windows, macOS, Linux)

CommandWhat it does
nslookup -type=CNAME www.example.comThe canonical name the alias points to
nslookup www.example.comThe final addresses, with the alias listed under "Aliases"
nslookup -type=CNAME www.example.com 1.1.1.1The same question, asked of Cloudflare

PowerShell (Windows)

CommandWhat it does
Resolve-DnsName -Name www.example.com -Type CNAMEThe CNAME record; its target is in the NameHost column
Resolve-DnsName www.example.comThe CNAME row followed by the A and AAAA rows of the target
(Resolve-DnsName www.example.com -Type CNAME -DnsOnly).NameHostJust the target name, DNS only

Common mistakes

  • Trying to put a CNAME at the apex. Use your provider’s ALIAS or flattening feature, or A and AAAA records.
  • Missing trailing dot in a zone file. The target becomes a name inside your own zone and resolves to nothing.
  • Pointing MX at a CNAME. Point MX at a hostname with its own A or AAAA records.
  • Leaving a CNAME behind after a SaaS trial ends. Audit CNAMEs that point outside your domain.
  • Long chains across several providers. Each hop is another place an outage or misconfiguration can break the name.

CNAME records in Domain Visualizer

Domain Visualizer looks up a CNAME at www on every scan, and at autodiscover and other common subdomains in an advanced scan. The record detail panel shows the alias target, so you can see at a glance which provider controls a name.

FAQ

Is a CNAME slower than an A record?

Slightly, the first time. The resolver needs an extra lookup for the target, but it caches both answers, so later queries are as fast as a direct A record until the TTLs expire.

Can a CNAME point to an IP address?

No. A CNAME target must be a hostname. To point a name at an IP address, use an A or AAAA record.

Does a CNAME affect email for the name?

Yes. A name that is a CNAME cannot hold MX or TXT records of its own, so mail settings for it come from the target name instead. Avoid CNAMEs on names that need their own mail records.

Sources and further reading