Skip to Content

5 Useful Tips to Check DNS MX Record in Linux

DNS MX record is short for mail exchange. It is used to direct email to a mail server. The MX record indicates how email messages should be routed when we send out an email. The best way is to check dns MX record in Linux is using the dig command.  For example: dig mx will output all the MX records for

  • DNS MX record was first defined in RFC 1035.
  • DNS MX record must always point to a domain name.
  • DNS MX record can not point to a IP address
  • DNS MX record can not point to a domain which doesn’t have A record
  • DNS MX record can not point to a Cname
  • DNS MX record can point to a different domain
  • DNS MX record supports multiple DNS records


Purpose of DNS MX record

In simple words, an MX record is used to tell the world which mail servers accept incoming mail for the domain and where emails sent to the domain should be routed to. If the MX records are not pointed to the correct location, we might not receive email.

When someone sends an email to an address at the domain “,” their email server performs a DNS lookup for the MX records of “” Based on the priorities specified in the MX records, the sending server attempts to deliver the email to the mail server with the lowest priority. If the first-choice mail server is unreachable or unavailable, the sender’s server falls back to the mail server with the next highest priority.

For example, if we send an email from to, the yahoo mail server will try to send that email to the mx record of gmail servers based on the priority.

If there is no MX record present, the protocol is to try to deliver the email to the A or AAAA record in the destination. For example, an email is sent to hello@howtouselinux.dom but howtouselinux.dom has no MX records. The email server will then do an A-record lookup for and attempt delivery there.

MX records play a crucial role in email delivery, allowing proper routing of messages across the internet and ensuring they reach the intended recipients’ mail servers.

Example of DNS MX record

An MX record consists of two main components:

Priority (Preference):
Each MX record has a priority value assigned to it, indicating the order in which the mail servers should be used. The priority is represented by a numerical value, where a lower number indicates a higher priority. Email servers attempt to deliver messages to the server with the lowest priority value first. If that server is unavailable, the next server with a higher priority is tried.

This is also sometimes described as distance, which does make it somewhat more intuitive if we think in terms of mail server preferring to attempt delivery to the shortest-distanced MX handler.

Mail Server Address:
The mail server address associated with an MX record is the domain name or IP address of the mail server responsible for receiving email messages for the domain.

Let’s consider the domain “” and its corresponding MX records: MX 10 MX 20

In this example, the domain “” has two MX records.

MX Record 1:
Priority: 10
Mail Server Address:

MX Record 2:
Priority: 20
Mail Server Address:

The MX records indicate that email servers should first attempt to deliver messages to the mail server “” with a priority of 10. If that server is unavailable, the backup mail server “” with a priority of 20 should be used.

Check MX record with dig command in Linux

The best way to check MX record in Linux is using dig command. Open the terminal and type dig domain name mx. It will return all the MX records of this domain. For example, dig mx will output the MX records for domain

Here is an example.

% dig mx 
; <<>> DiG 9.10.6 <<>> mx +answer
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59938
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 13, ADDITIONAL: 3
; EDNS: version: 0, flags:; udp: 1280
;; ANSWER SECTION: 0 IN MX 20 0 IN MX 10 0 IN MX 30 0 IN MX 40 0 IN MX 50

In the answer section, there are 5 MX records for the domain are the priorities for these MX records. The ‘priority’ numbers before the domains for these MX records indicate preference; the lower ‘priority’ value is preferred. The server will always try first because 10 is lower than 20. In a result of a message send failure, the server will default to others.

By default, dig performs a lookup for an A record if no type argument is specified.

Check MX record with nslookup Command in Linux

nslookup (from name server lookup) is a network administration command-line tool for querying the Domain Name System (DNS) to obtain the mapping between domain name and IP address, or other DNS records.

  1. To check MX records using the nslookup command in Linux, you can follow these steps:
  2. Open a terminal on your Linux system.
  3. Type nslookup followed by a space.
  4. Set the query type to MX by typing set type=MX.
  5. Enter the domain name for which you want to check the MX records. For example, to check the MX records for “”, type
  6. Press Enter to execute the command.


% nslookup -debug -type=mx

QUESTIONS:, type = MX, class = IN
mail exchanger = 10
ttl = 0
mail exchanger = 40
ttl = 0
mail exchanger = 50
ttl = 0

MX record points to a domain name

MX records can point to a domain name instead of directly specifying an IP address. This allows for flexibility in managing email infrastructure and allows the domain owner to change the underlying mail server’s IP address without modifying the MX records.

DNS MX record must point to another host or to the original host. It is illegal for an MX record to point directly to an A or AAAA record.

hostA IN MX 0 hostA
hostA IN MX 0 <-illegal

This line says that mail for hostA will be delivered to hostA.

MX record points to multiple domain names

It is possible to configure several MX records for a domain, typically pointing to an array of mail servers for load balancing and redundancy. We can understand this from the above MX records.

By specifying multiple MX records, you can distribute email delivery across different mail servers or provide redundancy in case of server failures. Email servers attempting to deliver messages to the domain “” will follow the priorities specified in the MX records and attempt to deliver to the servers in the order of their priority.

This approach ensures that if one mail server is unavailable or overloaded, the email can be routed to an alternative server, providing better reliability and fault tolerance in email delivery for the domain.

MX record points to different domains

It is common for organizations to configure MX records to specify different domains for handling email delivery. This can provide flexibility in managing email infrastructure and allow delegation of email handling to specialized mail servers or third-party email services. Here’s an example:

Suppose we have a domain called “,” and we want to configure MX records to handle email delivery through different domains: MX 10 MX 20

Usually, MX records point to hosts inside the same domain. Therefore, managing them does not require the cooperation of others. But it is legal for MX records to point to hosts in different domains. hostA IN MX 10 hostB

MX record points to a domain that has A or AAAA record

An MX record must point to a hostname that has an A or AAAA record. To illustrate, consider the following:

hostA IN MX 10 hostB ←illegal
hostA IN MX 20 hostC
hostB IN MX 10 hostC
hostC IN A

Note that hostB lacks an A record but hostC has one. It is illegal to point an MX record at a host that lacks an A or AAAA record. Therefore, the first line in the preceding example is illegal, whereas the second line is legal.

DNS MX record Points to 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. Pointing to a CNAME is forbidden by the RFC documents that define how MX records function.

hostA IN MX 10 hostB ←illegal
hostB IN CNAME hostc
hostc IN A