DNS Lookup

What is a CNAME record?

The record that makes one name an alias of another; the usual way to set up www and external services.

A CNAME (Canonical Name) is a DNS record saying that one name is an alias of another. When a resolver meets a CNAME, it continues the lookup with the target name and finally returns the target's A or AAAA record.

www.example.com.   3600   IN   CNAME   example.com.
example.com.       3600   IN   A       203.0.113.10

In this example a lookup for www.example.com is first sent to example.com and then returns 203.0.113.10. When the server's IP address changes, you only update the A record of example.com; www follows automatically.

When is a CNAME used?

  • The www subdomain. The most common way to connect www to the main domain.
  • Hosting and SaaS services. Services like Netlify, Vercel, GitHub Pages, Shopify and Webflow give you a name such as yourshop.myshopify.com instead of an IP address. Because their IP addresses can change, they ask you to use a CNAME.
  • CDNs. Content delivery networks ask you to point a name like cdn.example.com at their infrastructure with a CNAME.
  • Service verification and email. Microsoft 365's DKIM records and the tracking and verification records of many newsletter services are added as CNAMEs.

How do you add a CNAME record?

FieldExampleNotes
Name / HostwwwEnter only the subdomain part; the panel adds the domain itself.
TypeCNAME
Value / Targetexample.comThe full name to point to. Not an IP address.
TTL3600

If the panel doesn't expect the full name in the "Name" field and you type www.example.com, the record ends up as www.example.com.example.com. Always look the record up after saving it.

CNAME rules

CNAME is powerful but has strict rules. They're defined in RFC 1034 and RFC 2181, and most setup mistakes come from them.

A name with a CNAME can't have other records

If a name is a CNAME, you can't add MX, TXT, A or any other record to the same name. For example, if support.example.com is a CNAME, you can't add a verification TXT record to it. Even where a panel allows it, the result is inconsistent and resolvers ignore one of the records.

No CNAME at the root of a domain

The domain itself (example.com, i.e. @) always has SOA and NS records, so by the rule above it can't be a CNAME. If your service gives you a name for the root domain too, you have two options:

  • Add the IP addresses the service gives for the root domain as A records.
  • If your DNS provider supports it, use an ALIAS / ANAME record or Cloudflare's CNAME flattening. These aren't standard record types; the provider resolves the target itself and publishes it as an A record.

MX and NS must not point to a CNAME

The target of MX and NS records must be a name with an A record directly. If you wrote MX 10 mail.example.com, mail.example.com should be an A record, not a CNAME.

Keep chains short

A CNAME can point to another CNAME, but every step is an extra lookup, and if any link in the chain breaks the whole name stops working. Keep it to one step where you can.

A record or CNAME?

SituationChoice
Root domain (example.com)A (or ALIAS if your provider supports it)
You were given an IP addressA
You were given a name (*.vercel.app, *.myshopify.com)CNAME
The same name also needs MX or TXT recordsA
www should go where the root domain goesCNAME

CNAME vs redirect

A CNAME is not a web redirect. When you point www.example.com at example.com with a CNAME, the browser's address bar still shows www.example.com; the server serves the same site under both names. To send visitors to one address (also recommended for SEO) you need a 301 redirect on the web server. That's done in the server settings or .htaccess, not in DNS.

Likewise, the SSL certificate has to cover the name you added the CNAME for. If the target service doesn't issue its own certificate automatically, the browser shows a security warning.