大网数据广告活动
服务器运维问答

How to enable dig to show status codes?

· 52CE 我爱测

With default options dig shows the return status for a DNS query in the comment ;; ->>HEADER<<- ... status: NXDOMAIN : ubuntu:~$ dig hosted-by.myinternetservices.com. ; <<>> DiG 9.11.3-1ubuntu1.2-Ubuntu <<>> hosted-by.myinternets…

问题原文

原帖链接 · pabouk - Ukraine stay strong · CC BY-SA 4.0

With default options dig shows the return status for a DNS query in the comment ;; ->>HEADER<<- ... status: NXDOMAIN:

ubuntu:~$ dig hosted-by.myinternetservices.com.

; <<>> DiG 9.11.3-1ubuntu1.2-Ubuntu <<>> hosted-by.myinternetservices.com.
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 63671
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;hosted-by.myinternetservices.com. IN   A

;; Query time: 0 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Wed Oct 17 10:15:02 CEST 2018
;; MSG SIZE  rcvd: 61

But very often I want to have a shorter output from dig and I use the option +noall to achieve this:

ubuntu:~$ dig +noall +answer www.seznam.cz.
www.seznam.cz.          266     IN      A       77.75.77.39
ubuntu:~$ dig +noall +short www.seznam.cz.
77.75.77.39

I also need to see the status for cases when there is no answer but I was not able to get the status when I use +noall. Is there a simple way how to show the status?

已采纳解答

原帖链接 · Andrew B · CC BY-SA 4.0

There is, but it makes the output less terse. The response code is only shown in +comments to the best of my knowledge.

$ dig +noall +comments +answer example.com
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 7367
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; ANSWER SECTION:
example.com.            58368   IN      A       93.184.216.34

The only way to condense it down any further is to perform your own text transformations on the above output. If you find yourself needing to work with the individual fields of a DNS response frequently, you might be better off looking at writing a custom script using a DNS client library for your preferred language.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。