In Cloudflare DNS, why can't mail go through the proxy, and what happens when an MX record points at a proxied hostname?
answer
- port 25 is not HTTP
- MX has no orange cloud
- an answer you never created
- a prefix added at query time
basics
~20 sCloudflare's proxy does not carry SMTP, so MX records are always DNS-only; an MX aimed at a proxied name is answered with a generated _dc-mx name resolving to the origin IP, which keeps mail flowing but exposes that IP.
solid answer
~40 s`MX` records cannot be proxied, and Cloudflare does not proxy SMTP on port 25 by default, so a mail host's `A` or `AAAA` record must stay **DNS-only**: proxied, it would send other mail servers to Cloudflare's addresses and delivery would fail. If an `MX` targets a hostname that is proxied, for example `example.com MX example.com` with the apex orange-clouded, Cloudflare detects the conflict and answers the MX query with a generated name such as `_dc-mx.a1b2c3d4e5f6.example.com`, whose `A` record is the origin IP. `SRV` records get the same treatment with a `dc-` prefix. Mail keeps working, but the web origin's IP is now one `dig` away. The fix is a dedicated DNS-only mail hostname, ideally on a different server from the website; Spectrum can proxy SMTP where it is configured.
code
console · 4 lines$ dig example.com mx +short
100 _dc-mx.a1b2c3d4e5f6.example.com.
$ dig _dc-mx.a1b2c3d4e5f6.example.com a +short
192.0.2.1go deeper
Recall that MX records are always DNS-only and that a mail host's A record must be gray-clouded, because the proxy does not carry SMTP.
Explain the _dc-mx rewrite: when an MX targets a proxied name, Cloudflare answers with a generated name that resolves to the origin IP, and SRV gets a dc- prefix.
Spot that a _dc-mx answer, or any DNS-only mail record on the web server's IP, publishes the origin, and fix it by moving mail to its own hostname and address.
Make separating mail from web origins a migration rule, and decide whether hosting mail elsewhere or paying for Spectrum for SMTP fits the organisation.
## Why mail cannot be orange-clouded Mail moves between servers over **SMTP**, a protocol that is not HTTP. Cloudflare's proxy handles HTTP and HTTPS, and it does not proxy SMTP traffic on port `25` by default. Two consequences follow: - An **`MX` record** has no proxy status at all. Like `TXT`, `SRV` and every type other than `A`, `AAAA` and `CNAME`, it is always DNS-only. - An **`A` or `AAAA` record used for mail**, such as `mail.example.com`, must also be DNS-only. If it were proxied, sending servers would resolve it to Cloudflare's anycast addresses, connect there on port 25, and the message would never reach the mail server. Mail authentication records are in the same position: SPF and DMARC are `TXT` records and always DNS-only, and Cloudflare refuses to proxy some CNAME targets used for DKIM validation because a proxied answer would break them. ## When MX points at a proxied name A common setup before moving to Cloudflare is a single server for web and mail: ```plaintext example.com MX example.com example.com A 192.0.2.1 ``` Once the apex `A` record is proxied, a naive answer would send mail to Cloudflare. Cloudflare detects this and **rewrites the MX answer at query time**: ```plaintext example.com MX _dc-mx.a1b2c3d4e5f6.example.com _dc-mx.a1b2c3d4e5f6.example.com A 192.0.2.1 example.com A 203.0.113.1 (a Cloudflare address) ``` Key facts about this mechanism: 1. The `_dc-mx` record does **not** appear in the zone's DNS records table; it only shows in `dig` responses. 2. It resolves to the **origin IP** taken from the proxied record, so mail reaches the server directly. 3. `SRV` records pointing at a proxied name get the same treatment with a `dc-` prefix, for example `dc-a1b2c3d4e5f6.example.com`. 4. The record is harmless for delivery, and it is the documented, intended behaviour. ## Why it matters The generated record keeps mail flowing, but it publishes the address of the very server the proxy was meant to hide. If web and mail share an IP, anyone who queries the domain's MX and follows it learns the web origin, and can send traffic straight there, around the WAF, cache and DDoS mitigation. Cloudflare's docs state it plainly: if the mail server resides on the same IP as the web server, the MX record exposes the origin IP. ## The fix | Situation | What to do | |---|---| | The domain receives no mail | Delete the `MX` record; no `_dc-mx` answer is generated. | | Mail on its own server | Point `MX` at `mail.example.com`, a DNS-only `A` record with the mail server's IP. | | Mail on the web server | Same as above, but plan to move mail to a different IP, because the DNS-only mail record still reveals the shared address. | | SMTP must go through Cloudflare | Configure Spectrum for SMTP; without it, port 25 is not proxied. | After the change the zone looks like this: ```plaintext example.com MX mail.example.com mail.example.com A 198.51.100.25 (DNS only, a separate server) example.com A 203.0.113.1 (proxied answer) ``` ## Other records that must stay DNS-only Mail is the best-known case of a wider rule: a record whose consumer is not a browser should usually not be proxied. - **Domain verification.** A CNAME or TXT record that proves ownership to another service must answer with the expected target. Proxied, the CNAME answers with Cloudflare's addresses and verification fails; some services need the record DNS-only permanently. - **DKIM and validation targets.** Cloudflare warns about, or refuses, proxying CNAMEs whose targets are known DKIM or certificate-validation hosts, because a proxied answer would break them. - **SRV-based services.** An `SRV` record that targets a proxied name is rewritten to a `dc-` name for the same reason MX is. ## A migration checklist for mail 1. Before moving the zone, list every `MX` target and the address each resolves to. 2. If an `MX` targets the apex or `www`, create a dedicated mail hostname first and repoint the `MX` to it. 3. Leave the mail hostname DNS-only, and check whether its address matches the web origin. 4. After activation, query the `MX` from outside and confirm no `_dc-mx` name comes back. ## Checking it from outside A `dig example.com mx +short` that returns a `_dc-mx` name shows that the MX still targets a proxied hostname. Querying that name for `A` shows exactly what the outside world learns. Running both after every mail change is a cheap regression check for an exposed origin.
- Why can't you delete a _dc-mx record from the Cloudflare dashboard?It is not a stored record. Cloudflare inserts it into DNS responses at query time whenever an `MX` resolves to a proxied hostname, so it never appears in the records table. To stop it, remove the conflict: delete an unused `MX`, or point the `MX` at a separate DNS-only mail hostname.
- Is there any way to send SMTP through Cloudflare's network?Only with Spectrum configured for SMTP. Without Spectrum, Cloudflare does not proxy port 25, so mail records stay DNS-only and the mail server's address is public. That is a reason to keep the mail server off the web origin's IP.
- Proxying the MX record hides the mail server's IP from senders.
- Cloudflare's proxy relays SMTP on port 25 for proxied records by default.
- A _dc-mx answer means the zone was hijacked and must be removed.
- A DNS-only mail hostname is safe even when it shares the web server's IP.
- Proxying mail.example.com keeps mail flowing while hiding the server.