Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

If I add multiple A-records for my domain, they are returned in a round robin order by DNS servers.

Example:

1.1.1.1 A example.com
1.1.1.2 A example.com
1.1.1.3 A example.com

But how does web browsers react if the first host (1.1.1.1) is down (unreachable)? do they try the second host (1.1.1.2) or do they return a error message to the user? Are there any difference between the most popular browsers?

If I implement my own application, I can implement so that the second is used in case the first is down, so it's possible. And this would be very helpful to create a fault tolerant website.

share|improve this question

4 Answers 4

up vote 28 down vote accepted

Yes, most browsers from the last 5-10 years will try the other A records if one fails to respond. This is sometimes called "browser retry" or "client retry" apparently. You'll pretty much only find stuff about it in the context of the various browser exploits which this feature enables against sites not using it (see DNS rebinding and DNS pinning, anti-dns pinning, anti-anti-dns pinning, anti-anti-anti-dns pinning, and so on). Kind of a bad reputation, but it does prove it exists.

Pretty much every browser does indeed receive the full list of A records, and does indeed check others if the one it is using fails. You can expect each client to have a 30 second wait when they first try to access a site when a server is down, until it connects to a working address. The browser will then cache which address is working and continue using that one for future requests unless it also fails, then it will have to search through the list again. So 30 second wait on first request, fine thereafter.

But it isn't something you necessarily want to use, it's going to have lots of caveats about browser compatibility, os compatibility, proxy compatibility, cache-control headers are going to have weird effects on whether it remembers which IPs are down or starts having that 30 second wait on every request, people writing custom clients for your site are going to end up using gethostbyname instead of getaddrinfo and not be able to handle the failover, all sorts of potential problems.

You also can't rely on multiple A records to allow for "master" and "slave" servers, because you'll never know which address a browser is going to pick out of the list. They all need to be just as capable of handling visitors if running, because any one might get traffic if it's up. A browser might think your third server out of the list is the most appealing, maybe it looks the closest, and it will choose that one even though all three are still up.

But if you can live with the limitations and have a reasonably simple HTTP system that you can predict the browser interaction with, it will work.

Oh, you'll also have to deal with a lot of people telling you this doesn't exist (since that was true 15 years ago). But you can try telneting to a domain name with several A records, some with dead IPs and some good ones, if you need to prove it (yes, even good old telnet now uses getaddrinfo and handles multiple A records gracefully these days) -- it will print out a nice list of the IPs it's trying until it finally succeeds.

share|improve this answer
3  
Here's a report from the National Bureau of Economic Research which supports Joff's answer. –  Marco Oct 27 '11 at 15:06
1  
Intriguingly, while stackexchange.com points to one IP, Google returns several: $ dig google.com @ns1.google.com ;; ANSWER SECTION: google.com. 300 IN A 74.125.226.6 google.com. 300 IN A 74.125.226.7 google.com. 300 IN A 74.125.226.0 google.com. 300 IN A 74.125.226.4 google.com. 300 IN A 74.125.226.8 google.com. 300 IN A 74.125.226.2 google.com. 300 IN A 74.125.226.1 google.com. 300 IN A 74.125.226.3 google.com. 300 IN A 74.125.226.5 google.com. 300 IN A 74.125.226.14 google.com. 300 IN A 74.125.226.9 –  Louis St-Amour Aug 10 '12 at 19:21
    
Sorry, but I don't think that's how it works. Browsers have nothing to do with resolving IP addresses -- that happens in system software. If you provide multiple A records, you should assume that any given client will receive a random one from the list. –  Jan Steinman Dec 5 '12 at 18:57
1  
This is how it works in contemporary browsers. They all choose to use system calls like getaddrinfo() to get multiple IP addresses and handle failover internally, rather than getting a single IP address from the system. Other commenters and answerers here are part of the "lot of people telling you this doesn't exist" from Joff's last paragraph---I assume they mean well but they are spreading misinformation. –  Robert Tupelo-Schneck Sep 17 '13 at 15:14

This is basic DNS load balancing distribution technique: DNS Round Robin.

This has nothing to do with browser, it depends on the implementation of the resolver , and the local/remote cache of the DNS address.

Changes are that if a server fail, due to caching in the DNS layer your website may be inaccessibile.

See here for a basic explaination: http://en.wikipedia.org/wiki/Round-robin_DNS

share|improve this answer
    
Well, since the browser is the resolver - it depends on the implementation of the browser, as what I know. –  Jonas Mar 19 '11 at 23:31
1  
No, there are the system library that resolve the dns using of course the DNS Nameserver that you setup in the system. The function are part of the standard operating system library. –  keatch Mar 19 '11 at 23:56
    
But both nslookup cnn.com on Windows and host cnn.com on Linux returns a list of IP-addresses, so then it definitely depends on the implementation of the browser. –  Jonas Mar 20 '11 at 0:07
    
They return a list because that is what is resolved from the dns server. The OS determines what IP to use, not the browser. Windows will use whichever resolved first. *ix implementations depend partially on the bundled tcp stack implementation. –  iivel Mar 20 '11 at 1:36
1  
@iivel: No, that is not true. If I write a Java program and resolve a name with InetAddress.getAllByName("example.com") I get a list with all IP-addresses, so I can choose to start a TCP-connection to all of them if I want. And it's the same if you use getaddrinfo() in C. So it's definitely a choice that the developers do and not the Operating System. –  Jonas Mar 20 '11 at 8:30

Here is an interesting page that discuss providing High Availability for your site. It has a section on multiple A records, however the page is quite old. http://www.tenereillo.com/GSLBPageOfShame.htm

share|improve this answer

The OS determines what IP to use, not the browser. Windows will round robin the returned list (in the list passed back from DNS), though will continue to use the same address until DNS is flushed or times out. *ix implementations depend partially on the bundled tcp stack implementation but typically follow a round robin method as well.

share|improve this answer
1  
No, this is wrong. If I write a Java program and resolve a name with InetAddress.getAllByName("example.com") I get a list with all IP-addresses, so I can choose to start a TCP-connection to all of them if I want. And it's the same if you use getaddrinfo() in C. So it's definitely a choice that the developers do and not the Operating System. The DNS-server only decides in what order the list of IP-addresses is returned. –  Jonas Mar 20 '11 at 8:38
    
Ok, so you can manually do whatever you want with the stack - you could even roll your own and forget about winsock all together. However, if you write an app and let the OS do its thing (abstract away) - then the behavior is as noted. You question was specifically about traditional application behavior - not what is possible. Most developers handle using the unresolved name and let the OS do what it does, rather than tightly coupling behaviors together. –  iivel Mar 20 '11 at 13:46
1  
Not sure why the answer was downvoted, but the question is about what browsers do. Currently all browsers let the OS do the resolution (short of some plugins for firefox and chrome). If you'd like details on how to ensure availability should a provider go down - look at load balancers or clustering. –  iivel Mar 20 '11 at 14:11
    
Browsers probably do as you say - let the OS do the DNS lookup, but it return a list with IP-addresses to the Browser. And the question is: What does the most popular browsers do if the first address is unreachable? do they try the second? –  Jonas Mar 20 '11 at 14:38
    
In theory they will (if they are on XP SP2 or greater for IE). I know that FF does, I'm not sure about Chrome. This is a decent breakdown on the mechanism for you. tenereillo.com/BrowserDNSCache.htm If high availabilty is important - I wouldn't leave it to browser behavior though (yes to multiple A records, but no to different systems) –  iivel Mar 20 '11 at 14:51

Your Answer

 
discard

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.