6

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?

1

2 Answers 2

8

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.

2
  • 1
    How about if I want all requests to that IP Address reirected to my localhost?
    – Mob
    Nov 11, 2012 at 14:45
  • 1
    I think you'll have to set it via the firewall as well. Nov 11, 2012 at 19:26
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .