IPTables – 规则不起作用

我正在研究一些新的规则,但我似乎无法让他们目前的工作,我不断得到的错误是iptables: Applying firewall rules: iptables-restore: line 36 failed ,这是COMMIT

我确实移动COMMIT,看看我是否可以缩小这个问题,我认为它可以在-A LIMIT_INDIVIDUAL_CURRENT -m recent --update --seconds 300 --hitcount 200 -j DROP是否有任何人有一个想法。

 *filter :INPUT DROP [13:672] :FORWARD DROP [0:0] :OUTPUT ACCEPT [1604:100070] :LIMIT_INDIVIDUAL_NEW - [0:0] :LIMIT_INDIVIDUAL_CURRENT - [0:0] :LIMIT_OVERALL_NEW - [0:0] -A INPUT -i lo -j ACCEPT #Apache -A INPUT -p tcp --dport 80 -m state --state RELATED,ESTABLISHED -j LIMIT_INDIVIDUAL_CURRENT -A INPUT -p tcp --dport 80 --syn -m state --state NEW -j LIMIT_INDIVIDUAL_NEW #Teamspeak -A INPUT -p tcp --dport 30033 -m state --state RELATED,ESTABLISHED -j LIMIT_INDIVIDUAL_CURRENT -A INPUT -p tcp --dport 30033 --syn -m state --state NEW -j LIMIT_INDIVIDUAL_NEW -A INPUT -p tcp --dport 10011 -m state --state RELATED,ESTABLISHED -j LIMIT_INDIVIDUAL_CURRENT -A INPUT -p tcp --dport 10011 --syn -m state --state NEW -j LIMIT_INDIVIDUAL_NEW -A INPUT -p udp --dport 9987 -j ACCEPT #Iptables DoS and Slowloris mitigation -A LIMIT_INDIVIDUAL_CURRENT -m recent --set -A LIMIT_INDIVIDUAL_CURRENT -p tcp --tcp-flags FIN FIN -m recent --remove -A LIMIT_INDIVIDUAL_CURRENT -m recent --update --seconds 300 --hitcount 200 -j DROP -A LIMIT_INDIVIDUAL_CURRENT -j ACCEPT -A LIMIT_INDIVIDUAL_NEW -m recent --set -A LIMIT_INDIVIDUAL_NEW -m recent --update --seconds 1 --hitcount 30 -j DROP -A LIMIT_INDIVIDUAL_NEW -j LIMIT_OVERALL_NEW -A LIMIT_OVERALL_NEW -m limit --limit 500/second -j ACCEPT -A LIMIT_OVERALL_NEW -j DROP COMMIT 

我试过了,看起来您的怀疑是正确的:

 [root@risby home]# iptables -A FOO -m recent --update --seconds 300 --hitcount 200 -j DROP iptables: Invalid argument. Run `dmesg' for more information. [root@risby home]# dmesg|tail -1 [1141835.281122] xt_recent: hitcount (200) is larger than packets to be remembered (20) 

man iptables显示如下:

  --hitcount hits This option must be used in conjunction with one of --rcheck or --update. When used, this will narrow the match to only happen when the address is in the list and packets had been received greater than or equal to the given value. This option may be used along with --seconds to create an even narrower match requiring a certain number of hits within a specific time frame. The maximum value for the hitcount parameter is given by the "ip_pkt_list_tot" parameter of the xt_recent kernel module. Exceeding this value on the command line will cause the rule to be rejected. 

所以如果我是你的话,我会尝试下降到20010 。 如果这样会导致问题消失(或者至less离开那条线),那么你已经确定了这个问题。 我在内核模块上运行了一个strings ,并查找了这个参数,并在其中find了以下两个条目:

 parm=ip_pkt_list_tot:number of packets per IP address to remember (max. 255) parmtype=ip_pkt_list_tot:uint 

它告诉我这个参数可以在模块加载的时候被设置为参数,但是不能超过255.这就是我认为即使重新编译自己的内核也没有帮助的那种限制,你必须重写模块使用多个单字节( uint =无符号整数)计数器; 我怀疑这不会被列入议事日程。

希望以上内容能够解决这个问题,并可能进行补救。