dnsmasq round-robin how to

Dnsmasq is currently compiled with round – robin algorithm (or a simple implementation of this algorithm). We make use of this capability for an very simple load balancing technique.
What dnsmasq & round robin do? Basically , we configure 1 host and give for him N° IP addresses , dnsmasq changes the IP order of this IP corresponding to one host after any single DNS request.
Whats the point?
After each new connection the IP responding will be the next in the list , doing so the requests will be balanced on 3 different servers managing 1 domain.
Let’s say we have a very big host called blackbox and for not bombing our host and the load we just add 3-5 or N servers for balancing the load of the server.

We give to our linux router/firewall an configuration like:
cat /etc/hosts
# /etc/hosts: static lookup table for host names

#<ip-address>    <hostname.domain.org>    <hostname>        localhost.localdomain    localhost darkinet blackbox blackbox blackbox
#NOTE: In real life this should be something like blackbox.com with an public IP address.
#           www.google.com   #I added google before lol 😀
# End of file

Ok, this is good, now lets see our simple configuration at work:
If we just $dig blackbox

blackbox.		0	IN	A
blackbox.		0	IN	A
blackbox.		0	IN	A

The seccond response

blackbox.		0	IN	A
blackbox.		0	IN	A
blackbox.		0	IN	A

The third response

blackbox.		0	IN	A
blackbox.		0	IN	A
blackbox.		0	IN	A

So, we see that the order of the IP changes after each DNS request cyclically.
Then we restart dnsmasq
# /etc/init.d/dnsmasq restart

This is not for serious load balancing (yep it costs up to 4000 bucks or even more)
So in conclusion, if you are not

ns1.google.com.        329163    IN    A
ns2.google.com.        327587    IN    A
ns3.google.com.        331744    IN    A
ns4.google.com.        331744    IN    A

And you don’t have the need to use 4 server farms for a domain, than this may be your case.

2 thoughts on “dnsmasq round-robin how to

  1. It’s so interesting, i think that is possible to do the same thing with internet line.
    To make a load balance system with more than one internet line.

  2. Yes mister spammer :D, It will be great if you expand your idea, In my case i have 1 uplink (WAN) and on the DMZ I have some servers, in this case I use the firewall for routing to , and modify the /etc/hosts, this is possible because the target is 1 single ip address, but i don’t understand how could be a load balancing between 2 different hosts from 2 different WAN’s?

Leave a Reply

Your email address will not be published. Required fields are marked *