在我的机器上本地查询 DNS 服务器 运行 时,如何使 dig 使用 localhost 以外的源 IP?

How do I make dig use a source IP other than localhost while querying a DNS server running locally on my machine?

我正在尝试 运行 一个 coredns 插件 https://github.com/coredns/demo returns 1.1.1.1 for 172.0.0.0/8 or 127.0.0.0/8 and 8.8.8.8 for everything否则。

我 运行 二进制文件并尝试使用 dig example.org @localhost -p1053 +short 从 dig 发出请求,其中 returns 1.1.1.1 因为请求是从本地主机发送的

我是否可以从 dig 向 coredns 发送一个请求,它可能看起来像是从另一个 IP 发送的 DNS 服务器,它会 return 8.8.8.8 而不是?

来自挖掘手册:

   -b address[#port]
       Set the source IP address of the query. The address must be a valid address on one of the host's network interfaces, or "0.0.0.0" or "::". An optional port may be
       specified by appending "#<port>"

否则,如果服务器支持 ECS(EDNS 客户端子网),您可以使用挖掘选项 +subnet=addr 将其提供给服务器并查看其回复如何变化。