Balancing load between two DNS servers


I have a net with 2 DNS servers (master & slave), but I don’t want clients to ask directly to them. So, in the same net, I have a debian machine with haproxy 1.7.5 installed. I want clients to have in their /etc/resolv.conf file the IP of the proxy. I want the proxy to balance the load between the two servers.

IP DNS master =
IP DNS slave =

In the file /etc/haproxy/haproxy.cfg at the end, I added:

resolvers mydns
    nameservers dns1
    nameservers dns2

Then I start haproxy:

haproxy -f /etc/haproxy/haproxy.cfg

If I execute in the proxy:

netstat -tuna

I get these two new lines:

udp    0    0    ESTABLISHED
udp    0    0    ESTABLISHED

But I was expecting to receive something like this:

udp    0    0    ESTABLISHED
udp    0    0    ESTABLISHED

Obviously, the DNS requests from clients to the proxy aren’t working…

Is it possible to achieve this using haproxy?



You can’t load balance UDP with haproxy. That’s not what the dns resolvers command in haproxy is for. You’d need a udp load balancer. You can use nginx for this if you do a custom compile.



Okay, thank you very much!!


dnsdist (or just iptables or pf rules
depending on your needs and platform) is for load balancing DNS. Using nginx for this is a poor choice.