DNS & Domain Names

CNAME Records and the Apex Domain Problem

Understand how CNAME aliases work, why you cannot place one on a bare domain and which workarounds actually solve it.

Key takeaways

  • A CNAME points a name at another name, never at an IP address or a web address.
  • A name with a CNAME cannot hold other ordinary records such as MX, TXT or NS.
  • The apex of a domain must carry SOA and NS records, so a standard CNAME is not allowed there.
  • Common solutions are provider-side flattening or alias records, fixed A and AAAA records, or redirecting the apex to www.

A CNAME record makes one name an alias of another. It says: for anything you want to know about www.example.com, go and look up site.host.example.net instead. You cannot use one on your bare domain, example.com, because a CNAME may not share a name with other records, and a bare domain always has some.

That restriction catches people when a hosting platform says "point your domain at this hostname". For www it takes ten seconds. For the bare domain you need one of a few workarounds, and they differ in how well they behave.

How a CNAME resolves

www.example.com.        3600  IN  CNAME  site.host.example.net.
site.host.example.net.   300  IN  A      198.51.100.25

When a resolver asks for the address of www.example.com and finds a CNAME, it restarts the search with the target name. The client receives the alias and the final address together.

Following an alias to an address
Resolver Your DNS host Platform's DNS Address of www.example.com? 1 CNAME to site.host.example.net 2 Cached with its own TTL Address of site.host.example.net? 3 A record 198.51.100.25 4 The platform can change this any time Resolver Your DNS host Platform's DNS Address of www.exam ple.com? 1 CNAME to site.host.ex ample.net 2 Cached with its own TTL Address of site.host.example.net? 3 A record 198.51.100.25 4 The platform can change this any time

The benefit is in that last note. The platform can change addresses, add capacity or steer visitors by region without asking you to edit anything. You said "wherever that name points", and they control where it points.

CNAME stands for "canonical name". The target is the canonical, or official, name, and the record's owner name is the alias.

The rules

  • The target is a name. CNAME 192.0.2.10 is wrong. Use an A record for addresses.
  • No scheme, port or path. https://host.example.net/page is not a valid target. DNS knows nothing about web paths.
  • Nothing else at the same name. Apart from DNSSEC's own records, a CNAME stands alone. You cannot give www both a CNAME and a TXT record.
  • One CNAME per name. There is no round robin of aliases in standard DNS.
  • MX and NS targets should not be aliases. Those must point at names that have address records.
  • Chains are legal but costly. An alias to an alias adds lookups and points of failure.

A CNAME is also not a redirect. The browser's address bar still shows www.example.com. The server it reaches has to be configured to answer for that name and present a certificate that covers it. If the platform does not know about your hostname, you will see an error page or a certificate warning even though DNS is correct.

Why the apex cannot have one

The apex is the top name of a zone, such as example.com. Every zone needs an SOA record and NS records there. You may well want MX records for email and TXT records for verification there too.

A CNAME claims the whole name: every question about it is supposed to be answered by the target. That conflicts with the SOA and NS records, so the standards forbid the combination. Some software will let you enter it anyway, and the results range from rejection to email that silently stops arriving.

A subdomain versus the apex
www.example.com Can be a CNAME Usually holds nothing else Target can change freely Works with any DNS host example.com Must hold SOA and NS Often holds MX and TXT Standard CNAME not allowed Needs a workaround to follow a hostname VS www.example.com Can be a CNAME Usually holds nothing else Target can change freely Works with any DNS host example.com Must hold SOA and NS Often holds MX and TXT Standard CNAME not allowed Needs a workaround to follow a hostname

Workarounds

Alias records and CNAME flattening

Many DNS providers offer a record type called ALIAS or ANAME, or a feature called CNAME flattening. You enter a hostname at the apex. The provider's servers look up that hostname themselves and answer queries with ordinary A and AAAA records.

To the outside world it looks like a normal address record, so no rule is broken and MX and TXT can coexist.

Things to check:

  • It is a provider feature, not a standard record type. Moving to another DNS host means finding their equivalent.
  • The lookup happens from the provider's servers, so location-based steering by the target may be less accurate.
  • The provider chooses how often to refresh. A change at the target takes a little longer to reach you.
  • Combined with DNSSEC, support varies.

