8

This command will show the output of MX record:

dig @ns1.myname.com myname.com +short MX

and this will output A record:

dig @ns1.myname.com myname.com +short A


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


UPDATE: Cakemox this is the output I receive:

root@server1:~# dig +noall +answer @ns1.myname.com myname.com MX
myname.com.      86400   IN      MX      10 ASPMX2.GOOGLEMAIL.COM.
myname.com.      86400   IN      MX      10 ASPMX3.GOOGLEMAIL.COM.
myname.com.      86400   IN      MX      1 ASPMX.L.GOOGLE.COM.
myname.com.      86400   IN      MX      5 ALT1.ASPMX.L.GOOGLE.COM.
myname.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 @ns1.myname.com myname.com +short MX; dig @ns1.myname.com myname.com +short A
5 ALT1.ASPMX.L.GOOGLE.COM.
5 ALT2.ASPMX.L.GOOGLE.COM.
10 ASPMX2.GOOGLEMAIL.COM.
10 ASPMX3.GOOGLEMAIL.COM.
1 ASPMX.L.GOOGLE.COM.
63.98.113.202

4 Answers 4

7

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 @ns1.myname.com myname.com +short MX; dig @ns1.myname.com myname.com +short A

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

1
  • 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, 2012 at 19:53
7
dig +noall +answer @ns1.myname.com myname.com 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.

4
  • Hi there, I update my question.
    – sg552
    Feb 5, 2012 at 20:07
  • By "ANY" I mean literally "ANY". It will return all resource record types for a given domain name.
    – Cakemox
    Feb 5, 2012 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, 2012 at 8:00
  • Yup, I was totally assuming that ns1.myname.com was authoritative for myname.com.
    – Cakemox
    Feb 8, 2012 at 12:12
2

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 @ns1.myname.com myname.com +short MX @ns1.myname.com myname.com +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 are 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 @ns1.myname.com myname.com MX myname.com 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 @ns1.myname.com myname.com MX myname.com 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.

0

If your version of dig supports the -f option ("batch mode"), you can have dig read the lookups to perform from stdin:

$ echo -e "a myname.com\nmx myname.com" | dig @ns1.myname.com +short -f -
1.2.3.4
10 mx.myname.com

You must log in to answer this question.

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