6 Answers
6

rr.example.com. A 192.0.2.12
rr.example.com. A 192.0.2.23
rr.example.com. A 192.0.2.34
rr.example.com. A 192.0.2.45

When you query a DNS server for rr.example.com you'll get back a list of IP addresses back. You can then choose to connect to one of them. Should the first attempt to connect get actively refused, just try the next.

Most browser will follow this flow, as long as the endpoints actively refuse TCP connectivity. Should an endpoint timeout, the ressource will be treated as unreachable even though not all IP's has been tried

Since most applications (browsers included) are often only interested in 1 IP endpoint at a time and just choose the first available answer, you risk skewing the load between the target servers so that the first server gets all the traffic while the others might be idle.

To circumvent this, most DNS servers offer what is known as a Round Robin configuration, making the server alternate the order in which equally matching records are returned. Before load balancers were commonplace, this was an efficient way to load balance and somewhat implement fault-tolerance on network systems.

There are two questions. @Sirch already covered the first part pretty good
–
Mathias R. JessenJun 21 '13 at 17:38

Oh, I see, I skipped over the description. Thank you for the answer btw!
–
mowwwalkerJun 21 '13 at 17:49

1

Do browsers/network stacks typically try the first address received? Or will they try a random one? Would it make sense to randomize the order IPs are returned by your DNS server to try to balance the load?
–
Tom MarthenalJun 21 '13 at 19:12

Depends on the specific client implementation. Most servers will randomize the order of returned IP addresses (this is the behavior referred to as "round-robin"). Interesting questions actually, I think I'll expand on the answer a bit
–
Mathias R. JessenJun 21 '13 at 19:20

Yes, it is possible for multiple hostnames to use the same ip address, the best practise is to use a CNAME record to point to the A record

bar.example.com. CNAME foo.example.com.
foo.example.com. A 192.0.2.23

Take note of all the full stops.

Having one hostname to represent multiple ip addresses is a little more complicated. If we are talking about MX records, this solution already exists in DNS using priority numbers, if you want it to represent multiple A records, youd better to use a load balancer, HAProxy for example.

You need to be clear on what you mean by two hostnames. If you mean two physical boxes with the same IP address the answer is typically no. A case where you would is if serverA and serverB are working as an active-passive cluster then you would have each server have two addresses a piece. One would be an ip address dedicated to that server and the second ip address would be one which was shared between the servers but only the active server will be listening to that shared address. The passive server only starts listening in the shared address when the active server goes down.

It is also worth noting that in IPv6 you can assign the same IP to two or more hosts and the network will do the load balancing and failover for you (if one is not reachable, try the other). Both are regarded as one logical endpoint and there is no DNS involved whatsoever.

Yes, it is possible and very common: If a server (with ip A) fall down, you may connect to the next IP of the DNS register and access an another server (with ip B) to get the service.

Multiple Domain for a same IP:

You need to answer the next question: Are all Domain providing the same service?

If yes: it is a very common configuration also: lot of companies buy lot of domain with different country top domain: xxx.com, xxx.net, xxx.org, etc. And all of them point to the same service, that is, to the same list of IP.

If no: It is possible but not common and not recomended. Some hosting companies that only allow HTTP service use NAT/Proxy to spare IP. But of course, that mean a Proxy that "understand" HTTP to identivy the destination service.