Linux 指令简单将攻击IP列入iptables 限制范围

Feb 23rd, 2008

转载本站文章请注明,转载自:扶凯[http://www.php-oa.com]

本文链接: http://www.php-oa.com/2008/02/23/linuxzhilingjiandanjianggongjiiplieruiptablesxianzhifanwei.html

来自CU的高人.http://php.twomice.net/bbs/viewthread.php?tid=39

netstat -an | grep -v LISTEN | awk ‘{print $5}’ | awk ‘BEGIN { FS=”:” } { Num[$1]++ } END { for(i in Num) if(Num[i]>8) { print i} }’ | xargs -i[] iptables -I INPUT -s [] -j DROP

红色部分为设定值,这条句子会自动将netstat -an 中查到的来自同一IP的超过一定量的连接的列入禁止范围,红色部分为阀值

Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪 ViVi 365Key 网摘 天极网摘 和讯网摘 博拉网 POCO 网摘 饭否 QQ 书签 Digbuzz 我挖网 Mister Wong
  1. 我国著名历史学家
    Mar 5th, 2008 at 22:00
    Reply | Quote | #1

    也用曾经有过类似脚本,在cron中定期运行,然后2小时解封。
    但是剔除了来自baidu爬虫和google爬虫的IP。
    而且封一个C段
    剔除搜索引擎ip之后的数据在ip.txt里保存如下格式的ip地址段:
    211.95.208.0/24
    219.78.190.0/24
    64.7.220.0/24
    68.163.195.0/24

    #!/bin/sh
    IPSRC=`cat ip.txt`
    for i in $IPSRC;do
    /sbin/iptables -A INPUT -s $i -j REJECT
    done

    我这用的是iptables -A
    注意-A和-I的区别,不要让-A …REJECT 在一个更宽泛的ACCEPT之后,否则无效