Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

CNAME Flattening, Zone Apex Records, and DNS Resolution

How Cloudflare CNAME flattening enables apex CNAME records, when to flatten or opt out, and how to verify DNS answers.

This page summarizes Cloudflare documentation on CNAME flattening: the process that lets you publish a CNAME at the zone apex (example.com) despite RFC rules that normally forbid it, and that changes whether resolvers see a CNAME chain or direct A/AAAA answers.

CNAME flattening: what it does when you query DNS

Section titled “CNAME flattening: what it does when you query DNS”

CNAME flattening means the authoritative resolver follows a CNAME to its final target and returns an IP address instead of the canonical hostname.

With CNAME flattening, Cloudflare finds the IP address that a CNAME points to. This process could involve a single lookup or multiple (if your CNAME points to another CNAME). Cloudflare then returns the final IP address instead of a CNAME record, helping DNS queries resolve faster.

— Cloudflare, CNAME flattening

The same idea appears in product copy for apex and custom domains:

ANAME or ALIAS are DNS records used by specific DNS providers. If your previous provider was using ANAME or ALIAS, you can recreate these records on Cloudflare as CNAME records. Cloudflare’s CNAME flattening allows you to create CNAME records at your zone apex, removing the need for those other record types.

— Cloudflare, Create zone apex record

On Cloudflare DNS record types, proxied CNAME records use flattening by default because answers must be Cloudflare anycast IPs. For DNS-only records, flattening is configurable (see below).

How proxy status changes the flattened answer

Section titled “How proxy status changes the flattened answer”

When the apex or subdomain CNAME is proxied, clients typically receive multiple Cloudflare anycast A records with a short TTL (for example 300 seconds). When the record is DNS only and flattening applies, the answer uses the resolved origin IP and TTL rules described in Example diagram.

Zone apex CNAME: why normal DNS blocks it and how flattening helps

Section titled “Zone apex CNAME: why normal DNS blocks it and how flattening helps”

At the zone apex, standard DNS does not allow a bare CNAME alongside other record types for the same name (see RFC 1912, referenced in Convert full setup to partial setup). Many operators therefore used vanity subdomains (shop.example.com) or provider-specific ANAME / ALIAS records.

On Cloudflare, an apex CNAME is supported through flattening. Adding that record deactivates existing apex A/AAAA records until you remove the CNAME; see Proxy traffic.

Standard Cloudflare for SaaS expects customers to use a CNAME to your CNAME target. When a customer must use an A record (common when their DNS vendor forbids apex CNAME), you need apex proxying:

Apex proxying allows your customers to use their apex domains (example.com) with your SaaS application.

— Cloudflare, Apex proxying

Apex proxying relies on static IP prefixes (or BYOIP); customers point apex A records to those IPs. Cloudflare describes the underlying DNS mechanism as CNAME flattening on the Apex proxying page. Enterprise add-ons apply; see Cloudflare for SaaS.

CNAME flattening settings: apex default, all records, per record

Section titled “CNAME flattening settings: apex default, all records, per record”

Configuration lives under Set up CNAME flattening.

Scope Behavior
Zone apex @ CNAME Flattening on by default on all plans
All CNAME records Optional on paid zones (flatten_all_cnames / dashboard CNAME flattening for all CNAME records)
Single CNAME Optional on paid zones: per-record Flatten or API settings.flatten_cname; tag cf-flatten-cname on export (Import and export records)

Paid zones gained API control of per-record flattening in October 2024 (cname_flatten true/false per the DNS changelog).

Per-record Flatten is unavailable when the name is already at the apex, the record is proxied (already flattened), or flatten all is enabled—see Set up CNAME flattening.

Outgoing transfers behave differently depending on apex vs subdomain and flatten mode; see Records transfer. Apex DNS-only CNAME records always transfer as flattened IPs; subdomains depend on global per-record settings.

DNS-only load balancing: flatten_cname on pool endpoints

Section titled “DNS-only load balancing: flatten_cname on pool endpoints”

Separate from zone DNS flattening, CNAME flattening for endpoints controls what a gray-clouded load balancer returns when an endpoint address is a hostname.

When a DNS-only (gray-clouded) load balancer selects an endpoint whose address is a hostname (for example origin.example.com), Cloudflare resolves that hostname to an IP address and returns an A/AAAA record to the client.

