Blocking ip range in hosts file?

2

I know how to edit my hosts file on osx, how can I block the range 78.31.8.0/22? What do I put in the hosts file?

John

Posted 2011-12-06T12:04:22.753

Reputation: 21

Answers

3

You cannot.

/etc/hosts is not for blocking – it is for translating domain names to addresses (when other methods are unavailable) – more specifically, an exact name to a single address. If a program tries to access the address directly, the system won't even touch /etc/hosts, because there will be nothing to look up.

Use a proper firewall, such as ipfw.

user1686

Posted 2011-12-06T12:04:22.753

Reputation: 283 655

2

A simple way to null a range of ip is:

route add 78.31.8.0/22 lo

Use the routing table to do it :)

Felix Yan

Posted 2011-12-06T12:04:22.753

Reputation: 261

how can I access the routing table? – John – 2011-12-06T13:22:32.800

You can just try the command I posted if you are using GNU/Linux :) – Felix Yan – 2011-12-06T14:48:10.743