我的服务器被Baiduspider杀死,无论我放在我的robots.txt文件中什么都没有发生。 所以暂时我需要通过iptables阻止尽可能多的IP地址。 我通过以下方式获取IP地址:
grep -ri Baidu /var/log/apache2/access.log | cut -f1 -d' ' | sort | uniq
我的iptables规则如下所示:
Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp dpt:ftp ACCEPT tcp -- anywhere anywhere tcp dpt:ftp-data ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ACCEPT tcp -- anywhere anywhere tcp dpt:www ACCEPT tcp -- anywhere anywhere tcp dpt:https ACCEPT tcp -- anywhere anywhere tcp dpt:snpp ACCEPT tcp -- anywhere anywhere tcp dpt:mysql LOG all -- anywhere anywhere limit: avg 5/min burst 5 LOG level debug prefix `iptables denied: ' DROP all -- anywhere anywhere
我正计划添加类似于以下内容的新规则:
for ip in $(grep -ri Baidu /var/log/apache2/access.log | cut -f1 -d' ' | sort | uniq); do iptables -A INPUT -s $ip -j DROP; done
但我不认为我可以添加它们。 我认为他们需要插入一个特定的位置。 他们需要插入哪些部分才能生效?
你的第一条规则看起来是允许一切的,使得它下面的所有规则都毫无意义(这是打算?)。
您需要插入上面的规则才能产生任何效果; 把你的-A INPUT改成-I INPUT 。
您也可以考虑在基于用户代理的Apache中阻止它们 – 403响应可能比失败的连接获得更好的消息,并且不需要现在使用的资源来响应这些具有内容的请求。