CNAME flattening and ALIAS records explained
CNAME flattening, ALIAS and ANAME are provider features that let the bare domain act like a CNAME by resolving the target hostname on the server side and answering with plain A or AAAA records.
- Updated Nov 27, 2026
- Markdown
Decide how to point the bare domain at a hostname when a CNAME is not allowed there and check what your provider returns.
- A domain whose DNS you can edit
- dig installed
A CNAME record makes one name an alias of another. It is the natural way to point www.example.com at a hosting platform, but it cannot be used on the bare domain example.com, the apex of the zone. Several providers offer a substitute called ALIAS, ANAME or CNAME flattening that gives the apex the same convenience. This lesson explains the restriction, how the workaround resolves, and when a plain A record is the better choice.
How it works#
The DNS rule is that a CNAME must be the only data at its name. When a resolver finds a CNAME it stops looking for other record types at that name and follows the alias instead. The apex of a zone always carries an SOA record and NS records, and often MX and TXT records for mail and verification. A CNAME there would conflict with all of them, so the standard forbids it, and many providers reject it or, worse, accept it and break mail.
That is a problem because hosting platforms often give you a hostname rather than a fixed IP, since the IP behind it can change. You can CNAME www to it, but the bare domain needs something else.
What ALIAS and flattening do#
Under names such as ALIAS, ANAME or CNAME flattening, the provider adds a special record at the apex that holds a hostname target. When the provider’s authoritative server receives a query for the apex, it looks up the target hostname itself, then replies with ordinary A (and AAAA) records. To the client it looks like this:
dig example.com A +noall +answerexample.com. 60 IN A 198.51.100.7There is no CNAME in the answer, so there is no conflict with SOA, NS or MX. The apex can keep its mail and verification records. Which addresses the client sees depends on when the provider last resolved the target.
Some providers apply the same flattening to a CNAME placed at the apex, hiding the restriction. Others implement it only for specific record types. Features and names differ, so read your provider’s documentation for what it supports and how often it refreshes. This lesson stays neutral: none of the behaviors below are guaranteed by the DNS standard.
Tradeoffs#
Benefits of flattening:
- The apex follows a platform hostname without manual IP edits.
- Mail and other apex records keep working.
- Clients need no special support, since they only see A records.
Costs:
- The addresses at the apex are a copy. If the target changes and the provider has not refreshed yet, the apex can point at stale addresses until it does.
- It is proprietary. Moving DNS providers may require rebuilding the setup, and the feature may not exist at the new one.
- Location based routing may be less accurate. If the target hostname returns different IPs per region, the provider resolves it from its own location and serves that answer to everyone, so users might not be sent to the nearest endpoint.
- The TTL you see on the apex is the provider’s, not the target’s.
Alternatives#
If flattening is not available or you want fewer moving parts:
- Use an A record at the apex with the platform’s stable IP, if it publishes one. Check that it is truly fixed first.
- Put the site at www with a CNAME, and redirect the bare domain to www with an HTTP redirect. See Redirect www to the bare domain for the reverse direction and the idea. The bare domain still needs an A record to answer the redirect request, and the certificate must cover both names.
- Move the zone to a provider that supports flattening.
For your own server with a stable address, a plain A record at the apex (Point a domain at your server) and a CNAME for www pointing at the apex is the simplest layout that works everywhere.
Check it worked#
Ask the authoritative server for the apex and confirm you receive address records, not an error:
dig @ns1.example.net example.com A +noall +answer
dig @ns1.example.net example.com AAAA +noall +answer
dig @ns1.example.net example.com MX +noall +answer
dig @ns1.example.net example.com NS +noall +answerThe A and AAAA answers show addresses. The MX and NS answers should still exist, proof that nothing replaced the rest of the apex. Then compare with the target:
dig +short target.example.net AIf the two address sets differ for longer than the provider’s stated refresh time, report it to the provider.
Edge cases and gotchas#
- Mail breaks with a real apex CNAME: if a provider lets you add a plain CNAME at the apex, MX and TXT lookups for the domain can fail or behave unpredictably.
- Certificates need the right names: flattening affects DNS only. Your certificate must still cover example.com and www.example.com, see How TLS certificates are issued.
- Target must resolve: if the target hostname disappears, the apex may return no addresses at all.
- IPv6: confirm the provider also flattens AAAA records. Some only do A.
- Not portable: exported zone files may contain a provider specific record type that other servers reject.
- Subdomain CNAMEs are fine: the restriction applies to the apex only, so app.example.com can be a normal CNAME.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
| Provider refuses a CNAME at the apex | The apex must hold SOA and NS | Use its ALIAS or flattening option, or an A record |
| Apex returns old addresses after the platform moved | The provider’s copy has not refreshed | Wait for the provider’s refresh, or set a fixed A record |
| Email stopped working after an apex CNAME | The CNAME hid the MX records | Remove the CNAME and restore MX, then use ALIAS or an A record |
| Apex resolves but HTTPS shows a name mismatch | The certificate does not include the bare domain | Issue a certificate covering example.com and www |
| Users far away get a slow endpoint | Flattened answer is resolved from the provider’s location | Use a platform side anycast or a regional setup |
| Exported zone fails to import elsewhere | ALIAS is a provider specific type | Replace with an A record at the new provider |
Quick reference#
www CNAME target.example.net. allowed, subdomain
@ CNAME target.example.net. NOT allowed at the apex
@ ALIAS target.example.net. provider feature, answers with A/AAAA
@ A 203.0.113.10 works everywhereRelated lessons#
- DNS record types explained: what CNAME, A and AAAA do.
- What is a DNS zone: why the apex has SOA and NS records.
- Subdomains and wildcard DNS records: other things the apex does not follow.
- Redirect www to the bare domain: the redirect pattern as an alternative.
- Check DNS with dig: inspect what the provider actually returns.
Next#
Continue with How TLS certificates are issued (ACME, HTTP-01, DNS-01).
Check what you learned
Frequently asked questions
Why can't I add a CNAME record for my root domain?
The root (apex) must hold SOA and NS records, and a CNAME may not coexist with any other record at the same name. The DNS standard therefore forbids a CNAME there.
What is the difference between ALIAS, ANAME and CNAME flattening?
They are different names for the same idea, used by different providers: the provider resolves a hostname and serves the resulting address records at the apex. Exact behavior and refresh timing vary by provider.
Is CNAME flattening part of the DNS standard?
No. It is a provider feature that happens on the authoritative side. To clients the answer looks like normal A or AAAA records.
What can I do if my DNS provider does not support ALIAS records?
Use an A record with a stable IP, move DNS to a provider that supports flattening, or point www at the target with a CNAME and redirect the bare domain to www.
Sources
Keep going: guides and tutorials
- Self-Hosted Static Site Hosting: Deploy a Folder With Levelrail Self-hosted static site hosting from a plain folder: one deploy command, _redirects, _headers and a custom 404 honored, plus a one command rollback.
- Deploy Next.js on a VPS With Docker, Git Push and HTTPS Deploy a Next.js app to your own VPS with Docker, a health check, HTTPS and rollback. Includes the NEXT_PUBLIC build trap that leaves variables empty.