最近两天,二奶机经常过热关机,毕竟是老机器了,经不起过高的温度。什么原因呢?top一下发现apache占用CPU高达30%。这就诡异了,我的网站啥时候也没有这么高的访问量啊。查了下access_log,居然有无数的IP来访。whois加上Google,原来是一堆的蜘蛛,大部分来自腾讯和搜狗。简直是疯狗,同时放出几十个蜘蛛来爬,这哪受得了!
我的路由器没有防火墙功能,所以只好在二奶机上弄了。还好上次编内核的时候把iptables编进去了,否则我估计这种天气,内核都编不下去就要关机了。折腾了一番,终于搞定。Gentoo对iptables的支持还不错,emerge了之后/etc/init.d里面就有了启动脚本,简单地看了一下也就会用了。现在我的iptables里面是这种状况,列出来给需要的人参考一下(基本上我把IP在中国的都给踢出去了,谁知道它们在找什么):
# iptables -LChain INPUT (policy ACCEPT)target prot opt source destinationall – anywhere anywhereDROP all – 124.115.4.0/24 anywhereDROP all – 124.115.0.0/24 anywhereDROP all – 122.194.170.0/24 anywhereDROP all – 114.80.93.56 anywhereDROP all – 122.81.25.8 anywhereDROP all – 123.125.66.0/24 anywhereDROP all – 218.5.3.149 anywhereDROP all – 220.181.94.222 anywhereChain FORWARD (policy ACCEPT)target prot opt source destinationChain OUTPUT (policy ACCEPT)target prot opt source destination
iptables -A INPUT -s-j DROP </div>