Score:0

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

im flag

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.
Patrick Mevzek avatar
cn flag
The port number is always 53, and the IP address should be the same for UDP or TCP so why not leverage the one from TCP error message? I did not see any option or way to achieve what you want specifically with `dig`.
Score:1
im flag

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
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.