In Cloudflare DNS, how does CNAME flattening let a zone apex point at a hostname, and when does it apply to other records?
answer
- answer with addresses, not the alias
- the apex: default on every plan
- paid zones: all CNAMEs or per record
- the cf-flatten-cname tag
- verification CNAMEs can break
basics
~20 sCloudflare follows the CNAME chain itself and answers with the final A or AAAA addresses, so an apex CNAME never reaches resolvers as a CNAME. It is on by default at the apex on every plan; paid zones can flatten all or chosen CNAMEs.
solid answer
~40 sWith CNAME flattening, Cloudflare resolves the CNAME's target, following further CNAMEs if there are any, and returns the final addresses under the queried name. It is on by default for a CNAME at the zone apex (`@`) on every plan, and proxied CNAMEs are effectively flattened anyway because they return Cloudflare anycast addresses. Paid zones can also turn on **CNAME flattening for all CNAME records** (`flatten_all_cnames`) or the per-record **Flatten** option, which a zone file carries as the `cf-flatten-cname` tag. A DNS-only flattened answer carries the lower of the CNAME's and the target's TTL; a proxied one carries 300 seconds. Flattening everything can break a third-party verification that looks for the CNAME itself, and a target with no A or AAAA records yields an empty NODATA answer.
go deeper
Remember that Cloudflare answers an apex CNAME with addresses, and that this happens by default on every plan.
Explain the scopes (apex, proxied, all CNAMEs, per record), which need a paid plan, and the TTL a flattened DNS-only or proxied answer carries.
Diagnose the flattening failures: a verification check broken by flatten-all, NODATA from a dangling target, and Error 1014 from a cross-account CNAME.
Decide which records a team may flatten, keeping third-party verification CNAMEs out, and how that policy travels through zone file exports and imports.
## The problem it solves The DNS rules forbid a CNAME at the zone apex, because the apex must also hold the zone's `SOA` and `NS` records and a CNAME cannot share its name with other data. Yet many hosting targets give you a hostname, not an address. **CNAME flattening** is Cloudflare's way round it: you store a CNAME at `example.com`, and Cloudflare never serves it as a CNAME. It looks up the target and answers with addresses, so what resolvers see is standards-compliant. The same mechanism lets a root custom domain point at a Cloudflare Pages site. ## How Cloudflare flattens a record 1. A resolver asks Cloudflare for `example.com IN A`. 2. Cloudflare finds a CNAME at the apex pointing to `external-origin.test`. 3. It resolves the target, following a chain of CNAMEs if there is one, until it reaches A or AAAA records. 4. It answers with those addresses under the queried name `example.com`, and with Cloudflare anycast addresses instead if the record is proxied. Because the resolver gets the addresses in one answer, flattening also saves it the extra lookups a CNAME chain would cost. ## Where flattening applies | Scope | Plans | How it is set | | --- | --- | --- | | CNAME at the zone apex (`@`) | All plans | Always on; nothing to configure | | Proxied CNAMEs | All plans | Flattened by default, since they answer with Cloudflare anycast IPs | | All CNAME records | Paid plans | **CNAME flattening for all CNAME records** on **DNS Settings**, or `flatten_all_cnames: true` through the API | | Selected CNAME records | Paid plans | The **Flatten** toggle on a record, or `"settings": {"flatten_cname": true}`; exported as the `cf-flatten-cname` tag | The per-record toggle is unavailable on the apex record (already flattened), on a proxied record (already flattened) and when flatten-all is on, which cannot be overridden per record. If a CNAME's target lives in the same zone, Cloudflare flattens it whatever the setting says. ## What the flattened answer looks like From Cloudflare's own example, an apex CNAME with a TTL of 3600 points to an external A record with a TTL of 7200: ```plaintext domain.test 3600 CNAME external-origin.test external-origin.test 7200 A 192.0.2.1 DNS only: domain.test 3600 IN A 192.0.2.1 Proxied: domain.test 300 IN A <Cloudflare anycast addresses> ``` - **DNS only:** the answer carries the target's address and the **lower** of the two TTLs. - **Proxied:** the answer carries several Cloudflare addresses with a TTL of **300** seconds. ## Pitfalls - **Third-party verification.** Many services verify domain control by checking that a CNAME points at them. With flatten-all on, the CNAME is never returned, so the check fails; leave such records unflattened. - **Dangling targets.** If the final target has no A or AAAA records, the flattened answer is empty (NODATA), which looks like a record that has not propagated. - **Cross-account targets.** A CNAME to a hostname in a different Cloudflare account is prohibited and produces **Error 1014: CNAME Cross-User Banned**. - **Partial setups.** On a partial (CNAME) setup, Cloudflare is not authoritative, so proxying the apex depends on the other provider supporting CNAME flattening, not on this feature. ## Choosing what to flatten - **Leave the apex alone.** It is flattened on every plan with nothing to configure. - **Proxied records need no setting.** Their answers are Cloudflare anycast addresses already. - **Prefer per-record flattening on paid zones** when only a few DNS-only CNAMEs benefit, so verification CNAMEs keep answering as CNAMEs. - **Turn on flatten-all only after auditing** every CNAME for a third party that checks the CNAME itself, because the zone-wide setting cannot be overridden per record. - **Keep the setting in the zone file.** Exports carry `cf-flatten-cname`, so an import into another zone restores per-record flattening. ## Why it matters in a migration When a zone moves to Cloudflare, an apex served by the old provider with an `ANAME` or `ALIAS` record, record types some providers invent for this purpose, is re-created in Cloudflare as a CNAME at `@`. Flattening makes that work on any plan, so the apex keeps pointing at a hosting hostname without anyone hard-coding addresses that the host may change.
- Why might a DNS-only CNAME on a Cloudflare paid zone be worth flattening even when it is not at the apex?Flattening answers with the final addresses in one response, saving resolvers the extra lookups of a CNAME chain. The cost is that the CNAME itself disappears from answers, so do not flatten a record a third party checks, such as a domain-verification CNAME. Use the per-record **Flatten** toggle to choose record by record rather than flattening all.
- After a migration, the apex on Cloudflare returns an empty answer although the CNAME is present. What is the likely cause?The CNAME's final target has no A or AAAA records, a dangling CNAME, so flattening has no address to return and answers with NODATA. Query the target directly; if it resolves only to another alias that ends nowhere, fix the target or point the apex at a hostname that has addresses.
- Cloudflare serves the apex CNAME as a CNAME and lets resolvers follow it.
- Flattening a CNAME at the apex requires a paid plan.
- A flattened DNS-only answer always carries the target record's TTL.
- Turning on flattening for all CNAMEs is always safe for verification records.
- A CNAME can point at a hostname in any other Cloudflare account.