2

I'm now using public DNS over VPN to avoid some DNS pollution in China. But this come with a price that I can't take advantage of CDN.

Is there a way to configure dnsmasq and let it query both DNS servers, both public one and ISP one, and return the IP with a lower metric?

I knew it could be done by using server=/domain/server directive to assign a DNS server for a certain domain, but the problem is there are hundreds of them. So I have to figure out something generic.

Thanks in advance.

xiaoyi
  • 123
  • 1
  • 5

3 Answers3

1

DNSmasq cannot do this for you. Powerdns with the pipe backend however can as you can write your own code to do the resolving. I would use python pydns for the backend as it can easily query arbitrary nameservers.

Dennis Kaarsemaker
  • 18,793
  • 2
  • 43
  • 69
1

Is there a way to configure dnsmasq and let it query both DNS servers, both public one and ISP one, and return the IP with a lower metric?

dnsmasq provides the options --all-servers

--all-servers

By default, when dnsmasq has more than one upstream server available, it will send queries to just one server. Setting this flag forces dnsmasq to send all queries to all available servers. The reply from the server which answers first will be returned to the original requestor.

This options does answer your problematic

Spredzy
  • 955
  • 8
  • 11
  • Actually --all-servers can indeed be used to query all the different nameservers. However, the response received can be very unreliable. Since it's mentioned that "The reply from the server which answers first will be returned to the original requestor.", if the fastest server to reply responds with "unable to resolve", the request is not resolved. – moonshadowolf13 Sep 07 '22 at 04:45
0

I don't think dnsmasq gives you this ability. There is a solution that lies with bind though. I know they say setting up bind is an overkill but it's not too bad for what you are trying to do.

options {
    forwarders {
            x.x.x.x;        //ISP dns ip address
            y.y.y.y;        //Public dns ip address
    }
}

The key is that forwarders are queried in order from TOP to bottom. So the ISP will be queried first (which also gives a lower metric most probably) and if it fails, the Public one will be queried.

nass
  • 548
  • 4
  • 10
  • 24
  • Thanks for your replying. But this will always get me polluted IPs. Seems I have to implement it myself... – xiaoyi Nov 28 '12 at 12:08
  • @xiaoyi `this will always get me polluted IPs` why is that? Do the ISP dns server actually return a fake address instead of returning nothing? – nass Nov 28 '12 at 12:12
  • yes, that's how ISP in China do it. like resolve google.com to some black hole IP. – xiaoyi Nov 28 '12 at 12:13