brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: dig -b picks which local address the query comes from

Dig
~/tips/tip-dns-dig-source-address

dig -b 192.168.1.20 @192.168.1.53 example.com

Sends a dig query from a chosen local address instead of the default one.

A machine with several addresses, or a server with both a VPN and a LAN interface, can send a DNS query from the address you did not mean. Resolvers that only answer certain clients then behave oddly. dig can choose its source.

The option is -b:

dig -b 192.168.1.20 @192.168.1.53 example.com

From the manual: it sets the source IP address of the query, and the address must be a valid address on one of the host’s network interfaces, or 0.0.0.0 or ::. A port can be added by appending #port, for instance -b 192.168.1.20#5300.

With that I can ask a resolver from the second interface of the same machine, for example to test whether an access list on it works as intended. Run the query once per address and compare:

dig -b 192.168.1.20 @192.168.1.53 example.com +short
dig -b 10.0.0.20 @192.168.1.53 example.com +short

If one gets an answer and the other gets a refusal or a timeout, the resolver treats the two source addresses differently.

The caveat: you cannot fake an address the machine does not have. The manual says it must be an address of one of the host’s interfaces, so for a test from a different network you need a client that really sits there.

Further reading: dig manual (-b)

Going deeper: Guide: dig for beginners, look up DNS records and read the answer

More Dig tips dig +noall +answer DS example.com dig nope.iana.org @9.9.9.9 | grep -E 'status|SOA' dig +search nas dig @8.8.8.8 www.google.com +subnet=203.0.113.0/24 dig +yaml example.com A All Dig tips (36) All topics

Link