Skip to content

CNAME flattening at the apex: how Cloudflare makes a root-domain alias actually work

DNS forbids a CNAME at the zone apex, yet platforms keep telling you to point example.com at their hostname. Cloudflare squares that circle with CNAME flattening. What it does, where it helps, and where it bites.

You cannot put a normal CNAME at the apex of a zone — the root name already holds SOA and NS records, and the DNS standard says a CNAME must be the only record at its name. Cloudflare gets around this with CNAME flattening: you enter a CNAME for example.com, Cloudflare resolves the target chain on its own side, and the world sees ordinary A and AAAA answers. The apex is flattened automatically on every plan, it coexists happily with your MX and TXT records, and the main things to watch are geo-targeted CNAME targets and anyone who assumes the published IPs are static.

What’s happening

The apex problem is structural. Every zone’s root name carries an SOA record and NS records by definition. A CNAME, per the standard, forbids any other record type at the same name. Put those two rules together and a CNAME at example.com is illegal — most DNS software refuses it, and software that accepts it anyway tends to break mail, because resolvers following the CNAME stop seeing the MX record at the apex. That trap, in its cPanel form, fills a whole article: the CNAME-at-apex trap covers the record-type rules in the Cloudflare context.

Flattening changes where the alias is resolved. When you create a CNAME on the apex in Cloudflare, the authoritative side chases the target (example.com → lb-1234.provider.net → …) itself, caches the result, and answers queries with the final A/AAAA set — synthesized answers, not a CNAME. Resolvers never see the alias, so no rule is violated, and your MX, TXT, and NS records at the apex keep working. The public answer tracks the target: when the provider moves their load balancer to new IPs, the flattened answer follows within the target’s TTL. Cloudflare documents the mechanism in its DNS docs.

Two related behaviours are worth separating. A proxied CNAME (orange cloud) is “flattened” in a trivial sense — the edge answers with Cloudflare anycast IPs regardless of the target. Flattening in the strict sense matters for DNS-only records, where the real target IPs are being published. At the apex, flattening is automatic and cannot be turned off; for non-apex CNAME records, Cloudflare also offers per-record flattening on DNS-only entries when you need an A-shaped answer at some other name.

What to check first

  • Whether you actually need a CNAME at the apex, or the provider publishes stable A record IPs you could use instead.
  • What the platform’s documentation says about apex domains — many explicitly say “use ALIAS/ANAME/flattening”.
  • Whether the target uses geolocated DNS — flattened answers are resolved from Cloudflare’s side, which can shift which regional endpoint your users get.
  • What else lives at the apex: MX, SPF TXT, verification TXT records all keep working under flattening, but confirm they exist before and after.
  • Whether the record should be proxied at all — if the orange cloud is on, the flattening question mostly disappears.

How to verify

# The world should see A/AAAA answers at the apex, never a CNAME
dig +short A example.com @1.1.1.1
dig CNAME example.com @1.1.1.1

# Compare with what the CNAME target resolves to right now
dig +short A lb-1234.provider.net @1.1.1.1

# Apex records that must survive alongside the flattened CNAME
dig +short MX example.com @1.1.1.1
dig +short TXT example.com @1.1.1.1

# Confirm the origin behind the alias serves your site
curl -sv --resolve example.com:443:203.0.113.10 https://example.com/ -o /dev/null 2>&1 | grep -E "HTTP|subject"

A healthy flattened apex shows A records that match (or belong to the same pool as) the target’s answers, an empty CNAME query response, and untouched MX/TXT records. If the CNAME query returns an actual alias from public resolvers, you are not looking at a Cloudflare-hosted zone.

The fix

  1. Create the CNAME at the apex like any other record. In DNS → Records, add a CNAME with the name @ and the target hostname the platform gave you. Cloudflare flattens it automatically — there is no switch to find for the apex, and this works on Free, Pro, and Business alike.
  2. Decide the proxy status deliberately. Orange-clouded, the hostname gets Cloudflare’s edge and the target is resolved internally; DNS only, the flattened target IPs are published directly. For a SaaS platform frontend, DNS only is often what the vendor expects; for your own origin, orange is usually the point.
  3. Keep apex mail and verification records where they are. Flattening’s whole value is coexistence: MX, SPF, DKIM-adjacent TXT records at the root all continue to resolve. Do not move mail records to a subdomain to “make room” — that was only ever necessary on hosts without flattening.
  4. Flatten non-apex names only when something requires it. A regular CNAME at www or app is fine and standard. Per-record flattening on DNS-only records is for the rare consumer that insists on seeing an A record at a specific name.
  5. Re-test after the platform migrates. Flattened answers follow the target automatically, but when a vendor changes hostnames (not just IPs), you still have to update the CNAME target yourself.

When this fix is wrong

If the target hostname is geo-routed — a CDN or global load balancer that answers differently by resolver location — flattening resolves it from Cloudflare’s vantage point, and DNS-only users may be steered to an endpoint chosen for Cloudflare’s resolver rather than for them. Proxying the record makes that moot (traffic enters Cloudflare’s anycast network anyway); if you cannot proxy, weigh the options in geo-DNS strategy: DNS, load balancing, CDN. And if the provider hands you stable dedicated IPs, a plain A record is simpler than any alias.

Common mistakes

  • Pasting the platform’s CNAME target as an A record “because apex CNAMEs don’t work” — the IP behind the hostname changes, and the site dies weeks later.
  • Assuming the flattened IPs are static and hard-coding them in firewalls, monitoring, or a partner’s allowlist.
  • Creating the apex CNAME at a DNS host without flattening during a migration away from Cloudflare, and breaking mail because the CNAME shadows the MX.
  • Confusing proxied behaviour with flattening, then being surprised that grey-clouding the apex suddenly publishes the vendor’s IPs instead of Cloudflare’s.

Prevention

  • Standardize on the alias, not the IP: whenever a vendor offers a hostname target, use the CNAME-plus-flattening pattern so their IP changes never involve you.
  • Note in your runbook that the apex answer is synthesized — anyone debugging with dig should expect A records where the dashboard shows a CNAME.
  • Check vendor status pages for hostname (not IP) changes during their migrations, since a retired target hostname breaks the alias outright.
  • When leaving Cloudflare for another DNS host, verify the destination supports ALIAS/ANAME at the apex before the move, or convert to A records first.

Flattening is one of those features you set up once and forget — until a migration, a geo-routing quirk, or a hard-coded IP reminds you it exists. Moving a production zone onto Cloudflare without dropping mail or exposing the origin is exactly the kind of work Stack Harbor handles under Managed Cloud Ops — book an infrastructure review if you want it done with a rollback plan.