DNS – Can Two Hostnames Share the Same IP Address?

domain-name-systemhostnameip

Can anyone explain whether it is possible for two hostnames to share the same IP address?

And what about if one hostname represents more than one IP address, is that possible too? Why?

Best Answer

Assigning more than one IP address to one hostname is also possible:

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.