How do I get the mx records for a domain from *nix command line?
42,082
Solution 1
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.
Solution 2
Try this:
nslookup -q=mx mydomain.com
Solution 3
dig -t mx mydomain.com
will work as well.
Related videos on Youtube
Author by
issackelly
Updated on September 17, 2022Comments
-
issackelly over 1 year
What is the best way to lookup MX records for a domain from the command line?
-
bortzmeyer over 14 yearsNo, the option the LEAST verbose is
dig +short MX mydomain.com