How to block IP Address via Windows Host
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.
Comments
-
Mob almost 2 years
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?
-
Ƭᴇcʜιᴇ007 over 11 years
-
-
Mob over 11 yearsHow about if I want all requests to that IP Address reirected to my localhost?