Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

MX and CNAME at the same name: mail breaks because a CNAME owns the name

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

Mail for a domain is found with an MX record. A CNAME at that same name says the name is only an alias. RFC 1034 states the rule: "If a CNAME RR is present at a node, no other data should be present". An MX is other data. The name should not be both an alias and a mail destination.

SMTP then has its own rule for what it does when it finds a CNAME. RFC 5321 says the lookup "first attempts to locate an MX record associated with the name. If a CNAME record is found, the resulting name is processed as if it were the initial name." RFC 5321 does not state the next point in these words: a sender that finds a CNAME follows the alias, so an MX that shares the name is not a destination you can rely on.

A second, different mistake is an MX whose target is a CNAME. RFC 5321 says the MX target, when queried, "MUST return at least one address record" and that "a value that will return a CNAME record when queried, lies outside the scope of this Standard."

What goes wrong

A CNAME "identifies its owner name as an alias, and specifies the corresponding canonical name". The rule that no other data be present "ensures that the data for a canonical name and its aliases cannot be different." It also means a cached CNAME can be used "without checking with an authoritative server for other RR types." A resolver that has cached the CNAME need not go back and look for an MX you added beside it.

When a server is looking for a type and finds a CNAME, it "includes the CNAME record in the response and restarts the query at the domain name specified in the data field of the CNAME record." A query for MX at an alias returns the CNAME and continues at the target. Queries for type CNAME are the exception: they are not restarted.

Google's SMTP relay page warns against a third-party CNAME record at the root or apex domain: "A CNAME record at the root conflicts with your MX records and disrupts incoming Google Workspace mail delivery and authentication." That is the same collision. The rule in RFC 1034 is not limited to the apex. It applies at every name.

If the MX lookup finds no MX records, RFC 5321 treats the name as an implicit MX pointing at itself, but only when the MX list is empty. A CNAME is not an empty MX list. Following the CNAME is the path the RFC describes. If that lookup returns a name error, "this situation MUST be reported as an error."

Likely causes

Cause What you see How to confirm
A CNAME and an MX at the same name Mail fails, or goes to the CNAME target, and the MX looks ignored Ask the authoritative server for CNAME and for MX, and read who owns each line
The name was turned into an alias for a website and the MX was left in place Web works, mail does not Both types at that owner name
The MX target is a CNAME The MX looks valid and the target has no address of its own dig the target for A and for CNAME
A resolver cached the CNAME You deleted the CNAME and mail still follows the alias The remaining TTL on the cached CNAME

Prove the cause before changing anything

All of these are read-only. The manual's form is dig @server name type. The default type is A, so set the type. The manual's example dig +noall +answer example.com shows "just the name, record type, TTL, and value for each answer".

1. Ask the authoritative server for both types at the mail name. Use a nameserver from the delegation in place of ns1.example.net.

dig +noall +answer @ns1.example.net example.com CNAME
dig +noall +answer @ns1.example.net example.com MX

Read the first column of each line. If the CNAME query returns a line, the name is an alias. An MX line that starts with the same name you asked for, example.com., is an MX owned by that name, and an alias with an MX of its own is the RFC 1034 collision. MX lines that start with another name belong to the CNAME's target, not to your name, so they are not a collision. Check the DNS console's record list for the name as well.

2. Ask your resolver, and compare.

dig +noall +answer example.com CNAME
dig +noall +answer example.com MX

RFC 1034 says that when a name server finds a CNAME it "includes the CNAME record in the response and restarts the query at the domain name specified in the data field of the CNAME record", so through a resolver an MX query at an alias returns the CNAME and then the target's MX. Data in both answers therefore does not by itself prove a collision; step 1 does. A CNAME that remains only in a resolver cache still steers mail until its TTL expires. RFC 1034 says the TTL is how long a resolver may keep the record.

3. Query the MX target.

dig +noall +answer mail.example.net A
dig +noall +answer mail.example.net CNAME

