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

How to make dig to show IP addresses it is sending queries to?

· 52CE 我爱测

By default when DNS servers do not respond dig does not show any information about the queries being sent. I can use the +qr option to see each query being sent: $ dig +qr archive.ubuntu.com ; <<>> DiG 9.16.1-Ubuntu <<>> +qr arch…

问题原文

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

By default when DNS servers do not respond dig does not show any information about the queries being sent. I can use the +qr option to see each query being sent:

$ dig +qr archive.ubuntu.com

; <<>> DiG 9.16.1-Ubuntu <<>> +qr archive.ubuntu.com
;; global options: +cmd
;; Sending:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21059
;; flags: rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: ec2af2d60803b6a5
;; QUESTION SECTION:
;archive.ubuntu.com.            IN      A

;; QUERY SIZE: 59

Unfortunately I still do not see the information I need most - the IP address the query is being sent to and ideally the port number too. Is it possible to make dig to show this information?

I can see this information for failed TCP connections but I would really like to see it failed UDP queries too.

$ dig +tcp archive.ubuntu.com
;; Connection to 172.29.128.1#53(172.29.128.1) for archive.ubuntu.com failed: timed out.

已采纳解答

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

Since the version 9.15.4 of ISC BIND released in 2019-09, dig supports YAML output which contains the DNS server's protocol, address and port.

Example of extracting the values using yq:

dig +yaml www.seznam.cz | yq -r '.[] | select(.type=="MESSAGE") | .message |
    [.socket_protocol, .response_address, .response_port] | @tsv'
UDP     172.31.112.1    53

Example of different way of formatting the output:

dig +yaml www.seznam.cz | yq -r '.[] | select(.type=="MESSAGE") | .message |
    "\(.response_address):\(.response_port)"'
172.31.112.1:53

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

资料来源与适用范围

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

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

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