MX Record

A DNS Mail Exchange (MX) record is a type of resource record in the Domain Name System that specifies the mail server responsible for accepting email messages on behalf of a domain name. MX records direct email to the proper servers and include priority values that determine the order in which mail servers should be contacted.

How it works

When someone sends an email to your domain (e.g., user@example.com), their email server needs to know which mail server should receive the message. MX records provide this information by mapping your domain name to one or more mail servers, along with priority values that determine the order in which they should be tried.

The email routing process using MX records works as follows: 1. **Email Sent**: Someone sends an email to user@example.com 2. **DNS Query**: The sender's mail transfer agent (MTA) performs a DNS lookup for MX records associated with example.com 3. **MX Records Retrieved**: The DNS server responds with all MX records for the domain, each containing a priority value and a mail server hostname 4. **Priority Sorting**: The sending MTA sorts the MX records by priority (lower numbers = higher priority) 5. **Connection Attempt**: The sender's MTA attempts to connect to the highest priority mail server (lowest number) via SMTP 6. **Failover**: If the first server is unavailable, the MTA tries the next highest priority server, continuing down the list until successful delivery or all servers fail The priority system ensures email delivery reliability through redundancy. Organizations typically configure multiple MX records pointing to different mail servers for backup and load balancing purposes.

Key Points

  • MX records consist of two parts: a priority value and a mail server hostname
  • Lower priority numbers indicate higher preference (e.g., priority 10 is tried before priority 20)
  • Multiple MX records provide redundancy and load balancing for email delivery
  • MX records must point to a hostname (A or AAAA record), never directly to an IP address
  • If no MX record exists, some mail servers will attempt delivery using the domain's A record as a fallback

Common Use Cases

  • Email Server Configuration: Directing email traffic to your organization's mail servers, whether self-hosted or using services like Gmail, Microsoft 365, or other email providers
  • Redundancy and Failover: Setting up multiple MX records with different priorities ensures email delivery continues even if the primary mail server is temporarily unavailable
  • Load Balancing: Configuring multiple MX records with equal priority distributes incoming email across multiple servers, preventing any single server from being overwhelmed
  • Spam Filtering: Pointing MX records to spam filtering services (like Cloudflare Area 1 or Barracuda) before routing clean email to the actual mail server

code Example Configuration

TypeHost / NameValue / Points toTTL
MX@10 mail1.example.com3600
MX@20 mail2.example.com3600
MX@30 mail3.example.com3600
Amail1192.0.2.103600

* MX records include a priority value (lower = higher priority) and a mail server hostname. Multiple records provide redundancy.

Frequently Asked Questions

Can an MX record point directly to an IP address?expand_more
No, MX records must point to a hostname (domain name), not an IP address. The hostname specified in the MX record must have its own A record (for IPv4) or AAAA record (for IPv6) that resolves to the actual IP address of the mail server. This is a fundamental DNS requirement defined in RFC 2181.
What happens if I have multiple MX records with the same priority?expand_more
When multiple MX records have the same priority value, mail servers will randomly select one of them for each delivery attempt. This provides basic load balancing, distributing incoming email approximately evenly across the servers with equal priority. This is useful when you have multiple mail servers with identical capabilities and want to balance the load between them.
Do I need an MX record if I don't receive email?expand_more
If you don't need to receive email at your domain, you can either omit MX records entirely or create a 'null MX' record (priority 0, pointing to a single dot '.') that explicitly indicates the domain doesn't accept email. The null MX approach is preferred as it clearly signals to sending servers not to attempt email delivery, preventing wasted delivery attempts.
How do MX records work with subdomains?expand_more
Each subdomain can have its own MX records independent of the parent domain. For example, example.com might have MX records pointing to one mail server, while support.example.com could have different MX records pointing to a different mail server. If no MX record exists for a subdomain, there's no automatic fallback to the parent domain's MX records - email to that subdomain will fail unless the sending server attempts delivery using the subdomain's A record.
What is a good TTL value for MX records?expand_more
MX records typically use TTL values between 1 hour (3600 seconds) and 24 hours (86400 seconds). Since mail server configurations don't change frequently, longer TTL values are generally acceptable and reduce DNS query load. However, if you're planning to migrate mail servers, lower the TTL to 5-15 minutes a day or two before the change to ensure faster propagation of the new records.