Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

In Windows System, there is this file at C:\WINDOWS\system32\drivers\etc\hosts. This file allows us to default a specific IP address to a host name.

The issue now is whether I can set multiple IP addresses to a host name. For example, can I do something like this:

192.168.244.128   gateway.net
192.168.226.129   gateway.net

And expect that the browser can resolve to both of them, see which one will work and thus point at that one?

If not, is there any other way to get the behavior I want?

Note: I am deploying this app in my own local area network, so there is no need for internet.

share|improve this question
add comment

8 Answers 8

up vote 11 down vote accepted

Normally you would not uses hosts to do this, but your DNS. Most DNS will provide what's called a "Round Robin" if you assign multiple A records to the one name in the zone.

What it would do then, is the first request comes through would receive 192.168.244.128, the next would receive 192.168.226.129, so on and so forth. However, by design, your local machine will cache its DNS resolution, and will usually use the same IP address over and over, until it expires (Time To Live, TTL).

share|improve this answer
add comment

I think you are going about this the wrong way. Let me know if I'm making the wrong assumptions here.

Scenario:

  • You have two windows servers running the same web application, probably on IIS.
  • You want your application to be fault tolerant so that if one of the servers fails, your application is still available.
  • You want this fault tolerance to be transparent to the browser, so that users can continue to access the application with the same hostname i.e. gateway.net

What your trying to do is called round-robin DNS (aka poor mans load balancing) , but your trying to do this from the client side. This does not seem to have the desired effect (at least on my Windows XP box) even if i flush the DNS cache. Windows will only resolve to the first IP in the file. Nonetheless round-robin DNS is not fault tolerant, so this won't help you achieve what you want.

Suggested solution:

Hardware load balancer: Some brand names are Alteon, Big-IP, Barracuda. What this does is basically present a single IP for your users to connect to & it forwards the requests to the web servers. If one of the servers becomes unavailable, then it will no longer forward traffic to it. This is the expensive option.

Network Load Balancing Services: This is a Microsoft technology available on windows server, which will give you a single clustered IP. It achieves the same result as a hardware load balancer, but in a different way. All you need to do is configure it.

share|improve this answer
    
ZEN-LB is a really simple and easy load balancer. We've had a lot of success with it and love it because its open source (free.) –  Derrick Boudwin Jan 31 '13 at 17:49
add comment

Yes, you can do this, I've used it to test round-robin DNS scenarios without having to actually enter the hosts in a DNS.

When an application calls gethostbyname, it gets back the full list of IP addresses (possibly in random order - depending on the libraries / OS).

share|improve this answer
add comment

My suggestion is to use an internal DNS server with DNS round-robin and TTL=0. If you update the DNS record (also with automatic ip checking system) when an IP/server is down, you can have an high-availability system.

share|improve this answer
    
This is not a solution for high availability. DNS is not designed for this and should only be used in conjunction with other fail over methods. A lot of resolvers ignore the TTL cache as well, making this method unreliable. –  Mark Henderson Oct 5 '09 at 20:41
add comment

I have done this on a home network where I assign static IPs to both the wired and wireless network interfaces of a laptop, and from another machine's hosts file point a single hostname to both those ip addresses. It seems to work fine.

share|improve this answer
add comment

@ Plamen Dimitrov You'll need a device to handle that kind of balance, possibly a switch that can handle BGP in front of your FW- or use your FW if it's capable. If your Ciscos handle BGP look into implementing that. This way you can have both of your ISPs IP going into the Cisco/or switch and the target servers would have valid IPs of 24-bit public IPs (DIFFERENT FROM THE 2 ISP IPs). At that point (you're using 3 different public IP blocks, the one for your servers MUST BE 24 BIT), you'd need to have each of your ISPs know about this solution and they'd have to be willing to support the BGP solution between them, which most will do. Now, when your FQDN resolves, it will resolve to your 24 bit block of IPs, even if 1 ISP lines goes down. The goal is, your 24-bit addresses will always be available due to your ISPs agreeing to route that 24bit address through their lines. This works for VPN too since all you're using for VPN are the 24bit addresses, not either of the IPs from the ISP that you plugged into your cisco/or switch. At that point you have to be wary of BGP FLAPPING where if your lines go up and down a lot, due to a line getting DOS, the DNS addresses will change so much, on the internet, that the DNS servers will AUTOMATICALLY REMOVE THE IPs THAT LEAD TO YOUR 24 BIT BLOCK OF IPs. That's a DOS attack on BGP solutions.

share|improve this answer
add comment

From http://www.unc.edu/atn/lsf/docs/7.0.5/lsf_config_ref/index.htm?hosts.5.html~main

IPv4 Example

192.168.1.1 hostA hostB 192.168.2.2 hostA hostC host-C

In this example, hostA has 2 IP addresses and 3 aliases. The alias hostB specifies the first address, and the aliases hostC and host-C specify the second address. LSF uses the official host name, hostA, to identify that both IP addresses belong to the same host.

share|improve this answer
    
"The format of LSF_CONFDIR/hosts is similar to the format of the /etc/hosts file on UNIX machines." I.e.: the source is not about regular hosts files. –  gertvdijk Jan 27 '13 at 0:57
add comment

You can't do this with the hosts file.

You can't do this with DNS either: you can serve multiple IPs for a single name, but the browser will pick just one of those multiple IPs, try it, and if this host is currently down, the browser will display a connection error.

One possible solution is to set up a proxy server and configure these two IPs as the parents for the domain they serve. At least in the case of Squid, the proxy will try one server and, if it fails, try the second server. Then configure your browser to use this proxy server.

share|improve this answer
    
Not true about round robin: www-archive.mozilla.org/docs/netlib/dns.html Note that the likes of google return multiple DNS records. Despite RFC3484 reordering, it obviously helps to return multiple IPs as a failover strategy. –  BrianEss Oct 7 '09 at 21:56
    
yes you can do it with the hosts file –  warren Nov 28 '09 at 7:11
add comment

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.