dig show only answer

I want dig only to show the answer of my query.

Normally, it prints out alot of additional info like this:

;; <<>> DiG 9.7.3 <<>> google.de
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55839
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.de.                     IN      A

;; ANSWER SECTION:
google.de.              208     IN      A       173.194.69.94

;; Query time: 0 msec
;; SERVER: 213.133.99.99#53(213.133.99.99)
;; WHEN: Sun Sep 23 10:02:34 2012
;; MSG SIZE  rcvd: 43

I want this to be reduced to just the answer section.

dig has alot of options, a good one i found was +noall +answer

; <<>> DiG 9.7.3 <<>> google.de +noall +answer
;; global options: +cmd
google.de.              145     IN      A       173.194.69.94

It leaves out most of the stuff, but still shows this options thing.

Any ideas on how to remove it using dig options? I sure could cut it out using other tools, but a option with dig itself would be the cleanest and nicest.


Solution 1:

I am not sure why you are getting comments in the output. That is the correct set of options for the behaviour you want. Here are the same options with the same version of dig:

$ dig -version
DiG 9.7.3
$ dig +noall +answer google.de
google.de.      55  IN  A   173.194.44.216
google.de.      55  IN  A   173.194.44.223
google.de.      55  IN  A   173.194.44.215
$

Solution 2:

Use the "+short" option

[root@myhost ~]# dig +short google.com
216.58.194.142

[root@myhost ~]# dig +short -x 216.58.194.142
dfw06s49-in-f14.1e100.net.
dfw06s49-in-f142.1e100.net.

[root@myhost ~]# dig +short google.com soa
ns1.google.com. dns-admin.google.com. 181803313 900 900 1800 60

Solution 3:

Use dig +param domain, not dig domain +param.

% dig +noall +answer -t aaaa d.ns.zerigo.net
d.ns.zerigo.net.        37788   IN      AAAA    2607:fc88:1001:1::4
% dig -t aaaa d.ns.zerigo.net +noall +answer

; <<>> DiG 9.9.2-P2 <<>> -t aaaa d.ns.zerigo.net +noall +answer
;; global options: +cmd
d.ns.zerigo.net.        37797   IN      AAAA    2607:fc88:1001:1::4

+noall +answer switch works differently depending on its position in the command line. This is surely a bug in dig since +short works OK on both sides.

% dig +short -t aaaa d.ns.zerigo.net
2607:fc88:1001:1::4

% dig -t aaaa d.ns.zerigo.net +short
2607:fc88:1001:1::4

Solution 4:

According to the man page, you might want to try:

dig google.de +noall +answer +nocomments

If that doesn't work I would have to ask what distribution you are using?

Edit: That is the weirdest thing. You have to put the options before the query.

[jglenn@lin02 ~]$ dig +noall +answer google.de
google.de.              35      IN      A       74.125.227.119
google.de.              35      IN      A       74.125.227.120
google.de.              35      IN      A       74.125.227.127
[jglenn@lin02 ~]$ dig +answer google.de +noall

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6_3.3 <<>> +answer google.de +noall
;; global options: +cmd
[jglenn@lin02 ~]$ dig google.de +noall +answer

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6_3.3 <<>> google.de +noall +answer
;; global options: +cmd
google.de.              203     IN      A       74.125.227.119
google.de.              203     IN      A       74.125.227.120
google.de.              203     IN      A       74.125.227.127