Fixed A and AAAA records

If the platform publishes stable addresses for apex use, enter them directly. This works everywhere. The catch is that you must update them yourself if the platform changes them, so follow its announcements. See A and AAAA records.

Redirect the apex to www

Put the site on www with a CNAME, and have a small web service answer at the apex with a permanent redirect to https://www.example.com/. Many registrars and platforms provide this. Make sure the redirect service handles HTTPS with a valid certificate; a redirect that works only over plain HTTP will fail for visitors whose browsers insist on encryption. HSTS explains that behavior.

HTTPS records

The newer HTTPS record type has an alias mode that is allowed at the apex and can point clients at another name. Browser and provider support has been growing but is uneven, so use it alongside address records rather than as the only route. SVCB and HTTPS records has the details.

Choosing

Your situation Sensible choice
DNS host offers flattening or ALIAS Use it at the apex, CNAME on www
Platform gives fixed addresses A and AAAA at the apex
Neither is available Redirect the apex to www
You are free to move DNS Choose a host that supports apex aliasing

Whatever you pick, choose one hostname as the official one and redirect the other to it, so that links, cookies and search listings all agree.

Testing

dig www.example.com CNAME +short
dig www.example.com +noall +answer
dig example.com +noall +answer

On Windows PowerShell:

Resolve-DnsName www.example.com

For a flattened apex you will see only addresses, with no sign of the hostname you entered. That is expected.

Then test the web side:

curl -I http://example.com/
curl -I https://example.com/
curl -I https://www.example.com/

Check that each ends up where you intend, with no certificate errors.

Connecting a domain to a hosting platform

Most people meet the apex problem while following a platform's setup page. The sequence below avoids the usual dead ends.

  1. In the platform's dashboard, add both example.com and www.example.com. The platform needs to know about a name before it will serve it or obtain a certificate for it.
  2. Note exactly what it asks for: a hostname for www, and either addresses or an alias target for the apex. Some also ask for a TXT record to prove ownership.
  3. At your DNS host, remove old records at those two names, such as a registrar's parking address. Leave MX and TXT records for email in place.
  4. Create the CNAME for www.
  5. Set up the apex with whichever method your DNS host supports.
  6. Wait for the old TTL, then check that the platform reports both names as verified and certificates as issued.
  7. Choose the primary name and turn on the redirect from the other.

If verification stalls, query the records yourself and compare them character by character with the instructions. A target copied with a missing letter looks plausible and fails silently.

What CNAMEs mean for caching

An alias and its target each have their own TTL, and that gives you two different dials. The TTL on your CNAME controls how quickly you can switch to a different platform. The TTL on the target's address records belongs to the platform and controls how quickly they can move traffic.

A long TTL on your alias is fine for a stable setup. Shorten it ahead of a planned move to another provider, then wait out the previous value before switching. Remember that a flattened apex behaves differently: the answer visitors cache is an ordinary address record with a TTL your DNS host chooses.

Pitfalls

Email breaks after adding a CNAME at the apex. Remove it, restore the MX and TXT records and use one of the methods above.

A verification record will not save. You are probably adding it at a name that already has a CNAME. Many services let you verify at a different name.

The doubled domain. A dashboard or zone file may append your domain to a target lacking a final dot, giving host.example.net.example.com. Check the saved value.

Certificate issuance fails on an aliased name. CAA records are looked up through aliases, so the target's policy may apply. See CAA records.

Abandoned aliases. If you cancel a service but leave the CNAME pointing at it, someone else may be able to claim that target and serve content under your name. Delete the record when you retire the service, as explained in dangling DNS and subdomain takeover.

Common questions

Is a CNAME slower than an A record?

It can add one extra lookup when nothing is cached. With caching, visitors rarely notice. Long chains are worth shortening.

Can a CNAME point to a different domain?

Yes, and that is the usual case when using hosting platforms and content delivery networks.

Can I alias my whole domain, including all subdomains?

A CNAME covers one name only. It does not carry the names beneath it. A separate standard record, DNAME, redirects a whole subtree, but it is far less commonly needed or offered.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in DNS & Domain Names →

Latest news on this topic