Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way to redirect all traffic to one IP in the hosts file? If not, how else could i achieve this?

share|improve this question
1  
It's almost certain that you are doing something wrong. What exactly are you trying to achieve? –  jcrawfordor Jun 29 '11 at 22:02
    
Indeed. Rerouting all traffic to a single IP (which IP?) seems quite a strange thing to do without any context. If you are trying to use it as a means of security (eg processing, monitoring, logging, etc.), then you would be better off creating a separate system for use as a gateway. –  Synetech Jun 30 '11 at 0:54
add comment

2 Answers

The hosts file simply acts as a way to overwrite DNS results, based on Fully Qualified Domain Names. There is no wildcard and there is no way to do it using this method... unless you have a many TB big file that lists every domain... But I doubt you want to go down this route (and I am not sure it would even work).

Even considering this, people can still type in IP addresses, and they will reach the target as normal.

If you want to redirect traffic, the best you can do is custom routes.

I warn you that this is very dangerous, but the easiest way is to go to command prompt and type...

route delete *
route add 0.0.0.0 mask 0.0.0.0 x.x.x.x

where x.x.x.x is the ip you want to route traffic to, however, this must be an IP that is reachable within the network

edit---

Another solution, which is a lot better, and I am not sure why I didn't think of this at the time is to simply edit the DNS server of the machine. If you have got local access to edit the routes, you certainly will be able to do this. Simply host a DNS server somewhere that does support wildcards (which a lot do), and point the machine to that.

This is a much safer and better way to redirect traffic. That being said, this will only redirect traffic targeting FQDNs, if you want ALL IP traffic, the route is probably the only route(!) to go down.

share|improve this answer
1  
Nope, unfortunately the HOSTS file does indeed not support wildcards. Sadly that means you can’t use something like *.2o7.net. :-( And like William said, an overly large HOSTS file certainly does cause problems such as pegging the CPU at 100% if you have the DNSCache service running, making SPYBot, HiajackThis, and other apps that process it take forever to work, slowing down Internet access (because the browser/etc. keep reading the whole thing over and over again), and using a lot more memory. –  Synetech Jun 30 '11 at 0:52
    
is it possible to use this approach if the IP I want to route traffic to is not on the local network? I've googled around, but I'm having trouble figuring out what routes I would need to leave intact and what I need to delete in order to make this work. –  QRohlf Aug 28 '11 at 21:32
1  
@QRohlf using this method, you are actually faking/manipulating the routing table, but, your machine will need a route to that outside machine, so, it will not work. You may be able to manually manipulate ARP to forward certain IPs, however, unfortunately, it has been about a year since I last did something like that (Need a new job!) and I would be lying if I said that I remembered exactly.... However, I have another idea and updating answer. –  William Hilsum Aug 28 '11 at 21:39
add comment

Where would you want to reroute traffic through? I've set up a linux router that would act as a DHCP Server and Proxy to filter all traffic based on allowed/disallowed MAC Address lists.

share|improve this answer
1  
You could use that system as a gateway so that all traffic through it can be monitored, processed, logged, etc. –  Synetech Jun 30 '11 at 0:55
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.