Skip to main content
All CollectionsDNS Records
DNS MX Record: Configuration, Lookup, and Best Practices
DNS MX Record: Configuration, Lookup, and Best Practices

This article explains DNS MX records, their configuration, and how to check them using various tools for reliable email delivery.

Updated over a month ago

MX (Mail Exchange) records are critical components of DNS configuration that determine where emails sent to your domain should be routed. Proper configuration of MX records ensures reliable email delivery and helps prevent issues with email receipt. This article provides a technical breakdown of MX records, their configuration, and how to troubleshoot them.


What is an MX Record?

An MX record is a DNS record type that directs email to a mail server, responsible for accepting and managing incoming mail for a domain. The MX record defines which mail servers should handle email for the domain, using the Simple Mail Transfer Protocol (SMTP). Unlike A or AAAA records, which map domain names to IP addresses, MX records point to a mail server’s domain name.


MX Record Format

An MX record has two essential parts:

  1. Priority: A numeric value indicating the preference of the mail server. Lower values are preferred.

  2. Mail Server Hostname: The domain name (not an IP address) of the mail server that will handle incoming email.

Example:

Copy codemydomain.com IN MX 10 mail1.mydomain.com mydomain.com IN MX 20 mail2.mydomain.com

Here, mail1.mydomain.com has a priority of 10 and will be used first. If it becomes unavailable, mail2.mydomain.com will take over, as it has a higher priority value of 20.


How to Configure MX Records

To set up MX records for your domain, follow these steps:

  1. Log into DNS Management Console: Access your DNS hosting provider’s control panel.

  2. Locate MX Records Section: Look for the DNS records management area, where you can add or modify DNS records.

  3. Add MX Record: Add the mail server’s fully qualified domain name (FQDN) and assign a priority number.

  4. Set TTL (Time to Live): TTL defines how long the record is cached. A typical TTL for MX records is around 3600 seconds (1 hour).

  5. Save the Record: After configuring the MX record, save and propagate the changes. DNS updates can take up to 48 hours to fully propagate.


How to Query an MX Record

1. Online MX Lookup Tools:

  • Tools like MXToolbox and DNSstuff provide web interfaces to query MX records for any domain. Simply enter the domain name, and the tool will return the mail server(s) associated with it.

2. Using nslookup (Windows/Linux/macOS):

  • Open your command prompt (or terminal) and use the nslookup utility to query the MX record.

Command:

bashCopy codenslookup -type=mx mydomain.com

Output:

javaCopy codeServer: UnKnown Address: 8.8.8.8 Non-authoritative answer: mydomain.com MX preference = 10, mail exchanger = mail1.mydomain.com mydomain.com MX preference = 20, mail exchanger = mail2.mydomain.com

3. Using dig (Linux/macOS):

  • dig is a powerful command-line tool for querying DNS records.

Command:

Copy codedig mx mydomain.com

Output:

yamlCopy code; <<>> DiG 9.10.6 <<>> mx mydomain.com ;; ANSWER SECTION: mydomain.com. 3600 IN MX 10 mail1.mydomain.com. mydomain.com. 3600 IN MX 20 mail2.mydomain.com.

4. Using host (Linux/macOS):

  • host is another command-line tool for DNS lookups.

Command:

Copy codehost -t mx mydomain.com

Output:

csharpCopy codemydomain.com mail is handled by 10 mail1.mydomain.com. mydomain.com mail is handled by 20 mail2.mydomain.com.


Backup MX Record

A backup MX record ensures email is not lost if the primary mail server fails. It has a higher priority number (lower preference), meaning it will only be used if the primary mail server is unreachable. This redundancy ensures your email service remains reliable.

Example:

scssCopy codemydomain.com IN MX 10 mail1.mydomain.com mydomain.com IN MX 30 mail2.mydomain.com (backup)

If mail1.mydomain.com is down, mail will be routed to mail2.mydomain.com.


MX Record Best Practices

  1. Use Multiple MX Records: Always configure at least two MX records—one primary and one secondary— to ensure redundancy. This setup prevents email loss if one server fails.

  2. Proper Priority Assignment: Set your primary mail server’s priority to the lowest number (e.g., 10) and assign a higher priority (e.g., 20, 30) to the backup server. Ensure that the backup server is configured correctly to handle email traffic.

  3. Do Not Point MX Records to CNAME: According to RFC 2181, MX records must not point to a CNAME record. Instead, they should point directly to an A or AAAA record (hostname). Using a CNAME in an MX record will lead to DNS resolution issues.

  4. TTL Settings: Set a reasonable TTL for MX records. A TTL of 3600 seconds (1 hour) is standard, allowing for relatively quick updates while still being cached for efficient resolution.

  5. Secure Your Mail Servers: Implement security protocols such as SPF, DKIM, and DMARC alongside MX records to prevent email spoofing and phishing.


Troubleshooting MX Record Issues

  1. Emails Not Delivered: If emails are not being received, check the MX record configuration to ensure it’s pointing to the correct mail server. Use tools like nslookup or dig to verify the current MX records.

  2. DNS Propagation Delay: After changing MX records, it can take up to 48 hours for the changes to propagate. During this period, email delivery may be inconsistent.

  3. Incorrect Priority Configuration: Ensure your primary mail server has the lowest priority number. Misconfigured priority numbers can cause mail to route incorrectly.

  4. Backup MX Server Not Working: If your backup mail server is not handling email, verify that it’s properly configured and that its priority is correctly set to a higher number than the primary mail server.


Conclusion

MX records are a fundamental part of email infrastructure, directing email traffic to the appropriate mail servers. Correct configuration ensures reliable email reception, while proper backup configurations prevent disruptions in service. Regularly check and validate your MX records to avoid mail delivery issues and keep your email services running smoothly.

Did this answer your question?