Howto Round Robin DNS on a Linux server
Round Robin DNS is the simplest way to load balance a webserver between 2 or more servers in different location or to have network redundancy. For load balancing, it does not take in consideration the load on the servers but it's extremely easy to setup. It's also quite effective for network redundancy, you can plug a single server on 2 different network/switch and if one fail, all trafic will go on the available network.
If you need to load balance servers in the same datacenter I suggest reading this article.
Networking setup
- 1 server with multiple NIC
- 2 servers at different locations
You simply need 2 network cards. Let say you will have eth0 : 64.15.75.216 and eth1 : 209.44.107.14
Location 1 IP : 64.15.75.216, location 2 IP : 209.44.107.14
Apache setup
- 1 server with multiple NIC
- 2 servers at different locations
The apache vhost will look like this :
<VirtualHost 64.15.75.216:80 209.44.107.14:80> [...] </VirtualHost>
Simply do something like this :
Location 1
<VirtualHost 64.15.75.216:80> [...] </VirtualHost>
Location 2
<VirtualHost 209.44.107.14:80> [...] </VirtualHost>
DNS server setup
When you have a request on your DNS server, the answer has to send 2 different IP. For example, with Bind, the order of how IP are sent is random.
Try :
dig portafixe.com
and you should see something like :
;; ANSWER SECTION: portafixe.com. 86400 IN A 64.15.75.216 portafixe.com. 86400 IN A 209.44.107.14
if you dig again, IP priority should be different.
This does 2 things.
- In theory, if one IP doesn't answer, ISP will ask the next IP within a few seconds (redundancy). I did some test with my ISP and the first request took 5 seconds to switch to the available IP.
- Load balance requests between the 2 IP addresses.
To configure that in bind, you need 2 A records with the differents IP addresses on all DNS servers. Here is an example of the bind zone file of portafixe.com :
[...] portafixe.com. A 64.15.75.216 www A 64.15.75.216 portafixe.com. A 209.44.107.14 www A 209.44.107.14 [...]
Note : If you do round robin DNS a domain for redundancy, it is also a very good idea to round robin the DNS server.
MySQL replication and web files mirroring
If you have 2 or more servers, I suggest reading those articles :
Mirroring web & mail files with rsync
They are part of a full tutorial on high availability and load balancing but they can still be used as is with little modifications.
- subjects:

