DNS MX Record

Mail Exchange Record

What is a MX Record?

A DNS MX record (Mail Exchange record) specifies the mail server responsible for receiving email messages on behalf of a domain. When someone sends an email to [email protected], the sending mail server queries the DNS for MX records of example.com to determine where to deliver the message.

MX records include a priority value (also called preference) that determines the order in which mail servers should be tried. Lower priority numbers indicate higher preference. For example, if a domain has MX records with priorities 10 and 20, email will first be sent to the server with priority 10. If that server is unavailable, the sending server will fall back to the server with priority 20. This mechanism provides built-in redundancy for email delivery.

Unlike A records, MX records point to a hostname rather than an IP address. The target hostname specified in an MX record must itself have an A or AAAA record — it cannot point to a CNAME. This is a common misconfiguration that can cause email delivery failures. Most email services like Google Workspace, Microsoft 365, and custom mail servers require specific MX records to be configured in your domain's DNS.

Syntax & Examples

The syntax of a DNS MX record includes a priority value:
example.com.    3600    IN    MX    10 mail.example.com.
example.com.    3600    IN    MX    20 mail2.example.com.
The fields are: domain name, TTL, class (IN), record type (MX), priority (lower = higher preference), and the mail server hostname. Here is a typical Google Workspace MX configuration:
example.com.    3600    IN    MX    1 aspmx.l.google.com.
example.com.    3600    IN    MX    5 alt1.aspmx.l.google.com.
example.com.    3600    IN    MX    5 alt2.aspmx.l.google.com.
example.com.    3600    IN    MX    10 alt3.aspmx.l.google.com.
example.com.    3600    IN    MX    10 alt4.aspmx.l.google.com.

How to Query MX Records

To query MX records using dig, run: dig example.com MX. For concise output: dig +short example.com MX. This will display the priority values and mail server hostnames. To query using a specific DNS server: dig @8.8.8.8 example.com MX. You can then check if the mail server hostnames resolve correctly: dig mail.example.com A.

Using nslookup, run: nslookup -type=MX example.com. On Windows PowerShell: Resolve-DnsName -Name example.com -Type MX. To test email delivery, you can use the SMTP EHLO command by connecting to the mail server directly: telnet mail.example.com 25. Online MX lookup tools like the one at ip.now.to provide a quick way to check MX records without command-line access.

Related Record Types

Frequently Asked Questions

What is a DNS MX record?

A DNS MX (Mail Exchange) record specifies the mail servers responsible for receiving email for a domain. It includes a priority value that determines the order in which servers are tried, with lower numbers being tried first. MX records are essential for email delivery to work correctly.

What does MX priority mean?

MX priority (or preference) is a numerical value that determines the order in which mail servers are contacted. A server with priority 10 is preferred over one with priority 20. If multiple servers share the same priority, the sending server will distribute mail between them randomly, providing load balancing.

Can an MX record point to an IP address?

No, an MX record must point to a hostname (FQDN), not an IP address directly. The target hostname must have its own A or AAAA record that resolves to an IP. Additionally, the MX target should not be a CNAME, as this violates RFC 2181 and can cause delivery issues with some mail servers.

What happens if there are no MX records for a domain?

If no MX records exist, the sending mail server will fall back to the domain's A record as specified in RFC 5321. This means email would be attempted to the domain's web server IP address. However, this fallback is unreliable and not recommended — always configure explicit MX records for domains that receive email.

How do I set up MX records for Google Workspace?

For Google Workspace, you need to add five MX records with specific priorities: aspmx.l.google.com (priority 1), alt1.aspmx.l.google.com (priority 5), alt2.aspmx.l.google.com (priority 5), alt3.aspmx.l.google.com (priority 10), and alt4.aspmx.l.google.com (priority 10). Remove any existing MX records first to avoid conflicts.