How to check MX records with dig

Mail exchangers tell senders which hosts should receive inbound mail for a domain. Checking MX records with dig helps confirm a mail-provider cutover, investigate bounce reports, or prove that a domain intentionally refuses inbound mail before deeper SMTP troubleshooting begins.

dig asks the resolver configured on the workstation unless a server is named with @server. An MX answer row includes the owner name, TTL, class, record type, preference value, and exchange host. SMTP senders prefer lower preference numbers before higher ones.

Printed answer order is not the same as delivery order, and DNS evidence does not prove SMTP reachability, TLS readiness, provider provisioning, or mailbox acceptance. A single MX 0 . row is a Null MX no-mail signal, while a name with no MX answer may still need address-record review when it is expected to receive mail.

Steps to check MX records with dig:

  1. Query the domain for MX records with status and answer rows visible.
    $ dig +noall +comments +answer gmail.com MX
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1
    
    ;; ANSWER SECTION:
    gmail.com.		432	IN	MX	5 gmail-smtp-in.l.google.com.
    gmail.com.		432	IN	MX	20 alt2.gmail-smtp-in.l.google.com.
    gmail.com.		432	IN	MX	10 alt1.gmail-smtp-in.l.google.com.
    gmail.com.		432	IN	MX	40 alt4.gmail-smtp-in.l.google.com.
    gmail.com.		432	IN	MX	30 alt3.gmail-smtp-in.l.google.com.

    NOERROR means the resolver returned a DNS response for the name. The ANSWER count shows how many MX rows matched the query.

  2. Read each MX answer row from left to right.

    The fields are owner name, TTL in seconds, class, type, preference, and exchange host. TTL values can differ between repeated checks because recursive resolvers cache answers.

  3. Identify the preferred mail route by the lowest preference value.

    Preference 5 is preferred before 10, 20, 30, and 40. When several rows share the same preference, SMTP senders can treat those exchangers as peers rather than relying on the printed order.

  4. Print compact MX rows when the status has already been checked.
    $ dig +short gmail.com MX
    5 gmail-smtp-in.l.google.com.
    20 alt2.gmail-smtp-in.l.google.com.
    10 alt1.gmail-smtp-in.l.google.com.
    40 alt4.gmail-smtp-in.l.google.com.
    30 alt3.gmail-smtp-in.l.google.com.

    The compact form keeps the preference value before the exchange host, but removes the DNS status, answer count, TTL, class, and type.
    Related: How to show short DNS answers with dig

  5. Resolve the selected exchange host when mail routing readiness matters.
    $ dig +noall +answer gmail-smtp-in.l.google.com A
    gmail-smtp-in.l.google.com. 74	IN	A	74.125.130.26

    A reachable address record is only the DNS layer of the mail route. Test SMTP separately when firewall, TLS, provider, or mailbox acceptance is part of the incident.

  6. Check for a Null MX record on domains that should not receive mail.
    $ dig +noall +comments +answer example.com MX
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR
    ;; flags: qr rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
    
    ;; ANSWER SECTION:
    example.com.		300	IN	MX	0 .

    A single exchange host of . with preference 0 declares that the domain accepts no inbound mail. Do not mix a Null MX row with normal mail exchangers.

  7. Check the DNS status when no MX answer row appears.
    $ dig +noall +comments +question +answer www.example.com MX
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR
    ;; flags: qr rd ra ad; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
    
    ;; QUESTION SECTION:
    ;www.example.com.		IN	MX

    NOERROR with ANSWER: 0 means the name exists from this resolver's view but has no MX row for the query. NXDOMAIN means the queried name does not exist.