1

I'm wondering if it is possible just using DNS records to "load balance" traffic coming to my nameservers.

I thought about having multiple A records per nameserver, like this:

           IN NS ns1.example.com
           IN NS ns2.example.com

    ns1    IN A  10.0.0.1
    ns1    IN A  10.0.0.2
    ns2    IN A  10.0.0.1
    ns2    IN A  10.0.0.2

The idea is that the requests will be routed evenly to the two servers, even if the resolver always chose ns1, or if an intermediary dns cache is causing trouble.

I have used something like this for my MXs and it works, but I'm not sure if it works for the NSs records too. I don't really see a reason why it wouldn't, but I'd like your opinion.

Thanks.

EDIT

To be clear, I'm not looking for a perfect load balancing solution here, and I'm aware that a client will have to retry on the second NS if the first is down.

I simply would like to have an equal bandwidth repartition on each server, not because one is overloaded, but because I have a traffic cap on each of those servers, so I would like to avoid having 90% of the requests go to ns1 and the rest to ns2.

1
  • 1
    Have you considered a UDP load balancer in front of your DNS servers?
    – pauska
    May 30, 2013 at 14:52

5 Answers 5

4

DNS is Already Load Balanced

DNS (in most cases) is inherently load balanced through one of two mechanisms.

NS Records are Returned in Random Order

Most DNS servers will return NS inquiries in a random order.

Note the two queries below. See how on a subsequent query, the order of the nameservers is changed.

dig @8.8.8.8 NS serverfault.com


;; ANSWER SECTION:
serverfault.com.        300     IN      NS      ns1.serverfault.com.
serverfault.com.        300     IN      NS      ns3.serverfault.com.
serverfault.com.        300     IN      NS      ns4.serverfault.com.
serverfault.com.        300     IN      NS      ns2.serverfault.com.



;; ANSWER SECTION:
serverfault.com.        300     IN      NS      ns2.serverfault.com.
serverfault.com.        300     IN      NS      ns3.serverfault.com.
serverfault.com.        300     IN      NS      ns1.serverfault.com.
serverfault.com.        300     IN      NS      ns4.serverfault.com.

DNS Resolver Behavior

Most DNS resolvers will pick the first nameserver in the list and query it. Some will pick a nameserver at random.

In either case, if your DNS server is randomizing your NS records, then traffic should be balanced.

Load Balanced DNS

In your case, you are pointing NS1/NS2 to the same IPs. There's no need for this. However, if you had.

ns1.domain.com 10.0.0.1
ns1.domain.com 10.0.0.2
ns2.domain.com 10.0.0.3
ns2.domain.com 10.0.0.4

You would not be splitting traffic for NS1 over two servers. This would spread the requests for NS1 over the two servers. Before DNS providers started using anycast approaches, this was and is a popular technique.

(Note there are some changes with IPv6.
See http://blogs.technet.com/b/networking/archive/2009/04/17/dns-round-robin-and-destination-ip-address-selection.aspx)

2
  • Thanks for the information, but I don't really understand your last point. 10.0.0.1 and 10.0.0.3 are on the same server ? If that's the case, is it any different than what I wrote ? Because in my example, 10.0.0.1 is one server and 10.0.0.2 is another, so the requests are spread too right ? May 31, 2013 at 12:40
  • Each IP represents a different server. May 31, 2013 at 12:59
0

The concept of one A record to many IP addresses is called "Round Robin DNS". It has existed for a very long time.

It's not a guaranteed method of evenly distributing your traffic, and there are plenty of other ways to configure DNS for both load balancing or high availability or both, but you sure can't beat round robin for simplicity.

However, as far as I understand resolvers, a client will always pick the NS which responds fastest. Unless you're able to logically or geographically place each NS to be quicker for ~50% of your clients, then one NS will be favoured over the other.

1
  • 2
    Of course, if one server is loaded then it'll respond slower than one that doesn't have any traffic. :-)
    – Nathan C
    May 30, 2013 at 12:25
0

I'd avoid it, as there is no way indicate that a server is up or down, so if 10.0.0.1 is down, that means around 50% of the requests sent to your server will fail the first time, and need to be retried, which will negatively affect anything using DNS. BillThor and suprjami have already pointed out that servers that are more responsive will end up with more traffic, and that could very possibly mean that you need to adjust things manually to balance it out.

Proper load balancing takes into account the state of the machines doing the work, the amount of work they are doing, and can often make transparent changes to adjust the situation without need for your intervention.

2
  • Well even in the default configuration, if ns1 is down they will have to retry with ns2, right ? It's not really different. May 30, 2013 at 13:52
  • Yet another reason to not do it.. it's just another layer that doesn't really do much. If you list 2 name servers, they should already get something resembling half the traffic.
    – NickW
    May 30, 2013 at 13:55
0

There are (basically) two types of DNS traffic a DNS server can receive. Technically it's recursive and non-recursive, but an easier way to think of it is client and other servers. Clients may be looking up anything on the internet, expecting your DNS server to act as a server and find out the information for them. Other servers will only be asking your DNS servers for domains that you are listed as authoritative for.

For other servers, you just need to list multiple NS records for your domain (both in your zone and with the DNS registrar), and other servers on the internet will automatically randomly pick which of your servers to use. They may even prefer the fastest or closest server. Make sure those servers actually have authoritative copies of your zone that are properly replicated from the master, of course. I'm not sure if multiple A records behind the NS records will work, but you'll get what you want simply by listing 4 NS records.

For clients, they don't use DNS to look up which DNS server to use. That wouldn't be possible, since it would introduce a circular dependency (DNS lookups depending on DNS lookups). The client configuration is generally fairly simple, with a (short) list of IPs that are tried in the same sequence for every DNS lookup. The DNS server's domain name is not used by the clients. If you want to load balance DNS for clients, you need to use some kind of real load-balancers. Make sure to load balance both UDP and TCP, as both are required for DNS to function reliably.

0

DNS traffic is already load balanced (and cached). Adding additional A records will increase the load on all nameservers as they will need to provide the additional addresses.

If one of your nameservers is overloaded, but the other isn't look at the server configuration or the network configuration. If one server is unreachable, traffic will move to other causing a load imbalance.

Also check your TTL values to ensure servers can cache your data for a reasonable amount of time. In most cases your data should be cachable for hours or days. Reduce the TTL and take the load if an address is changing.

Also check to make sure your server is not able to be used for DNS amplification. From the Internet it should only respond to queries for which it is authoritative. This could use your bandwidth up quite quickly without providing the intended service.

EDIT: If you want to reduce traffic to your servers, add secondaries on different networks. Several organizations provide secondary DNS services. Traffic gets spread across more servers using round robin scheduling.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .