---
title: What is a DNS MX record?
description: A DNS MX record directs email to a mail server. Learn more about mail exchange (MX) records and how they are used in the email sending process.
image: https://www.cloudflare.com/preview.png
---

##  What is a DNS MX record? 

 The MX record directs emails to a mail exchange server. 

######  Learning objectives 

 After reading this article you will be able to: 

* Understand the purpose of an MX record
* Learn how MX records fit into the process of sending an email

On this page 

## What is a DNS MX record?

A DNS 'mail exchange' (MX) record directs email to a mail server. The MX record indicates how [email](/learning/email-security/what-is-email/) messages should be routed in accordance with the Simple Mail Transfer Protocol ([SMTP](/learning/email-security/what-is-smtp/), the standard protocol for all email).

Example of an MX record:

example.com record type: priority: value: TTL

@ MX 10 mailhost1.example.com 45000

@ MX 20 mailhost2.example.com 45000

The 'priority' numbers before the [domains](/learning/dns/glossary/what-is-a-domain-name/) for these MX records indicate preference; the lower 'priority' value is preferred. The server will always try mailhost1 first because 10 is lower than 20\. In the result of a message send failure, the server will default to mailhost2.

The email service could also configure this MX record so that both servers have equal priority and receive an equal amount of mail:

example.com record type: priority: value: TTL

@ MX 10 mailhost1.example.com 45000

@ MX 10 mailhost2.example.com 45000

This configuration enables the email provider to equally [balance the load](/load-balancing/) between the two servers.

Sign up

Free DNS included with any Cloudflare plan

[Start for free →](/plans/)

## What is the process of querying an MX record?

Message transfer agent (MTA) software is responsible for querying MX records. When a user sends an email, the MTA sends a DNS query to identify the mail servers for the email recipients. The MTA establishes an SMTP connection with those mail servers, starting with the prioritized domains (in the first example above, mailhost1).

## What is a backup MX record?

A backup MX record is just an MX record for a mail server with a higher 'priority' value (which means a lower priority), so that under normal circumstances mail will go to the more prioritized servers. In the first example above, mailhost2 would be the 'backup' server because email traffic will be handled by mailhost1 as long as it is up and running.

Report

Secure your DNS infrastructure

[Get the report →](/lp/dns-and-the-threat-of-ddos/)

## Can MX records point to a CNAME?

A [CNAME](/learning/dns/dns-records/dns-cname-record/) record is used for referencing a domain's alias instead of its actual name. CNAME records typically point to an [A record](/learning/dns/dns-records/dns-a-record/) (in IPv4) or AAAA record (in IPv6) for that domain. However, MX records have to point directly to a server's A record or [AAAA record](/learning/dns/dns-records/dns-aaaa-record/). Pointing to a CNAME is forbidden by the [RFC documents that define](https://tools.ietf.org/html/rfc2181) how MX records function.

## How to set up MX records in Cloudflare

For help setting up MX records in Cloudflare, refer to [Set up email records](https://developers.cloudflare.com/dns/manage-dns-records/how-to/email-records/).

```json
{"@context":"https://schema.org","@type":"Organization","name":"Cloudflare","url":"https://www.cloudflare.com","logo":"https://www.cloudflare.com/logo.svg","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"]}
{"@context":"https://schema.org","@type":"WebSite","name":"Cloudflare","url":"https://www.cloudflare.com","inLanguage":"en","potentialAction":{"@type":"SearchAction","target":"https://www.cloudflare.com/search?q={search_term_string}","query-input":"required name=search_term_string"}}
{"@context":"https://schema.org","@type":"WebPage","name":"What is a DNS MX record?","description":"A DNS MX record directs email to a mail server. Learn more about mail exchange (MX) records and how they are used in the email sending process.","url":"https://www.cloudflare.com/learning/dns/dns-records/dns-mx-record/","inLanguage":"en"}
```
