How to reroute all traffic using hosts file?
Solution 1:
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.
Solution 2:
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.