Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This command will show the output of MX record:

dig +short MX

and this will output A record:

dig +short A

My question is how to output both A and MX with +short in one output display? Thank you.

UPDATE: Cakemox this is the output I receive:

root@server1:~# dig +noall +answer MX      86400   IN      MX      10 ASPMX2.GOOGLEMAIL.COM.      86400   IN      MX      10 ASPMX3.GOOGLEMAIL.COM.      86400   IN      MX      1 ASPMX.L.GOOGLE.COM.      86400   IN      MX      5 ALT1.ASPMX.L.GOOGLE.COM.      86400   IN      MX      5 ALT2.ASPMX.L.GOOGLE.COM.

I was hoping I could get this kind of output with just one dig command and without separating with semicolon?

root@server1:~# dig +short MX; dig +short A

Thank you.

share|improve this question
up vote 3 down vote accepted

What do you mean by 'ouput in one display'?

I can almost not imagine this being the actual answer due to the simplicity, but based on what I assume is your answer now, this should do the trick:

dig +short MX; dig +short A

You can simply queue several commands in one line by separating them with a semicolon.

share|improve this answer
Ah yes thats what I mean actually. Sorry about my English. Is there anyway I could run it with just one dig query instead separating with semicolon? I will mark this as solve. Thank you. – sg552 Feb 5 '12 at 19:53
dig +noall +answer ANY

You can grep out the types you need if you don't want all of them, or query for each one you want in turn.

share|improve this answer
Hi there, I update my question. – sg552 Feb 5 '12 at 20:07
By "ANY" I mean literally "ANY". It will return all resource record types for a given domain name. – Cakemox Feb 5 '12 at 20:50
It's worth adding that ANY only works the way you expect with the authoritative name servers for that domain. Non-authoritative name servers will return everything they currently have cached but will not do any extra queries for records they don't have cached. – Ladadadada Feb 8 '12 at 8:00
Yup, I was totally assuming that was authoritative for – Cakemox Feb 8 '12 at 12:12

You can combine them into one command with no semicolon, but as noted in another question, it will still send 2 queries to the server (not a problem here):

dig +short MX +short A

You can "reuse" the dig command and keep sending new query parameters in quartets (URL, server to query, query type, query option) as long as you giving it enough information to run a query on each quartet. More simpler still, you only need to specify the server and query option once, so this works:

dig +short MX A

If you need only one query for some reason, you can use ANY with dig (make sure you are querying the authoritative server, not a recursive server's cache) and grep out the answers with the -E option:

dig +noall +answer MX A | grep -E '[[:space:]]A[[:space:]]|MX[[:space:]]'

Note: you cannot use +short with this route as it removes the record type you need to use grep on.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.