Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
           IN NS

    ns1    IN A
    ns1    IN A
    ns2    IN A
    ns2    IN A

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.



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.

share|improve this question
Have you considered a UDP load balancer in front of your DNS servers? – pauska May 30 '13 at 14:52
up vote 4 down vote accepted

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 @ NS

;; ANSWER SECTION:        300     IN      NS        300     IN      NS        300     IN      NS        300     IN      NS

;; ANSWER SECTION:        300     IN      NS        300     IN      NS        300     IN      NS        300     IN      NS

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.

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.

share|improve this answer
Thanks for the information, but I don't really understand your last point. and are on the same server ? If that's the case, is it any different than what I wrote ? Because in my example, is one server and is another, so the requests are spread too right ? – Vincent Rischmann May 31 '13 at 12:40
Each IP represents a different server. – jeffatrackaid May 31 '13 at 12:59

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.

share|improve this answer
Of course, if one server is loaded then it'll respond slower than one that doesn't have any traffic. :-) – Nathan C May 30 '13 at 12:25

I'd avoid it, as there is no way indicate that a server is up or down, so if 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.

share|improve this answer
Well even in the default configuration, if ns1 is down they will have to retry with ns2, right ? It's not really different. – Vincent Rischmann May 30 '13 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 '13 at 13:55

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.

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.