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

Copy article link

Free DNS included with any Cloudflare plan

What is a DNS MX record?

A DNS 'mail exchange' (MX) record directs email to a mail server. The MX record indicates how email messages should be routed in accordance with the Simple Mail Transfer Protocol (SMTP, the standard protocol for all email). Like CNAME records, an MX record must always point to another domain.

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 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 between the two servers.

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.

Can MX records point to a CNAME?

A CNAME record is used for referencing a domain's alias instead of its actual name. CNAME records typically point to an 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. Pointing to a CNAME is forbidden by the RFC documents that define how MX records function.

Learn more about the uses for CNAME records.