An address at the target is what RFC 5321 requires. A CNAME at the target is the case the RFC places outside the standard.

Fix

Keep one role for the name. A mail destination has MX records and no CNAME. An alias has a CNAME and no MX.

Make one change at a time, and only the one that matches what the name is for.

When the name should receive mail: remove the CNAME

First, save both answers from the authoritative server, using your own name and nameserver in place of the placeholders, and export the zone from your DNS console into zone-before-remove-cname.txt:

dig +noall +answer @<nameserver> <name> MX > mx-before-remove-cname.txt
dig +noall +answer @<nameserver> <name> CNAME > cname-before-remove-cname.txt

Risk: the next step deletes the CNAME at the mail name. Whatever used that alias, including a website name that pointed at another host, stops resolving through it. Resolvers keep the deleted record until its TTL runs out, so mail can follow the old CNAME for a while after you delete it.

Delete the CNAME and keep the MX, with the MX targets pointing at names that have address records.

To undo it: add back the CNAME from cname-before-remove-cname.txt, or from zone-before-remove-cname.txt. That puts back the state you saved, which had the MX beside the CNAME, so it restores the collision. Do it only if the deletion broke something that needs the alias, and fix that another way.

When the name should be an alias: remove the MX

First, save both answers from the authoritative server into new files, so the files from the other case are not overwritten, and export the zone into zone-before-remove-mx.txt:

dig +noall +answer @<nameserver> <name> MX > mx-before-remove-mx.txt
dig +noall +answer @<nameserver> <name> CNAME > cname-before-remove-mx.txt

Risk: the next step deletes the MX at that name. Mail for the name stops being delivered by an MX until mail is directed somewhere else. A name that is an alias should not receive mail through its own MX.

Delete the MX and keep the CNAME.

To undo it: add back the MX lines owned by the name from mx-before-remove-mx.txt, or from zone-before-remove-mx.txt. That restores the saved state, which had the CNAME beside the MX, so it restores the collision. Do it only if mail stopped and you have no other route for it.

When the MX target is a CNAME

First, save the MX record and the target's CNAME into new files:

dig +noall +answer @<nameserver> <name> MX > mx-before-change-target.txt
dig +noall +answer <mx-target> CNAME > target-cname-before-change-target.txt

Risk: the next step changes the MX target, which sends mail to a different server. A target with no address record makes the destination unusable, which RFC 5321 says must be reported as an error.

Point the MX at a name that has an A or AAAA record, not at a CNAME.

To undo it: set the MX target back to the value in mx-before-change-target.txt.

Example (illustrative): example.com has a CNAME to www.example.net and an MX to mail.example.com. dig +noall +answer @ns1.example.net example.com CNAME returns the CNAME, and the MX query to the same server returns lines that start with example.com.. Mail does not arrive. The administrator saves both answers, deletes the CNAME, and leaves the MX. The website, which depended on the alias, stops resolving through it until its own name is used. Adding back the saved CNAME restores the collision, so it is done only if nothing else can serve the website.

Confirm the fix

  1. Asked of the authoritative server, one of the two queries at the mail name is empty or returns only lines owned by another name. The name has either a CNAME or an MX of its own, not both.
  2. Each MX target returns an address record and does not return a CNAME.
  3. After the old CNAME's TTL, a resolver with no @ agrees with the authoritative server.

What to watch afterwards

  • A website alias added later at the mail name recreates the collision.
  • Google's guidance warns specifically about a CNAME at the root next to MX records.
  • An MX target that is an alias is a separate break from a CNAME sitting beside the MX.

Risks and limits

  • RFC 1034 says no other data "should" be present with a CNAME. Servers differ in what they return when a zone breaks the rule. The safe state is not to publish the combination.
  • RFC 5321 points to RFC 2181 for the MX-target rule. The requirement quoted here is the one in RFC 5321 section 5.1.
  • Following a CNAME is not the same fault as a missing MX.

Sources