How to block IP Address via Windows Host

I want to block access to a certain ip address via windows host.

This is the ip address 41.190.8.17. And this is the content of my host file.

# localhost name resolution is handle within DNS itself.

127.0.0.1 41.190.8.17

If I go to my browser and input 41.190.8.17, it takes me directly to the site.

Please can someone tell me why it is ignoring this?


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.


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.