— Cloudflare, CNAME flattening for endpoints

Set flatten_cname: false on an endpoint when clients must receive the CNAME itself (third-party SaaS, geo-aware downstream DNS, failover between hostnames). The toggle applies only when the load balancer is DNS-only, the endpoint is a hostname, the LB name is not the zone apex, and steering selected that endpoint—otherwise flattening still occurs (CNAME flattening for endpoints). Enterprise Load Balancing required. Health monitors always resolve hostnames to IPs for probes; only client-facing answers change.

Partial (CNAME) setup and internal resolution

Section titled “Partial (CNAME) setup and internal resolution”

With partial setup, authoritative DNS points hostnames to {hostname}.cdn.cloudflare.net. Cloudflare resolves proxied origins differently than in a full zone—especially when a CNAME in the partial zone points to another name that also exists in-zone (DNS resolution).

Heroku apex on Cloudflare illustrates apex CNAME + flattening:

Fortunately, Cloudflare offers CNAME flattening to resolve requests for your root domain.

— Cloudflare, Configure Cloudflare and Heroku over HTTPS

Named Tunnels can use an apex CNAME to {uuid}.cfargotunnel.com; with partial setup you must create records at the external provider (Tunnels FAQ).

Workers in partial zones need every resolved hostname present in Cloudflare DNS or fetch() may return 530 / 1016 (Known issues).

When to leave CNAME visible (do not flatten)

Section titled “When to leave CNAME visible (do not flatten)”

Flattening breaks workflows that require the literal CNAME in the answer.

Domain verification (DKIM, third-party SaaS): causes include proxied verification CNAME, zone-wide flatten all, or per-record flatten on a DNS-only record (Verify a domain with CNAME). Fix: DNS only, flatten off globally and per record, correct NS delegation.

Email-related CNAME: Email issues notes providers that need readable CNAME for DKIM or autodiscover may fail when flattening is on.

Global flatten all:

If a CNAME target is being used to verify a domain for a third-party service, turning on CNAME flattening for all CNAME records may cause the verification to fail since the CNAME record itself will not be returned directly.

— Cloudflare, CNAME flattening

If the final target has no A/AAAA, flattening returns NODATA—DNS can look “stuck” (CNAME flattening). A CNAME to another Cloudflare account’s name triggers Error 1014: CNAME Cross-User Banned (Error 1014).

Mis-pointed external CNAME chains toward Cloudflare often surface as Error 1001 or Error 1002. Do not browse *.cdn.cloudflare.net labels directly.

Proxied CNAME to another CDN is blocked or should stay DNS only to avoid dual-proxy loops (Proxy status use cases).

You cannot mix a CNAME with other record types on the same name; see Records with the same name.

  • Turning on flatten all while a vendor still polls for a visible verification CNAME.
  • Proxying verification or DKIM CNAME records (Cloudflare may warn or block; see Proxy status).
  • Expecting flatten_cname: false on a load balancer to work when the LB is proxied, at the zone apex, or when steering picks another endpoint.
  • Apex A records to standard anycast IPs in partial setup without static IP/BYOIP—Cloudflare only recommends apex A/AAAA with static or BYOIP (Convert full to partial).
  • Partial-zone CNAME chains that keep targets only in Cloudflare while authoritative DNS disagrees—traffic may ignore auth DNS for the target (DNS resolution).

Stale upstream answers can affect proxied or flattened CNAME paths; see Stale response for upstream DNS resolution.

  1. Query the hostname from a resolver outside your network: for apex or flattened DNS, confirm you get A/AAAA (and Cloudflare anycast IPs when proxied). For load balancer endpoints with flatten_cname: false, use dig as in Verify on the load balancing doc.
  2. For vendor domain verification, query the verification name with type CNAME and confirm the answer is a CNAME, not only A, per Verify a domain with CNAME.
  3. In the Cloudflare dashboard, review DNS Settings (flatten all) and each record’s Flatten and proxy status.
  4. If HTTP fails with Cloudflare 1xxx errors, cross-check targets against Error 1001, Error 1002, and Error 1014.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

Example check for a DNS-only load balancer hostname:

dig lb.example.com A +short
dig lb.example.com CNAME +short

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact wording you are asking about.