Pingie.net

CNAME or A Record: Which One Your Domain Actually Needs

Choosing between a CNAME and an A record comes down to one question: do you know the server's IP address, or only its hostname? This guide explains the difference between the two, the rule that keeps CNAMEs off your root domain, and how to check which one a name actually uses.

Simon MeierPublished ยท 7 min read
Illustration comparing an A record that points a domain straight at a server with a CNAME that points to another name first
Key takeaways The short version, before the details.
  1. An A record points a name straight at an IPv4 address. A CNAME points a name at another name.
  2. A CNAME cannot share its name with any other record, so it cannot sit on your root domain.
  3. For the root domain, use an A record or your DNS provider's alias (flattening) feature.

CNAME vs A record: the short answer

When you choose between a CNAME vs A record, the A record wins whenever you have a fixed IP address to point at. The CNAME wins when a service gives you a hostname instead, such as a CDN, a website builder or a hosted shop. That service can then change its IP addresses without you having to touch your DNS.

There is one hard limit: a CNAME cannot live on your bare domain (example.com). It does work on subdomains like www.example.com or shop.example.com.

What is an A record?

An A record (A for address) maps a name directly to an IPv4 address. When a browser asks for example.com, the resolver gets back a number it can connect to right away.

example.com.    3600    IN    A    203.0.113.10
example.com.Name

The hostname this record answers for.

3600TTL

How many seconds resolvers may cache the answer.

AType

Says that an IPv4 address follows.

203.0.113.10Value

The server the name points to.

A name can hold several A records, which spreads visitors across servers. The AAAA record is the IPv6 version and works the same way with an IPv6 address.

What is a CNAME record?

A CNAME (canonical name) record marks a name as an alias for another name. It never holds an IP address. The resolver follows the alias to the target name and looks up that name's A or AAAA records instead.

www.example.com.    3600    IN    CNAME    example.net.

This is what a resolver does when someone visits www.example.com:

Asked forwww.example.com
CNAMEexample.net
A198.51.100.20

The benefit is that the owner of example.net can move to new servers and your www name follows automatically. The cost is one extra lookup. Resolvers usually cache it, so visitors rarely notice.

Difference between A record and CNAME record

FeatureA recordCNAME record
Points toAn IPv4 addressAnother hostname
Extra lookupNoYes, to resolve the target
Allowed on root domainYesNo
Can share its name with MX, TXT and other recordsYesNo
When the server's IP changesYou update the recordThe target's owner updates theirs
Typical useRoot domain, your own serverswww and subdomains that point at hosted services

Why a CNAME cannot share a name with other DNS record types

The DNS specification, RFC 1034, says that if a name has a CNAME, no other data may exist at that name. The reason is simple: a CNAME says that everything about this name lives somewhere else. If the name also had its own TXT or MX record, resolvers would get two conflicting answers.

So a name with a CNAME cannot also carry an MX, TXT, A or any other ordinary record type. Most DNS dashboards won't let you save that combination. RFC 2181 adds a related rule: MX and NS records must point to a name that has its own address records, never to an alias. Our guide to how MX records route email covers that side in more depth.

Why you cannot use a CNAME on the root domain

Every root domain (the zone apex, meaning example.com with no prefix) must have an SOA record and NS records. Those records already exist at that name, so the no-other-data rule leaves no room for a CNAME. That is why hosting guides tell you to add an A record for example.com and a CNAME for www.example.com.

If you put a CNAME on a name that also needs email, the CNAME takes priority. Your MX and TXT records for that name, including SPF and DMARC, will then be rejected by your DNS panel or ignored by resolvers. Keep mail-related records on names that have no CNAME.

Alias record vs CNAME: what is the difference?

The root domain cannot hold a CNAME, so many DNS providers offer a workaround called an ALIAS record, an ANAME record or CNAME flattening. You enter a hostname, just as you would for a CNAME. The provider then looks up that hostname's IP addresses itself and serves them as ordinary A and AAAA records.

  • To the outside world, an alias record looks like a normal A record, so it can sit on the root domain next to MX and TXT records.
  • To you, it behaves like a CNAME: when the target's IP changes, your answer changes with it.
  • It is not a standard record type. Each provider builds it differently. Amazon Route 53 alias records, for example, can only point at certain AWS resources.

Your provider may have no alias option while your host only gives you a hostname. In that case, ask the host for fixed IP addresses for the root domain. Or redirect example.com to www.example.com and put the CNAME on www.

Which record should you use for each setup?

SetupUse
Root domain on a server with a fixed IPA record (plus AAAA for IPv6)
Root domain on a host that only gives a hostnameAlias or flattened record, or A records with the IPs the host publishes
www or a subdomain on a CDN, site builder or hosted appCNAME to the hostname they give you
Several subdomains on one server you runAn A record on one name and CNAMEs on the rest, so moving servers takes one edit
A subdomain that also receives emailA record, since a CNAME would block MX and TXT records
Domain ownership check for a serviceWhatever type the service asks for, exactly as written

How to check if a domain uses a CNAME or an A record

Open the DNS lookup tool, enter the hostname and pick a record type:

  • CNAME shows the alias target if the name has one. If it has none, the tool reports that no CNAME records were found, which usually means the name uses A records directly.
  • A shows the IPv4 addresses the name ends up at. For an alias, these are the target's addresses, because the resolver follows the CNAME for you.
  • ANY runs A, AAAA, MX, NS, TXT and CNAME queries in one go. It's a quick way to spot a CNAME sitting next to records it should not have.
See which record a name usesLook up A, CNAME and other records for any domainOpen tool

In a terminal, dig shows the whole chain in one answer:

dig www.example.com A +noall +answer

If the first answer line says CNAME and a later one says A, the name is an alias. On Windows you can run the same check with nslookup. See our nslookup command examples. If you just changed a record and still see the old value, caching is the cause. It's explained in how DNS propagation works.

Ready to confirm your DNS setup?

  • See whether www is a CNAME and where it points
  • Check the IP addresses your root domain returns
  • Spot a CNAME sharing a name with other records
Look up your records

Frequently asked questions

Slightly, on the first lookup. The resolver has to fetch the CNAME and then the target's A record. Both answers are cached for their TTL, so repeat visitors are served from the cache and the gap is usually tiny. Avoid long chains of CNAMEs that point at more CNAMEs, because each hop adds another lookup.

No. A name with a CNAME cannot hold any other record, including an A record. Pick one: an A record if you have a fixed IP address, or a CNAME if a service gave you a hostname. Using both on different names is fine, such as an A record on example.com and a CNAME on www.example.com.

No. A CNAME value must be a hostname. If you type an IP address into a CNAME field, most DNS panels reject it. Any panel that accepts it treats the numbers as a hostname, and no such hostname exists. Use an A record for IPv4 addresses and an AAAA record for IPv6 addresses.

Email, yes: a name with a CNAME cannot have its own MX or TXT records, so keep mail on names without one. SEO, no: search engines see the page visitors get, not the record type that delivered it. Redirects and duplicate hostnames matter for SEO, but the DNS record type does not.

Most people use a CNAME. If you point www at your root domain or your host's hostname, moving servers only takes one change. Use an A record on www only if www also needs records that a CNAME would block, or if your host tells you to use fixed IP addresses.