Chinaunix首页 | 论坛 | 博客
  • 博客访问: 644763
  • 博文数量: 98
  • 博客积分: 3145
  • 博客等级: 中校
  • 技术积分: 1902
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-15 12:52
文章分类
文章存档

2021年(1)

2020年(1)

2016年(8)

2015年(3)

2014年(1)

2013年(5)

2012年(4)

2011年(9)

2010年(12)

2009年(42)

2008年(12)

我的朋友

分类: LINUX

2009-01-12 16:45:49

说明

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

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

 

内核

IPTABLES

LINUX 2.6.18

IPTABLES 1.3.6

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

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 1.3.6.tar.bz2

#wget

#wget 2.6.18.tar.bz2

编译安装

安装connlimit模块

#tar jxvf iptables-1.3.6.tar.bz2 patch-o-matic-ng-20071128.tar.bz2 linux-2.6.18.tar.bz2

#cd patch-o-matic-ng-20071128

#./runme --download

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

内核路径:/usr/src/linux-2.6.18

IPTABLES路径:/usr/src/iptables-1.3.6/

注意默认路径为:

内核路径:/usr/src/linux

IPTABLES路径:/usr/src/iptables

编译内核:

#cd /usr/src/linux-2.6.18

#make menuconfig

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

Networking-à

Networking options à

[*] Network packet filtering (replaces ipchains)  --->

IP: Netfilter Configuration  ---> 

Connections/IP limit match support 

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

#make

#cp /usr/src/linux/net/ipv4/netfilter/ipt_connlimit.ko  /lib/modules/2.6.22-14-server/kernel/net/ipv4/netfilter/

加载模块

#depmod –a

检查模块可用性

# modprobe  ipt_connlimit

说明:如果不报错,就表示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

阅读(1884) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~