Chapter 3 · Lesson 17 of 22
Domains and HTTPS

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.

By the end you will

Decide how to point the bare domain at a hostname when a CNAME is not allowed there and check what your provider returns.

Time
10 min
Level
Intermediate
Check
4 questions
You need
  • 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:

bash
dig example.com A +noall +answer
output
example.com.   60   IN   A   198.51.100.7

There 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:

  1. Use an A record at the apex with the platform’s stable IP, if it publishes one. Check that it is truly fixed first.
  2. 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.
  3. 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:

bash
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 +answer

The 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:

bash
dig +short target.example.net A

If 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#

SymptomLikely causeFix
Provider refuses a CNAME at the apexThe apex must hold SOA and NSUse its ALIAS or flattening option, or an A record
Apex returns old addresses after the platform movedThe provider’s copy has not refreshedWait for the provider’s refresh, or set a fixed A record
Email stopped working after an apex CNAMEThe CNAME hid the MX recordsRemove the CNAME and restore MX, then use ALIAS or an A record
Apex resolves but HTTPS shows a name mismatchThe certificate does not include the bare domainIssue a certificate covering example.com and www
Users far away get a slow endpointFlattened answer is resolved from the provider’s locationUse a platform side anycast or a regional setup
Exported zone fails to import elsewhereALIAS is a provider specific typeReplace with an A record at the new provider

Quick reference#

output
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 everywhere

Next#

Continue with How TLS certificates are issued (ACME, HTTP-01, DNS-01).

Check what you learned4 questions
1Why can a CNAME not be placed at the apex (example.com)?
2What does a provider's ALIAS or flattening feature return to a client that asks for the apex?
3What is a downside of flattening?
4What is the simplest option if your provider has no ALIAS feature?

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

View MD Edit
Share
Helpful?
Progress is saved in this browser only.

Keep going: guides and tutorials

View MD Edit
Share
Helpful?
Run this on your own server

Levelrail deploys apps from git with health-checked releases and one-click rollback.

docker pull ghcr.io/glincker/levelrail:latest Install Levelrail From GLINR Studios