I would like to block sites using iptables. How do I go about this, and how do I ensure that the iptables rules are saved?
|
| |||||
feedback
|
|
Blocking sites with iptables rules is a very bad idea, mainly because iptables (as most firewalls) deals with the IP addresses, and relationship between a site and its IP address(es) is rather loose:
So, even though other answers explain how you do it, I urge you to seek some other solution. For example, installing a transparent http proxy will achieve what you need. This transparent HTTP proxy HOWTO is a bit outdated, but it will help you get started. Once you have a transparent proxy, you can add arbitrary rules to it to block specific sites, you don't even need to use the caching feature of squid, if you don't want it. There are other ways to handle site blocking (other firewalls, proxies, etc.), but iptables rules is pretty much one of the worst possible ways to handle it. | |||
|
feedback
|
|
Under gentoo, to save the iptables rules you have added, use
However, you'll also need to make sure that the iptables init script (whose purpose is to reload the rules) is run at boot:
Both commands should be run as root (via sudo if you have it installed) | |||
|
feedback
|
|
ok, Lets say you want to block the IP address 192.168.1.5, just enter this at command prompt in your shell script:
Then you can block outoging IP address 192.168.1.2 from the server with this command:
and it should block that site from ever bothering you again. hope this helps. | |||||||||||
feedback
|
