57

What is the best way to lookup MX records for a domain from the command line?

3 Answers 3

96

Here are 4 options, in order from least to most verbose:

dig +short -t mx mydomain.com
host -t mx mydomain.com
nslookup -q=mx mydomain.com
dig -t mx mydomain.com

(Thanks to bortzmeyer for suggesting dig +short.)

The difference is largely a matter of personal preference and what your goal is. I tend to use host, but if you want full details about exactly what you're getting back from the server (e.g. because you're troubleshooting DNS), dig is the way to go. On the third hand, if you're doing this in a script, the output from dig +short is going to be easiest to parse.

1
  • 8
    No, the option the LEAST verbose is dig +short MX mydomain.com
    – bortzmeyer
    Sep 21, 2009 at 7:19
8

dig -t mx mydomain.com will work as well.

8

Try this:

nslookup -q=mx mydomain.com

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .