Anticode Open builder

CNAME vs A record: which one your setup needs

An A record points a name at an IP address. A CNAME points a name at another name, and lets that other name decide the address. Use a CNAME when a host gives you a hostname to point at, an A record when it gives you an IP, and flattening or ALIAS when you need hostname-style pointing on a bare domain.

Updated · By the Anticode team

The two records in one line each

A record
shop.example.com A 203.0.113.10. A name maps directly to an IPv4 address. Its sibling, the AAAA record, does the same for IPv6.
CNAME record
www.example.com CNAME sites.host.net. The name is an alias. A resolver that finds it restarts the lookup at sites.host.net and uses whatever addresses that name has.

The practical difference is who controls the address. With an A record, you do: if the host moves to new servers, your record goes stale and the site breaks until you edit it. With a CNAME, the host does: they change the addresses behind their own name and your record keeps working. That's why hosting platforms, website builders and CDNs nearly always ask for a CNAME on a subdomain.

Which one to use

Picking a record for common setups
Your situationRecordWhy
Host gives you a hostname, you're connecting www or another subdomainCNAMEThe host can change servers without you touching DNS
Host gives you an IP addressA (and AAAA if they give IPv6)There's no name to alias
Connecting the bare domain, host gives a hostnameCNAME flattening or ALIAS/ANAME, if your DNS provider offers itA plain CNAME isn't allowed at the apex
Connecting the bare domain, host gives IPsA recordsAllowed at the apex alongside MX and other records
Verifying ownershipTXTNeither A nor CNAME; a TXT record holds a token the host reads

Why a root domain can't take a plain CNAME

The DNS rule is that a name with a CNAME can't have any other records. RFC 1912 puts it plainly: a CNAME isn't allowed to coexist with other data. The apex of every domain must carry an SOA record and NS records, and usually has MX records for email and TXT records for things like SPF. A CNAME there would have to replace all of them, which breaks the zone. So example.com CNAME sites.host.net is refused by standards-following DNS software, while www.example.com CNAME sites.host.net is fine, because www has nothing else on it.

The same rule catches people on subdomains too. If www already has an A record from an old host, or a TXT record someone added, a new CNAME on www will either be refused or conflict. Delete the old record for that exact name first.

CNAME flattening and ALIAS records

Several DNS providers offer a way round the apex problem. You enter something that looks like a CNAME at the root; the provider looks up the target's addresses itself and answers visitors with ordinary A and AAAA records. Cloudflare calls this CNAME flattening and applies it automatically at the apex. Other providers call the record type ALIAS or ANAME. To the rest of the internet the answer is a normal A record, so the zone stays valid, while you still get the benefit of following the host's name.

If your provider has none of these, the fallbacks are to use A records with addresses the host publishes (if it does), or to put the site on www and redirect the bare domain to it with your registrar's forwarding feature.

Mistakes and how to spot them

  • A CNAME pointing at a URL. The value is a hostname only: sites.host.net, never https://sites.host.net/.
  • A missing or extra trailing dot. In raw zone files, sites.host.net. with a final dot is absolute; without it the zone name is appended. Most web panels handle this for you, so only add the dot if the panel's examples do.
  • Chained CNAMEs. A CNAME to a name that is itself a CNAME works but adds lookups. Point at the name the host gives you, not at your own intermediate alias.
  • Checking too soon. Old answers stay cached for the previous record's TTL. Ask a public resolver directly: dig @1.1.1.1 www.example.com or nslookup www.example.com 1.1.1.1.

Where Anticode fits

When you connect your own domain to an Anticode site, the Domains section gives you a CNAME to add for the hostname, plus a TXT record when ownership needs verifying. That means a subdomain such as www or book works with any DNS provider. A bare domain works only where your provider supports CNAME flattening or ALIAS records; Anticode doesn't give out IP addresses for A records. The step-by-step version is in how to connect a custom domain.

Questions people ask

Is a CNAME slower than an A record?

It adds a lookup the first time a resolver sees the name, then both answers are cached. For a website the difference isn't something visitors notice.

Can I have a CNAME and MX records on the same name?

No. A name with a CNAME can't hold other records, which is exactly why mail and CNAMEs don't mix on the root domain.

Does CNAME flattening affect email?

No. Flattening only changes how the address records for the name are answered. Your MX, SPF and other records at the apex stay as they are.

Sources

  1. RFC 1912: Common DNS Operational and Configuration Errors, checked
  2. RFC 1034: Domain Names, Concepts and Facilities, checked
  3. CNAME flattening (Cloudflare DNS docs), checked