A CNAME at the zone apex took our website live and broke all incoming email
We moved our marketing site to a hosting platform that asked for a CNAME. We added one for the bare domain, the site worked, and inbound email quietly stopped. A CNAME cannot coexist with other records at the same name, and the apex always has others. How resolvers behaved and the ALIAS options that fix it.
On a Thursday afternoon we moved the marketing site for example-shop.com to a managed hosting platform. Its
setup guide said: "Point your domain at our platform with a CNAME to sites.hostingplatform.example." We added
two records in our DNS provider's console:
www.example-shop.com. 300 IN CNAME sites.hostingplatform.example.
example-shop.com. 300 IN CNAME sites.hostingplatform.example.
The console warned about the second one, but allowed it with a confirmation checkbox. Both names loaded the new site within minutes.
On Monday, sales reported that a customer's purchase order "bounced". Then support noticed their inbox, which normally gets hundreds of emails a day, had received almost nothing since Thursday evening. A test message from an external account came back with:
550 5.1.2 The domain example-shop.com does not have valid MX records
or the mail server could not be resolved.
What resolvers saw
Our zone still contained the MX records:
example-shop.com. 300 IN MX 10 mx1.mailprovider.example.
example-shop.com. 300 IN MX 20 mx2.mailprovider.example.
But public resolvers did not return them:
dig +short MX example-shop.com @8.8.8.8
sites.hostingplatform.example.
Asking for MX returned the CNAME instead. And the CNAME's target, the hosting platform, has no MX records of its own:
dig MX sites.hostingplatform.example @8.8.8.8 +noall +answer +authority
hostingplatform.example. 900 IN SOA ns1.hostingplatform.example. hostmaster.hostingplatform.example. ...
So any mail server looking up where to deliver mail for example-shop.com followed the CNAME, found no MX at the
target, and either bounced the message or retried and eventually gave up. TXT lookups had the same problem: our
SPF and domain verification records were also hidden, which is why some messages that did arrive were marked as
spam.
A CNAME owns its whole name
A CNAME record says "this name is an alias for that other name". RFC 1034 states that if a CNAME record is
present at a node, no other data should be present there. The reason is resolution logic: when a resolver finds
a CNAME for a name, it restarts the lookup at the target, for any record type. A resolver asked for the MX of
example-shop.com sees the CNAME and goes to the target for MX. It never looks at other records at the original
name, because by definition there should not be any.
The apex of a zone (the bare domain, example-shop.com.) always has other records: the SOA and NS records are
mandatory there, and in practice MX and TXT records too. A CNAME at the apex therefore always conflicts with
records that must exist.
Why it half worked
Different DNS software handles the conflict differently. Our provider's authoritative servers returned the CNAME for every query type at that name, which is a reasonable interpretation of "the CNAME wins". Browsers only ask for A and AAAA records, followed the CNAME, and got the platform's addresses, so the site worked. Mail servers ask for MX, followed the same CNAME, and got nothing useful. Everything that is not a web browser broke, and nobody tests email after changing a website's DNS.
Some resolvers cached the old MX records for their TTL (300 seconds), so a few messages still arrived in the first minutes, which made the problem look intermittent at first.
Environment
| Item | Value |
|---|---|
| Domain | example-shop.com, managed DNS provider |
| Change | CNAME added at apex for website hosting |
| Hidden records | MX (2), TXT (SPF, DMARC verification, site verification) |
| Impact | 3.5 days of bounced or delayed inbound email |
1. Remove the apex CNAME immediately
We deleted the apex CNAME. Within one TTL (five minutes), dig MX example-shop.com returned the mail servers
again and new email began arriving. Senders whose servers had been retrying delivered queued messages over the
next hours. Messages that had already bounced were lost; we worked out the list of senders from bounce reports
that customers forwarded and asked them to resend.
2. Point the apex at the platform the right way
The website still needed the bare domain to work. Three options exist for that:
ALIAS / ANAME / flattening (provider feature). Many DNS providers offer a record type that behaves like a CNAME at the apex but answers with A and AAAA records. The authoritative server resolves the target itself and returns its addresses:
example-shop.com. 300 IN ALIAS sites.hostingplatform.example. (provider-specific)
To resolvers it looks like ordinary A and AAAA records, so it coexists with MX, TXT, SOA and NS. Names differ: ALIAS, ANAME, "CNAME flattening", or, on AWS Route 53, alias records pointing at AWS resources. None of these are standard DNS record types; they are provider features.
A and AAAA records with the platform's addresses. If the platform publishes stable addresses for apex domains, as many do, use them directly. The risk is that the platform changes them; check whether they commit to keeping them stable.
Redirect the apex to www. Keep www as a CNAME (which is fine, since www has no other records) and serve a
redirect from the apex to https://www.example-shop.com. This needs something answering on the apex address, often
the DNS provider's redirect service.
We used the provider's ALIAS record. The final zone:
example-shop.com. 300 IN ALIAS sites.hostingplatform.example.
example-shop.com. 300 IN MX 10 mx1.mailprovider.example.
example-shop.com. 300 IN MX 20 mx2.mailprovider.example.
example-shop.com. 300 IN TXT "v=spf1 include:_spf.mailprovider.example -all"
www.example-shop.com. 300 IN CNAME sites.hostingplatform.example.
3. Turn the console warning into a block
Our DNS is now managed as code (the provider's Terraform provider), and a validation step rejects any CNAME at a name that has other records, and any CNAME at the zone apex. The console's checkbox is no longer the only line of defence.
1. Every record type at the apex resolves correctly, checked against several public resolvers:
for r in 1.1.1.1 8.8.8.8 9.9.9.9; do
echo "== $r"; dig +short MX example-shop.com @$r; dig +short A example-shop.com @$r
done
== 1.1.1.1
10 mx1.mailprovider.example.
20 mx2.mailprovider.example.
203.0.113.70
...
2. Mail delivery. Test messages from three external providers arrived, with SPF passing. A DMARC aggregate report the following day showed normal volumes again.
3. Synthetic monitoring for DNS. A check now runs every five minutes and alerts if the MX lookup for any of our domains does not return the expected mail servers, or if SPF and DMARC TXT records are missing. A similar check for the website already existed; email had none.
4. Change checklist. DNS changes now require listing every record type at the affected names before and after, and a test email after any change to an apex.
5. Security implications. While SPF and DMARC records were hidden, receivers could not verify mail claiming to be from our domain, which made spoofing our domain easier for those days. We reviewed DMARC reports for the period and found no spoofing campaign, but the monitoring above now covers authentication records too.
Takeaways
- A CNAME cannot share its name with any other record, and the zone apex always has SOA, NS and usually MX and TXT.
- Resolvers follow a CNAME for every record type, so MX and TXT lookups end up at the alias target.
- For the apex, use ALIAS/ANAME/flattening, A/AAAA records, or a redirect to
www. - Monitor MX and email authentication records, and test email after any apex DNS change.
References: RFC 1034, section 3.6.2 aliases and canonical names, RFC 2181, clarifications to the DNS specification, Amazon Route 53, choosing between alias and non-alias records, RFC 5321, SMTP address resolution.
Add a label
Embed this post
<iframe src="https://hibug.me/cname-at-zone-apex-broke-mail" width="700" height="420" frameborder="0" loading="lazy"></iframe>
I work as a platform engineer supporting product teams who want to ship without becoming infrastructure experts. That means a lot of Dockerfiles, Kubernetes manifests, CI pipelines and the Linux and network details underneath them. The problems I write about are the ones new and experienced engineers both hit: a non-root pod that cannot write its volume, a pipeline that deployed an older commit, a merge that dropped a teammate's fix, files nginx cannot read, large responses that hang over a VPN, a DNS record that broke mail. I explain each one from the error message down to the mechanism, then show the fix and a quick way to check it. Where a topic is a fundamental, like Kubernetes objects, I teach it through one broken deploy rather than a list of definitions.
Related Stories
Sticky sessions pinned our heaviest customers to one node at 95% CPU while others idled
Comments
0No comments yet. Be the first to comment!
Sign In to post a comment.