CentOS 6 Iptables关于--hitcount数值限制的问题
来源:互联网 发布:老虎证券 知乎 编辑:程序博客网 时间:2024/05/21 18:39
一直知道iptables 很强大,但是所知甚少,今天突然想做下iptables 限制连接数的问题,参照iptables man手册 recent 部分,在iptables 文件中写了两条规则,命令行写法如下:
iptables -A INPUT -p tcp --dport 80 -m recent --name badguy --seconds 60 --update --hitcount 100 -j DROP iptables -A INPUT -p tcp --dport 80 -m recent --name badguy --set -j ACCEPT
重启iptables,但是奇妙的事情发生了:
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: iptables-restore: line 17 failed
立刻去查看iptables 文件,发现第17行的内容为 COMMIT!一定是规则有问题,把规则注释掉,再重启,OK了!然后用各种姿势google,无解。查到网友的写法跟我的写法一样一样的,正常工作!WTF的节奏!
继续调整规则,发现把–hitcount 100 去掉后就OK,加上就failed,回头继续看man 手册,关于–hitcount 的描述如下:
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 han 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.
粗体这句解释了问题,然后尝试将–hitcount 调低,调到10正常,20正常,大于20,failed 了,好了,问题就在这了,要突破ip_pkt_list_tot 的默认限制了。
google了下ip_pkt_list_tot,发现在/sys/module/xt_recent/parameters目录下,cat 了下ip_pkt_list_tot的值,还真是20,按照以往情况,直接echo 一个值进入就可以了,但是“白手起家”这位网友说不可,要进入到/etc/modprobe.d/ 目录下新建配置文件:
vim xt_recent.conf
options xt_recent ip_list_tot=1024 ip_pkt_list_tot=200
备注:(原文的文件名中没有.conf,试验后有警告提示:WARNING: All config files need .conf: /etc/modprobe.d/xt_recent, it will be ignored in a future release. 因此正确的写法应该加上.conf)
保存退出,调大–hitcount 的值为200,重启iptables ,OK!
再去cat ip_pkt_list_tot 的值,也变成了200。
搞定,收工!
- CentOS 6 Iptables关于--hitcount数值限制的问题
- CentOS中Iptables关于ping的配置问题
- fedora centos,ubuntu关于进程资源限制的问题
- 解决centos没有iptables的问题
- CentOS保存iptables规则问题
- 关于Untiy中数值传递的问题
- 关于链表中去掉重复数值的问题
- 关于指针所指数值输出的问题
- 解决CentOS(6和7版本),/etc/sysconfig/下没有iptables的问题
- 解决CentOS(6和7版本),/etc/sysconfig/下没有iptables的问题
- 解决CentOS(6和7版本),/etc/sysconfig/下没有iptables的问题
- 解决CentOS(6和7版本),/etc/sysconfig/下没有iptables的问题
- 解决CentOS(6和7版本),/etc/sysconfig/下没有iptables的问题
- 解决CentOS(6和7版本),/etc/sysconfig/下没有iptables的问题
- 解决linux服务器CentOS(6和7版本),/etc/sysconfig/下没有iptables的问题
- 解决CentOS 6.6,/etc/sysconfig/下没有iptables的问题
- CentOS下配置iptables碰到域名解析失败的问题
- 解决CentOS 6.6,/etc/sysconfig/下没有iptables的问题
- Eclipse 编辑注释模板
- 静态代码检查工具PC-Lint(二)
- Java中处理有效字符,截取小数无效字符
- 黑马程序员-Java基础其它对象(System和Runtime)
- Spring定时任务的几种实现
- CentOS 6 Iptables关于--hitcount数值限制的问题
- qt 的ui界面设计师中的布局 控件QWidget中使用的布局
- 数字的颠倒
- 【eclipse】用Eclipse编程时,查看源代码,显示Source not found问题的解决方法。
- 循环体中用“+”拼接字符串-代码典型缺陷分析
- linux运维
- mongodb入门
- python 显示unicode字符问题
- 欢迎使用CSDN-markdown编辑器