DEV Community

Cover image for “I can't create a CNAME for my root domain” – why that's correct and what to do instead
Daniele Michelin
Daniele Michelin

Posted on Originally published at daniele-michelin.com

“I can't create a CNAME for my root domain” – why that's correct and what to do instead

“I can't create a CNAME for my root domain!” – usually right after a platform or CDN has asked you to “point your domain at us with a CNAME”. The DNS panel refuses, and it looks like a provider limitation. In fact, it's a rule of the DNS standard.

The rule: a CNAME stands alone

A CNAME says: “This name is only an alias, all data lives at the target.” That leads to a strict rule, defined in RFC 1034 and clarified again in RFC 2181: if a CNAME exists for a name, there must be no other records for that same name. No MX, no TXT, no A.

The reason is logical: when a resolver asks for the MX of a name that is an alias, it follows the alias. If the same name also had its own MX, it would be unclear which one applies.

Why it never fits at the zone apex

The zone apex is the name of the zone itself, i.e. example.com without www, shown as @ in many panels. There are always at least two record types there:

  • SOA – the zone's administrative data,
  • NS – the authoritative name servers.

The zone doesn't work without them. Since a CNAME can't coexist with them, no CNAME is possible at the apex. On top of that, there are almost always MX and TXT records (SPF, verifications) in practice – and they would clash with an alias as well.

You can check it yourself:

dig +noall +answer example.com SOA
dig +noall +answer example.com NS
Enter fullscreen mode Exit fullscreen mode

What works instead

1. Set A and AAAA records directly

The simplest solution: enter the target's IP addresses directly as A (IPv4) and AAAA (IPv6). Many platforms publish fixed addresses for exactly this.

example.com.      3600  IN  A     203.0.113.10
example.com.      3600  IN  AAAA  2001:db8::10
Enter fullscreen mode Exit fullscreen mode

Downside: if the platform changes its IPs, you have to follow.

2. ALIAS, ANAME or CNAME flattening

Some DNS providers offer their own record type, often called ALIAS or ANAME, or talk about CNAME flattening. The principle is the same everywhere: the provider's name server resolves the target itself and serves ordinary A/AAAA records to the outside. To resolvers, everything looks standards-compliant.

Important: this isn't a feature of the DNS protocol but of the individual provider. When switching DNS providers, check whether the new one supports it too (see DNS migration without downtime).

3. Redirect to www

A proven approach: run the website on www.example.com with a CNAME there, and point the root domain via an A record at a web server that redirects to www over HTTP.

For www, a CNAME is fine

www.example.com is a name of its own without SOA and NS. As long as there are no other records there, a CNAME is perfectly fine:

www.example.com.  3600  IN  CNAME  target.platform.example.
Enter fullscreen mode Exit fullscreen mode

The same rule still applies, though: if you also need a TXT or MX record for www, you run into the same conflict.

How to check

  • Is there a CNAME at the apex? dig +noall +answer example.com CNAME should return nothing.
  • What does the root domain return? dig +short example.com A and dig +short example.com AAAA
  • Is the CNAME for www correct? dig +noall +answer www.example.com CNAME
  • Are there no other records next to the CNAME on www?
  • With ALIAS/ANAME: does the provider's name server return current IPs? dig @ns1.provider.example example.com A
  • After the change, do email (MX) and SPF (TXT) still work?

So the refusal in the DNS panel isn't an obstacle but a safeguard. Working around it risks exactly what nobody wants: a root domain that no longer accepts mail.


Originally published at daniele-michelin.com. More guides, free checks (SPF, TLS, headers) and an error-message lexicon: daniele-michelin.com/en/.

Top comments (0)