How to Check MX Records Using the DIG Command

The Domain Information Groper (DIG) command is a versatile tool for querying Domain Name System (DNS) servers. It is commonly used by network administrators to troubleshoot DNS issues because of its flexibility in showing the various records associated with a domain. In this article, you will learn how to utilize the DIG command specifically to query for Mail Exchange (MX) records, which are essential for determining the mail servers responsible for email reception for a domain.

In this tutorial you will learn:

  • Basic and advanced DIG command usage for querying MX records
  • Customizing output and troubleshooting common DNS problems
How to Check MX Records Using the DIG Command
How to Check MX Records Using the DIG Command
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System A Linux operating system with the ‘dig’ command installed.
Software DIG is part of the BIND DNS software package.
Other Internet connectivity for DNS querying.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user.

Examples of DIG Command Usage for MX Records

When using the dig command to query MX records for a domain, there are several options you can use to tailor the output and operation of the query. These options enhance the functionality of dig and allow users to customize the DNS query process according to specific requirements. Here’s a brief explanation of each option you will find in the examples below:

  • +short: Provides a concise output, showing only the MX records without additional details.
  • +noall: Suppresses all output except for what is explicitly requested.
  • +answer: Displays only the answer section of the query response, which includes the MX records.
  • +trace: Traces the path of the DNS resolution from the root servers down to the authoritative name servers.
  • +stats: Adds timing and operational statistics to the output, helping to diagnose performance.
  • +nocomments: Omits explanatory comments in the output, providing a cleaner view.
  • +json: Formats the output in JSON, making it easier to parse programmatically.
  • +dnssec: Includes DNS Security Extensions details, ensuring the response is verified and secure.
  • +time: Sets the query timeout period, useful for slower network connections.
  • +port: Specifies a different port number for the DNS query, useful when the default DNS port is blocked or redirected.
  • +tcp: Forces the query to use TCP instead of UDP, helpful for larger responses that exceed the UDP size limit.
  • +bufsize: Sets the size of the buffer used for UDP DNS queries, which can prevent fragmentation.
  • +retry: Specifies the number of retries for the query in case of failure, increasing reliability.
  • +additional: Shows additional records related to the query, providing more context.
  • +authority: Displays the authoritative section of the DNS response, which contains the servers responsible for the domain.

Here are practical uses of the DIG command for querying MX records. These examples illustrate a variety of operations achievable with DIG, ranging from straightforward queries to more intricate troubleshooting and analytical tasks. For demonstration purposes, we have used the domain “google.com” in our examples. Please replace “google.com” with your desired domain when applying these techniques.

  1. Basic MX Record Query: Retrieves the MX records for a domain.
    $ dig google.com MX

    This command provides MX records in a readable format, indicating the associated mail servers and their priorities.

  2. Short Format: Shows only the essential MX records without additional information.
    $ dig google.com MX +short

    This output is suitable for scripting or when only the raw MX record data is needed.

  3. Specifying a DNS Server: Targets a specific DNS server for your query.
    $ dig @8.8.8.8 google.com MX

    Useful when you want to bypass local DNS settings or when testing the response from an external name server.

  4. Verbose Output: Includes comprehensive details about the query and response.
    $ dig google.com MX +noall +answer

    This is helpful for debugging, as you can see the response section with just the answer to the query.

  5. DNS Path Trace: Shows how the DNS resolution happens from the root servers.
    $ dig +trace google.com MX

    Each step of the DNS lookup process is detailed, which is useful for seeing where potential issues may occur in DNS resolution.

  6. Timing Information: Adds performance statistics to the output.
    $ dig google.com MX +stats

    Analyzes the performance by indicating the duration of each phase of the DNS query.

  7. Querying Multiple Record Types: Fetches MX with A and AAAA records simultaneously.
    $ dig google.com MX A AAAA

    This gathers a more comprehensive set of DNS records that can aid in a broader analysis of the domain’s DNS configuration.

  8. Suppressing Comments: Omits comments in the output for a clearer display.
    $ dig google.com MX +nocomments

    Streamlines the output which can be easier to read or parse programmatically.

  9. Global DNS Information: Retrieves detailed DNS information including global settings.
    $ dig +trace +additional google.com MX

    Shows not just the MX records but also additional records that could be helpful in a detailed analysis.

  10. Different Output Formats: Outputs the response in JSON format, useful for automation.
    $ dig google.com MX +json

    Facilitates parsing the DIG command output when used in scripts or programs.



  11. DNSSEC Validation: Includes DNS Security Extensions details.
    $ dig google.com MX +dnssec

    Assures the integrity of the DNS response, checking for potential tampering.

  12. Timeout Increase: Adjusts the timeout setting for slower network environments.
    $ dig google.com MX +time=10

    Increases the waiting period for a DNS response, reducing the chance of timeouts in sluggish networks.

  13. Changing Query Port: Sends the query via a different port.
    $ dig google.com MX +port=5353

    Useful if your network or firewall setup requires DNS queries to be sent through a non-standard port.

  14. Using TCP Protocol: Switches from the default UDP to TCP for the DNS query.
    $ dig +tcp google.com MX

    Helpful when dealing with large DNS responses or in scenarios where UDP packets may be dropped or fragmented.

  15. Setting UDP Packet Size: Specifies the maximum size of UDP packets.
    $ dig google.com MX +bufsize=512

    Controls the chances of UDP fragmentation, which is useful in tuning the response for different network conditions.

  16. Retry Mechanism: Sets the number of retries for failed queries.
    $ dig google.com MX +retry=5

    Increases reliability by attempting the query multiple times in case of temporary network or server issues.

  17. Listing Detailed MX Records: Combines several flags for a comprehensive output.
    $ dig google.com MX +noall +answer +additional

    Outputs detailed lists of MX records, including the IP addresses of the mail servers, which is crucial for in-depth analysis and troubleshooting.

Conclusion

By mastering the DIG command, network professionals and enthusiasts can perform a wide variety of DNS queries and gain insight into the configuration and health of the domain’s MX records. The examples provided demonstrate just a fraction of DIG’s capabilities, showing that you can resolve simple MX record queries or dive into detailed DNS analysis.

We encourage you to try these examples yourself to enhance your understanding of DNS operations. If you have any questions or additional insights on using the DIG command for MX records, please leave a comment below.



Comments and Discussions
Linux Forum