Search code examples
linuxnetworkingdnsdig

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


I am trying to run a coredns plugin https://github.com/coredns/demo that returns 1.1.1.1 for 172.0.0.0/8 or 127.0.0.0/8 and 8.8.8.8 for everything else.

I run the binary and try to make a request from dig using dig example.org @localhost -p1053 +short which returns 1.1.1.1 since the request is sent from localhost

Is there anyway I can send a request from dig to coredns that it might look like to the DNS server that it is sent from another IP and it will return 8.8.8.8 instead?


Solution

  • From dig manual:

       -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>"
    

    Otherwise, if the server supports ECS (EDNS Client Subnet) you can use dig option +subnet=addr to give it to the server and see how its reply changes.