Windows – Mapping one IP address to another in the ‘hosts’ file

hosts-fileip addresswindows 7

The hosts file (%SystemRoot%\system32\drivers\etc\hosts) lets you make google.com point to, for example, 127.0.0.1 on your local machine, but what if I wanted to make, say, 192.168.1.5 point to 127.0.0.1 on my local machine? Is there a way to do that? Can that be done in the hosts file on Windows 7?

Best Answer

You can't use the hosts file for this.
This maps only names on IP addresses.

I haven't tried this myself, but I would guess that you can abuse the route command for this:

route add 192.168.1.5 127.0.0.1

This instructs the IP stack to route all traffic for 192.168.1.5 to the gateway at 127.0.0.1. Of course there is no gateway there so this only serves to blackhole traffic. You can't do anything useful with the traffic.

Related Question