dig show only answer

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
google.de.      55  IN  A
google.de.      55  IN  A

Solution 2:

Use the "+short" option

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

[root@myhost ~]# dig +short -x

[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

% dig -t aaaa d.ns.zerigo.net +short