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

;google.de.                     IN      A

google.de.              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 <<>> google.de +noall +answer
;; global options: +cmd
google.de.              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.

  • 1
    Anything in ${HOME}/.digrc?
    – ablackhat
    Sep 23, 2012 at 8:15
  • Nope, good idea though
    – Zulakis
    Sep 23, 2012 at 8:18

4 Answers 4


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
  • 21
    This seems rather interesting. Using dig +noall +answer google.de works, dig google.de +noall +answer doesn't, even though it is supported according to the manual.
    – Zulakis
    Sep 23, 2012 at 8:17
  • 11
    The order of flags apparently matters. Dec 3, 2013 at 19:41

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
  • Sorry, I had to edit my formatting. Hopefully it is now clear. Jan 13, 2018 at 8:00
  • 2
    i still do not get it, WHY and HOW is this an answer to the question? Jan 13, 2018 at 8:02
  • 11
    I suppose I made an assumption about the intent of the original questioner. For me, the full answer line is less useful. And I can do "dig google.com|grep ^google" if I don't remember the options of dig. But the +short option returns an IP address or host name with no additional text, which I can (for example) use in a script to create a firewall rule. That's usually the part of dig's output that matters to me. WIth the "+noall +noanswer" options I still must apply some string processing if I want to use the result in a script. Jan 15, 2018 at 0:27
  • 1
    This only shows the final result, not the full answer section.
    – OrangeDog
    Sep 27, 2021 at 9:16
  • This will also skip CNAMEs and only show the final A record. It's useful but not quite the same thing
    – madacoda
    Mar 3, 2022 at 5:58

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
  • 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, 2014 at 21:46
  • 1
    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, 2014 at 22:41
  • 1
    likely because you can query more than one name at a time. compare 'dig -t soa +noall +answer yahoo.com google.com +question' to 'dig -t soa +noall +answer yahoo.com +question google.com'
    – simpleuser
    Sep 14, 2015 at 0:20
  • +param option does not even work on latest versions of dig
    – madacoda
    Mar 3, 2022 at 5:57

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
google.de.              35      IN      A
google.de.              35      IN      A
[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
google.de.              203     IN      A
google.de.              203     IN      A
  • 6
    See below, dig somehow messes it up when it is dig google.de +noall +answer, it must be dig +noall +answer google.de to have it working. nocomments is already included in noall
    – Zulakis
    Sep 23, 2012 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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