首页 > 解决方案 > 在查询我的机器上本地运行的 DNS 服务器时,如何让 dig 使用 localhost 以外的源 IP?

问题描述

我正在尝试运行一个 coredns 插件https://github.com/coredns/demo,它为 172.0.0.0/8 或 127.0.0.0/8 或 127.0.0.0/8 返回 1.1.1.1 ,为其他所有内容返回 8.8.8.8 。

我运行二进制文件并尝试从 dig 发出请求,使用dig example.org @localhost -p1053 +short它返回 1.1.1.1,因为请求是从 localhost 发送的

无论如何我可以从 dig 向 coredns 发送一个请求,它可能看起来像是从另一个 IP 发送的 DNS 服务器,它会返回 8.8.8.8 吗?

标签: linuxnetworkingdnsdig

解决方案


从挖掘手册:

   -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 客户端子网),您可以使用 dig 选项+subnet=addr将其提供给服务器并查看其回复如何变化。


推荐阅读