112

For example, when we connect to www.example.com, at first we try to connect to 192.0.2.1. And if first try fails, then we try 192.0.2.222.

Is it possible? Can we register multiple backup IP addresses for one domain name?

Patrick Mevzek
  • 10,995
  • 16
  • 38
  • 54
firia2000
  • 1,773
  • 5
  • 19
  • 20
  • It will not _exactly_ work this way (with Round-Robin). If you query the host multiple times, it will give you back different IP-s every time you do the query and not just when a host fails. – karatedog Apr 21 '12 at 10:29
  • @karatedog, I was assuming that socket connection will try to connect to next IP if it cannot connect to first one – Akash Kava Oct 19 '12 at 18:28
  • 7
    @AkashKava: A single _connection_ has multiple internal steps. Simplified: an application queries the DNS and gets an IP address. Then it connects to that IP address. If that connection fails, the application won't go back to the first step and query the DNS again, only if coded explicitly to do this. And querying a DNS server multiple time does not necessarily gives you different IP address. So in short, stock DNS cannot be used for load-balancing purposes. – karatedog Sep 12 '15 at 08:52
  • can we use this technique to scale multiple load balancers? – Vikas Verma Jul 12 '20 at 07:50

3 Answers3

85

This is round robin DNS. This is a quite simple solution for load balancing. Usually DNS servers rotate/shuffle the DNS records for each incoming DNS request. Unfortunately it's not a real solution for fail-over. If one of the servers fail, some visitors will still be directed to this failed server.

Jens Bradler
  • 1,407
  • 12
  • 11
  • 3
    It depends on your expectations regarding recovery time. If the provided service can be down for some seconds or minutes you can update the DNS accordingly (e.g. take out IPs of failed systems). If this is not acceptable DNS cannot help you and you have to use load balancers and a high availability network structure. – Jens Bradler Apr 02 '14 at 07:46
  • Do you know how client choose its ip from the list? Is is a random selection or should the client choose the first of the list? Because in the first case the round/robin is not very useful. – Tobia Dec 13 '18 at 07:47
  • 1
    It's the job of the DNS server to shuffle or rotate the records. Most clients will use only the first record. For example Bind9 can be configured to apply different orderings to this type of record set: https://bind.isc.org/doc/arm/9.13/Bv9ARM.ch05.html#rrset_ordering – Jens Bradler Dec 14 '18 at 08:51
  • can we use this technique to scale multiple load balancers? – Vikas Verma Jul 12 '20 at 07:49
60

You can do it. That is what big guys do as well.

First query:

» host google.com 
google.com has address 74.125.232.230
google.com has address 74.125.232.231
google.com has address 74.125.232.232
google.com has address 74.125.232.233
google.com has address 74.125.232.238
google.com has address 74.125.232.224
google.com has address 74.125.232.225
google.com has address 74.125.232.226
google.com has address 74.125.232.227
google.com has address 74.125.232.228
google.com has address 74.125.232.229

Next query:

» host google.com
google.com has address 74.125.232.224
google.com has address 74.125.232.225
google.com has address 74.125.232.226
google.com has address 74.125.232.227
google.com has address 74.125.232.228
google.com has address 74.125.232.229
google.com has address 74.125.232.230
google.com has address 74.125.232.231
google.com has address 74.125.232.232
google.com has address 74.125.232.233
google.com has address 74.125.232.238

As you see, the list of IPs rotated around, but the relative order between two IPs stayed the same.

Update: I see several comments bragging about how DNS round-robin is not convenient for fail-over, so here is the summary: DNS is not for fail-over. So it is obviously not good for fail-over. It was never designed to be a solution for fail-over.

karatedog
  • 2,508
  • 19
  • 29
  • 1
    Do we have to enable something for this Round Robin to work or it is done automatically by every DNS Server? I have one linux and one MS DNS. – Akash Kava Oct 19 '12 at 18:35
  • 3
    Why would google do this if it doesn't cover failover? – Joseph Persico Jan 14 '16 at 00:44
  • 16
    @JosephPersie: because DNS is not used for fail over. By giving mulitple IPs to the same domain name the incoming requests are simply split among the servers that listen on those IP addresses. Think of it as a first level load-balancing, without backend health check. You don't need this, if you don't have thousands of servers :-) – karatedog Jan 14 '16 at 13:09
  • what happens when load balancer is down and request is forwarded to the same balancer ? – Jitendra Vispute Apr 04 '19 at 03:45
  • 1
    @JitendraVispute:DNS does not know about the service behind the IP address it returns. In short, if there is a broken server or a broken service behind an IP address that was just returned by the DNS server, then the request to that IP will fail. – karatedog Sep 12 '19 at 07:35
  • can we use this technique to scale multiple load balancers? – Vikas Verma Jul 12 '20 at 07:49
  • @VikasVerma: Definitely. As load-balancers (I assume TCP) are high-availability in nature, they will handle each others failure. So a "blind", round-robin distribution of incoming requests will scale well. (The above is an assumption. If you throw *single* loadbalancers behind every *single* IP address, and they don't crosscheck each other then nothing will handle their failure. In this case you will have an IP address, with a downed load-balancer behind it, and every incoming request to that IP address will fail, as I've written in the answer). – karatedog Jul 17 '20 at 15:27
4

Yes this is possible, however not convenient as Jens said. Using Next generation load balancers like Alteon, which Uses a proprietary protocol called DSSP(Distributed site state Protocol) which performs regular site checks to make sure that the service is available both Locally or Globally i.e different geographical areas. You need to however in your Master DNS to delegate the URL or Service to the device by configuring it as an Authoritative Name Server for that IP or Service. By doing this, the device answers DNS queries where it will resolve the IP that has a service by Round-Robin or is not congested according to how you have chosen from several metrics.

Ezra A.Mosomi
  • 511
  • 5
  • 4
  • 1
    This sounds like more of advertisement than anything, and load balancers are not stellar performers in the DNS world (in the respect of the specification). And to be precise: "in your Master DNS to delegate the URL or Service" there is no concept of URL or service in nameservers/DNS, when you delegate you delegate a zone (domain) to othernameservers. "as an Authoritative Name Server for that IP or Service." consequently nameservers are authoritative for zones/domains not for IP addresses or services. – Patrick Mevzek Aug 09 '18 at 20:38
  • From the working point of it, they do work, it has been the de facto standard for all the CDN to use the loadbalancers to hand this effectively as they can combine advanced features like GEO-LOCATION to give IP addresses that are even near your or for the server that is highly responsive among others metrics. – Ezra A.Mosomi Aug 13 '18 at 06:53
  • 1
    And they do introduce many problems as the same time. No silver bullet, everything has features and drawbacks. Any nameserver can do geo-location and reply with different IP based on client, no need of load balancers for that. There is even a standard that helps: EDNS Client Subnet. – Patrick Mevzek Aug 13 '18 at 07:07