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 = 10.10.24.2
IP DNS slave = 10.10.24.4
IP PROXY = 10.10.24.5

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

resolvers mydns
    nameservers dns1 10.10.24.2:53
    nameservers dns2 10.10.24.4:53

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    10.10.24.5:35000    10.10.24.2:53    ESTABLISHED
udp    0    0    10.10.24.5:35000    10.10.24.4:53    ESTABLISHED

But I was expecting to receive something like this:

udp    0    0    10.10.24.5:53    10.10.24.2:53    ESTABLISHED
udp    0    0    10.10.24.5:53    10.10.24.4:53    ESTABLISHED

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

Is it possible to achieve this using haproxy?

Hello,

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.

/Dave

2 Likes

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.

1 Like