howtouselinux

5 Useful Tips to Check DNS MX Record in Linux

Table of Contents

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 domain.com mx will output all the MX records for domain.com.

  • 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

Example of DNS MX record

% dig google.com mx +answer
; <<>> DiG 9.10.6 <<>> google.com 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
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1280
;; QUESTION SECTION:
;google.com. IN MX
;; ANSWER SECTION:
google.com. 0 IN MX 20 alt1.aspmx.l.google.com.
google.com. 0 IN MX 10 aspmx.l.google.com.
google.com. 0 IN MX 30 alt2.aspmx.l.google.com.
google.com. 0 IN MX 40 alt3.aspmx.l.google.com.
google.com. 0 IN MX 50 alt4.aspmx.l.google.com.

In the answer section, there are 5 MX records for the domain google.com. 10.20.30.40.50 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 aspmx.l.google.com. first because 10 is lower than 20. In a result of a message send failure, the server will default to others.

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.

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.

For example, if we send an email from hello@yahoo.com to hello@gmail.com, the yahoo mail server will try to send that email to the above 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 www.howtouselinux.com and attempt delivery there.

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 example.com mx +answer will output the MX records for domain example.com.

By default, dig performs a lookup for an A record if no type argument is specified. For Mx record, we can use this command to get it. – dig domain mx. Here is an example.

% dig google.com mx +answer
; <<>> DiG 9.10.6 <<>> google.com 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
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1280
;; QUESTION SECTION:
;google.com. IN MX
;; ANSWER SECTION:
google.com. 0 IN MX 20 alt1.aspmx.l.google.com.
google.com. 0 IN MX 10 aspmx.l.google.com.
google.com. 0 IN MX 30 alt2.aspmx.l.google.com.
google.com. 0 IN MX 40 alt3.aspmx.l.google.com.
google.com. 0 IN MX 50 alt4.aspmx.l.google.com.

 

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.

% nslookup -debug -type=mx google.com

Server: 64.104.76.247
Address: 64.104.76.247#53
————
QUESTIONS:
google.com, type = MX, class = IN
ANSWERS:
google.com
mail exchanger = 10 aspmx.l.google.com.
ttl = 0
google.com
mail exchanger = 40 alt3.aspmx.l.google.com.
ttl = 0
google.com
mail exchanger = 50 alt4.aspmx.l.google.com.
ttl = 0

MX record points to a domain name

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 192.168.1.1 <-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 google.com MX records.

MX record points to different domains

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
IN MX 20 hostC
hostB IN MX 10 hostC
hostC IN A 192.168.1.2

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 123.45.67.89

 

 

Related:

Welcome to howtouselinux.com!

Our website is dedicated to providing comprehensive information on using Linux.

We hope you find our site helpful and informative, and we welcome your feedback and suggestions for future content.

Learn More

Facebook
Twitter
LinkedIn