How to block IP Address via Windows Host

16,678

Solution 1

It won't work that way, because the hosts file is only being used for name resolution via DNS. Since it is already an IP address, Windows (or your application) doesn't need to do a DNS lookup.

I think you have to block access to the IP address in using the Windows Firewall. Maybe this would help, but it depends on what Windows version you're using.

Solution 2

You cannot block ip addresses via the host file, only domain resolutions! If you want to forward ips to localhost you'll have to make proxy rules, but if you want to just block ip address traffic, I'd use this.

Save this as block.bat

set ip=%1
netsh advfirewall firewall add rule name="BLOCK IP ADDRESS - %ip%" dir=in action=block remoteip=%ip%
netsh advfirewall firewall add rule name="BLOCK IP ADDRESS - %ip%" dir=out action=block remoteip=%ip%

then from an administrative Command line execute block.bat 192.168.0.1 or whatever IP address you want to block This doesn't redirect to 127.0.0.1, just blocks it.

Share:
16,678
Mob
Author by

Mob

Success

Updated on September 18, 2022

Comments