DNS polling maps multiple servers to the same hostname and doesn’t do much for the magic shown here.

If your back-end server is composed of multiple servers, such as a clustered or mirrored Web or file server, load balancer provides a single entry point. Large, busy e-commerce companies spend a lot of money on high-end load balancers to perform a variety of tasks: proxies, caching, health checking, SSL processing, configurable prioritization, traffic shaping, and many more.

But you don’t need a load balancer to do that much work. What you need is a simple way to distribute load across servers that provides failover and doesn’t care much if it’s efficient and perfect. DNS polling and subdomain delegation using polling are two simple ways to achieve this goal.

DNS polling maps multiple servers to the same hostname and is used in such a way that multiple servers can be used to process requests when users visit foo.example.com.

Using polling subdomain delegates is useful when you have multiple subdomains or your servers are geographically scattered. You have a master DNS server, and subdomains have their own DNS servers. Your master DNS server directs all requests to subdomains to their own DNS server. This improves response times because the DNS protocol automatically looks for the fastest link.

DNS round-robin

Polling has nothing to do with thrush Robins, and according to librarians I know, it started out as a French phrase, ruban rond, or round ribbon. Long ago, French government officials signed petitions in ungraded circles, wavy lines, or straight lines to cover their original sponsors.

DNS polling is also non-hierarchical, simply configuring a list of servers and routing requests to each server. It doesn’t really do load balancing because it doesn’t measure load at all, and there’s no health check, so if a server goes down, requests are still sent to that down server. Its virtue is simplicity. If you have a small cluster of files or Web servers and want an easy way to spread the load between them, DNS polling is for you.

All you do is create multiple A or AAAA records that map multiple servers to A single host name. This BIND example uses both IPv4 and IPv6 private address classes:

IN A 172.16.10.10 fileserv.example.com. IN A 172.16.10.11 fileserv.example.com. IN A 172.16.10.12 fileserv.example.com. IN AAAA fd02:faea:f561:8fa0:1::10 fileserv.example.com. IN AAAA fd02:faea:f561:8fa0:1::11 fileserv.example.com. IN AAAA fd02:faea:f561:8fa0:1::12Copy the code

Dnsmasq Saves A and AAAA records in the /etc/hosts file:

172.16.1.10 fileserv fileserv.example.com
172.16.1.11 fileserv fileserv.example.com
172.16.1.12 fileserv fileserv.example.com
fd02:faea:f561:8fa0:1::10 fileserv fileserv.example.com
fd02:faea:f561:8fa0:1::11 fileserv fileserv.example.com
fd02:faea:f561:8fa0:1::12 fileserv fileserv.example.comCopy the code

Note that these examples are very simplified, and there are several ways to resolve a fully qualified domain name, so learn how to configure DNS for yourself.

Use the dig command to check that your configuration works as expected. Replace ns.example.com with your DNS server:

$ dig @ns.example.com fileserv A fileserv AAACopy the code

It displays both IPv4 and IPv6 polling records.

Subdomain delegation and polling

Subdomain delegation is more configuration to do with polling, but it has some advantages. Use it when you have multiple subdomains or geographically dispersed servers. Response times are faster, and downed servers don’t respond, so clients don’t get hung up waiting for a reply. A short TTL, say 60 seconds, will do it for you.

This approach requires multiple DNS servers. In the simplest scenario, you need a primary DNS server and two subdomains, each with its own DNS server. Configure your polling records on the subdomain server, and then delegate on your primary domain server.

In BIND on the primary DNS, you need at least two additional configurations, A zone declaration and A/AAAA records in the zone data file. The delegate in the main DNS server should look like this:

Ns1.sub.example.com IN A 172.16.1.20 ns1.sub.example.com IN AAAA fd02: faea: f561:8 fa0:1: : 20 ns2.sub.example.com IN A 172.16.1.21 ns2.sub.example.com IN AAA fd02: faea: f561:8 fa0:1: : 21 sub.example.com NS IN ns1.sub.example.com. sub.example.com. IN NS ns2.sub.example.com.Copy the code

Each subsequent subdomain server has its own zone file. The key point here is that each server returns its own IP address. The zone declaration in named.conf is the same for all services:

zone "sub.example.com" {
    type master;
    file "db.sub.example.com";
};Copy the code

And the data files are the same, except that the A/AAAA records use each server’s own IP address. SOA records all point to the master DNS server:

; first subdomain name server $ORIGIN sub.example.com. $TTL 60 sub.example.com IN SOA ns1.example.com. admin.example.com. (2018123456; serial 3H ; refresh 15 ; retry 3600000 ; Expire) sub.example.com. IN NS ns1.sub.example.com. Sub.example.com. IN A 172.16.1.20 ns1.sub.example.com. IN AAAA fd02:faea:f561:8fa0:1::20 ; second subdomain name server $ORIGIN sub.example.com. $TTL 60 sub.example.com IN SOA ns1.example.com. admin.example.com. (2018234567; serial 3H ; refresh 15 ; retry 3600000 ; Expire) sub.example.com. IN NS ns1.sub.example.com. Sub.example.com. IN A 172.16.1.21 ns2.sub.example.com fd02:faea:f561:8fa0:1::21Copy the code

Next, generate the polling record on the subdomain server as before. You now have multiple DNS servers to handle requests to your subdomains. Again, BIND is complex and there are multiple ways to do the same thing, so your homework is to figure out the best configuration method for your use.

Making subdomain delegates in Dnsmasq is easy. Add the following line to the dnsmasq.conf file on your primary DNS server to point to the DNS server in the subdomain:

Server=/sub.example.com/172.16.1.20 server=/sub.example.com/172.16.1.21 server=/sub.example.com/fd02:faea:f561:8fa0:1::20 server=/sub.example.com/fd02:faea:f561:8fa0:1::21Copy the code

Then configure polling in /etc/hosts on the subdomain’s DNS server.

For details and help on configuration methods, refer to these resources:

  • Dnsmasq
  • DNS and BIND, 5th Edition