防火墙限制IP连接数connlimit - Safety - 黑小子博客

debian  linux 2.6.18 内核系统IPTABLES内建防火墙软件支持ip_connlimit模块,但是系统内核不支持ip_connlimit模块,需要手工添加ip_connlimit模块支持。才能使用connlimit模块关于IP连接限制的功能。

注意:在安装前先确定系统的内核版本以及IPTABLES版本,我使用的系统信息如下:

 

  另外还有系统编译可能需要如下的安装包支持:

build-essential cpp debhelper dpkg-dev file g++ g++-4.1 gcc gettext gettext-base html2text intltool-debian libmagic1 libselinux1-dev libsepol1-dev libsp1c2 libstdc++6-4.1-dev linuxdoc-tools make patch perl perl-modules po-debconf sgml-base sgml-data sp xml-core

#cd /usr/src

#wget http://ftp.netfilter.org/pub/iptables/iptables-1.3.6.tar.bz2

#wget http://ftp.netfilter.org/pub/patch-o-matic-ng/snapshot/patch-o-matic-ng-20071128.tar.bz2

#wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.tar.bz2

安装connlimit模块

说明:运行过程中会提示你输入内核路径及IPTABLES源码包路径,键入下面路径

注意默认路径为:

编译内核:

之后在出现的界面选择新内核模块connlimit位置如下:

M选中新增模块,之后按ESC保存退出

加载模块

检查模块可用性

说明:如果不报错,就表示OK

#iptables -I INPUT -p tcp --dport 80 -m connlimit --connlimit-above 20 -j REJECT

用来限制单个IP访问80端口连接数只要超过20个就直接拦截

IPTABLES关于connlimit模块说明如下:

   connlimit

       Allows you to restrict the number of parallel TCP connections to a server per client IP address (or address block).

 

       [!] --connlimit-above n

              match if the number of existing tcp connections is (not) above n

 

       --connlimit-mask bits

              group hosts using mask

 

       Examples:

 

       # allow 2 telnet connections per client host

              iptables -A INPUT -p tcp --syn --dport 23 -m connlimit --connlimit-above 2 -j REJECT

 

       # you can also match the other way around:

              iptables -A INPUT -p tcp --syn --dport 23 -m connlimit ! --connlimit-above 2 -j ACCEPT

 

       # limit the nr of parallel http requests to 16 per class C sized network (24 bit netmask)

              iptables -p tcp --syn --dport 80 -m connlimit --connlimit-above 16 --connlimit-mask 24 -j REJECT

 原文地址
 发表于: 2010-01-27,修改于: 2010-01-27 20:01 已浏览5次,有评论0条
郑重声明:资讯 【防火墙限制IP连接数connlimit - Safety - 黑小子博客】由 发布,版权归原作者及其所在单位,其原创性以及文中陈述文字和内容未经(企业库qiyeku.com)证实,请读者仅作参考,并请自行核实相关内容。若本文有侵犯到您的版权, 请你提供相关证明及申请并与我们联系(qiyeku # qq.com)或【在线投诉】,我们审核后将会尽快处理。
—— 相关资讯 ——