Can a host file DNS entry point to multiple Ip addresses?

14,953

Mostly dupe How to add multiple IPv6 address for single host in /etc/hosts? as auto-suggested by Stack.

Can a hostfile entry point to multiple addresses? NO

Can a hostfile have a hostname pointed to multiple addresses? YES

You can have multiple entries for the same name, e.g.:

192.168.99.12 testhost.local
192.168.99.34 testhost.local
192.168.99.56 testhost.local

This has the same effect as multiple A records in DNS for the name; gethostbyname or getaddrinfo for the name will return all the addresses, as an array or linked list respectively.

However, what a client program will do with multiple addresses depends entirely, and wildly, on the client program. Some will choose randomly, or at least maybe-somewhat-randomly, some will always use the first address, some will use the first address unless an error occurs then the second, some may even use several (or all) in parallel. Only if you are pretty lucky will you get a result similar to using an actual load balancer. Although you will avoid having a single-point-of-failure.

Share:
14,953

Related videos on Youtube

Ankit Jindal
Author by

Ankit Jindal

Updated on September 18, 2022

Comments

  • Ankit Jindal
    Ankit Jindal almost 2 years

    Can a host file DNS entry point to multiple Ip addresses ?

    basically i want have to ad servers , but no balancer due to port issues , the solution i think is host file entry ,but can one dns point to multiple ip address ?