What is the best way to lookup MX records for a domain from the command line?
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
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.