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

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 <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55839
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;                     IN      A

;; ANSWER SECTION:              208     IN      A

;; Query time: 0 msec
;; 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 <<>> +noall +answer
;; global options: +cmd              145     IN      A

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.

share|improve this question
Anything in ${HOME}/.digrc? – ablackhat Sep 23 '12 at 8:15
Nope, good idea though – Zulakis Sep 23 '12 at 8:18

3 Answers 3

up vote 5 down vote accepted

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      55  IN  A      55  IN  A      55  IN  A
share|improve this answer
This seems rather interesting. Using dig +noall +answer works, dig +noall +answer doesn't, even though it is supported according to the manual. – Zulakis Sep 23 '12 at 8:17
The order of flags apparently matters. – generalnetworkerror Dec 3 '13 at 19:41

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

dig +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              35      IN      A              35      IN      A              35      IN      A
[jglenn@lin02 ~]$ dig +answer +noall

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

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6_3.3 <<>> +noall +answer
;; global options: +cmd              203     IN      A              203     IN      A              203     IN      A
share|improve this answer
See below, dig somehow messes it up when it is dig +noall +answer, it must be dig +noall +answer to have it working. nocomments is already included in noall – Zulakis Sep 23 '12 at 8:19

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

% dig +noall +answer -t aaaa        37788   IN      AAAA    2607:fc88:1001:1::4
% dig -t aaaa +noall +answer

; <<>> DiG 9.9.2-P2 <<>> -t aaaa +noall +answer
;; global options: +cmd        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

% dig -t aaaa +short
share|improve this answer
Did you file it as bug or why did you add this paraphrase of the accepted answer to this question which has been solved 2 years ago? – Zulakis Jul 28 '14 at 21:46
The accepted answer says "I am not sure why you are getting comments in the output.", whereas I do know why and this answer is the most accurate one. – Nowaker Jul 28 '14 at 22:41
likely because you can query more than one name at a time. compare 'dig -t soa +noall +answer +question' to 'dig -t soa +noall +answer +question' – user1663987 Sep 14 at 0:20

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.