• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1810
  • Last Modified:

Using hosts file for dns and gateway

I know I can use the windows hosts file to resolve dns, but I have 2 gateways on my network and would like to send queries for a certain web site, out a certain gateway. Is this possible with the hosts file or is there another way?
So all http traffic out xxx.xxx.xxx.001
specific-site.com out xxx.xxx.xxx.002
1 Solution
If it is only a webpage you can set the hosts file with the correct domain name and the ip address you want.  

If as I'm understanding it you want to force a particular request down a particular GW you may need to setup a persistent route
something like (not 100% on the mask been /32)

route -p add  specific-site.com-ip mask xxx.xxx.xxx.002.

route print to see the current table.


you can also do this at the network level with static routes on your network equipment. As a rule of thumb, you must have a default gateway which will handle all the traffic unless there is a rule that routes a specific address through a different path.
Depending what your equipment is, you would do this one way or another. For instance if you have Cisco routers, router A and router B. Let's say router A is your default gateway but you want to send traffic to a specific ip address through router b, you can add a static route on router A that says IP route X.X.X.X 255.X.X.X (IP address and mask of website) X.X.X.X ( IP address of router B)
Again is going to depend on your network equipment.
Also keep in mind that some websites have multipla ip addresses and you may not always connect to it using the same IP unless you force it to on you DNS  server or your hosts file.
Depending on how advanced your network is, the network devices (as in the case of Cisco and other routers) can utilize "Routing" protocols, such as RIP, EIGRP, OSPF and learn where different networks are on different interfaces, but this is something that your network department would normally take care of.

One last thing to bear in mind is that even if you put multiple gateways on a Windows XP machine, the machine will only use the first one in the list until its no longer valid, then it will fail over to the next gateway.  While this is how you might want the gateways to function, there is no method for it to fail back to the original gateway should that one become available again.  It will continue to use the current gateway until its no longer valid or the machine is rebooted (or the IP configureation is refreshed, as in an ipconfig /release and renew)
TuscolaCountyAuthor Commented:
Thanks for the replies, I am going to try the route -p add  specific-site.com-ip mask xxx.xxx.xxx.002
this seems to be what we are looking for.

We know we can change and route traffic via the routers but I am looking for an easy way for only a few computers which are on a different subnet than the rest of our network users (200+)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

We Need Your Input!

WatchGuard is currently running a beta program for our new macOS Host Sensor for our Threat Detection and Response service. We're looking for more macOS users to help provide insight and feedback to help us make the product even better. Please sign up for our beta program today!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now