为iptables安装layer7模块

layer7 是在linux上面的一个防火墙模块,它可以在iptables上面实现七层过滤,能过滤包括电驴,msn,qq等一些列软件,我们知道在Linux上面firewall是基于内核模块实现的,所以我们要想起用layer7模块就必须编译内核,下面是步骤:

1. 需要源码包

The 2.4 or 2.6 Linux kernel source (2.6 strongly preferred)  内核源2.4或者2.6版本码包    The iptables source  iptables源码包    l7-filter kernel version" package  lyer7源码包     "Protocol definitions" package (l7-protocols-YYYY-MM-DD.tar.gz) lyer7规则包2.  编译内核 # tar zxvf linux-2.6.28.10.tar.gz -C /usr/src // 解压内核源码包到/usr/scr# tar zxvf netfilter-layer7-v2.22.tar.gz -C /usr/src//解压layer7源码包到/usr/src# ln –s /usr/src/linux-2.6.28.10/   /usr/src/linux//把内核解压后文件夹连接到/usr/src/linux文件夹# cd /usr/src/linux/ 切换到/usr/srclinux 文件夹# patch -p1 < ../netfilter-layer7-v2.22/kernel-2.6.25-2.6.28-layer7-2.22.patch  //用layer7提供的补丁为内核打补丁#cp /boot/config-2.6.18-164.el5    /usr/src/linux/.config 复制/boot/config-XX 为 .config为蓝本# make menuconfig编译内核在下面选项中启用以下模块Networking support → Networking Options →Network packet filtering framework →Code Netfilter Configurationü      <M> Netfilter connection tracking supportü      <M> “layer7” match supportü      <M> “string” match supportü      <M> “time” match supportü      <M> “iprange” match supportü      <M> “connlimit” match supportü      <M> “state” match supportü      <M> “conntrack” connection match supportü      <M> “mac” address match supportü      <M>   "multiport" Multiple port match supportv      Networking support → Networking Options →Network packet filtering framework → IP: Netfilter Configurationü      <M> IPv4 connection tracking support (required for NAT)ü      <M>   Full NATv      <M>     MASQUERADE target support                                                                                   <M>     NETMAP target support                                                                               <M>     REDIRECT target support 为内核添加支持选项(layer7)#make 开始编译#make modules_install 安装内核模块 安装在/lib/modules/2.6.28.10/#make install 安装新内核编辑grub 把新内核作为默认启动内核 并重启     # cp /etc/rc.d/init.d/iptables ~/iptables复制/etc/rc.d/init.d/iptables 到~/iptables 为了用service iptables 可用# cp /etc/sysconfig/iptables.config /root 备份iptables配置文件      # rpm -e iptables-ipv6 iptables iptstate --nodeps卸载当前系统下的iptables     # tar jxvf iptables-1.4.6.tar.bz2 –C /usr/src解压iptables 源码包到/usr/src     # cd /usr/src/iptables-1.4.6j切换到iptables文件夹内#cp   ../netfilter-layer7-v2.22/iptables-1.4.3forward-for-kernel-2.6.20forward/libxt_layer7.*   ./extensions/ 把layer7中对于iptables的补丁复制到iptables 源码中     ./configure --prefix=/usr --with-ksource=/usr/src/linux配置iptables 默认安装前缀为/usr 内核模块位于 /usr/src/linux下    #make 编译iptables     #make install 安装iptables     # tar zxvf l7-protocols-2009-05-28.tar.gz安装layer7的     # cd l7-protocols-2009-05-28切换到目录      # make install安装layer7规则包      # mv ~/iptables /etc/rc.d/init.d/把此前备份的 ~/iptables 复制回到/etc/rc.d/init.d/目录下# cp /root/iptables.config /etc/sysconfig/iptables.config 复制回iptables配置文件# vim /etc/rc.d/init.d/iptables 编写这个文件 把$iptables的路径改成/usr/sbin/$iptables

如果在防火墙启动的时候报错

Loading additional iptables modules: ip_conntrack_netbios_n[FAILED]

[[email protected] ~]# vi /etc/sysconfig/iptables-config

注释掉
#IPTABLES_MODULES="ip_conntrack_netbios_ns"

6.使用layer7
#iptables -t nat -A POSTROUTING -m layer7 --17proto qq  -j DROP 
或者
# iptables -t mangle -I POSTROUTING -m layer7 --l7proto msnmessenger -j DROP
# iptables -t mangle -I POSTROUTING -m layer7 --l7proto qq -j DROP

查看当前封禁情况:
# iptables -t mangle -L POSTROUTING -v
Chain POSTROUTING (policy ACCEPT 386 packets, 41321 bytes)
 pkts bytes target     prot opt in     out     source               destination        
    0     0 DROP       all  --  any    any     anywhere             anywhere            LAYER7 l7proto aim
    0     0 DROP       all  --  any    any     anywhere             anywhere            LAYER7 l7proto bittorrent

时间: 2024-07-28 16:07:42

为iptables安装layer7模块的相关文章

安装第三方模块

python安装第三方模块 方法1:使用软件管理工具(pip,pip2,pip3) python2和python3都自带了pip,而pip就仿佛有一个仓库,将我们需要安装的第三方模块都收纳其中,使用简 单的安装命令即可完成安装. 注意事项:用python3自带的pip或者pip3安装的第三方模块就只能为python3的编译器使用,这对于python2 的pip和pip2是同理的. 所以在我们需要对某一版本的python安装第三方模块的时候,就将原先的路径删除,增加对应的路径至环境变量. 个人推荐

python3.6 安装 xlrd 模块---Mac

要用Excel将数据和代码分离,需要import xlrd, 使用前需要先安装xlrd模块. 说明:通过在google中搜索"xlrd Mac",下载xlrd.py模块(下载地址:http://mac.softpedia.com/progDownload/xlrd-Download-48230.html),  但是只有0.7.1版本的,可能因为版本比较低,安装之后可以正常import xlrd,但是运行报错有问题,然后我就用了之前在windows上安装的xlrd1.0.0版本,安装成功

关于npm安装全局模块,require时报Error: Cannot find module &#39;XXX&#39;的解决办法

系统环境:centos 下午使用npm安装"cheerio",想搞爬虫玩玩. npm安装有两种模式: 本地 # npm install cheerio 全局 # npm install cheerio -g 如果想要全局安装,你首先要先设置个全局路径 我在"node的安装位置/lib/node_modules/"目录下新建了文件夹node_global专门用来存放新安装的全局包 # npm config set cache "node的安装位置/lib/n

查看npm全局安装的模块

1.查看所有高级的npm moudles npm list --depth=0 2.查看所有全局安装的模块 npm list --depth=0 -global

linux系统上安装paramiko模块

Linux系统上安装paramiko模块要求python要是2.7以上的,所以在安装模块之前应该安装python2.7(这里的安装过程略去) 在安装setuptools的时候突然报错了,RuntimeError:Compression requires the (missing) zlib module原因是因为没有安装zilb和zlib-devel包. yum install zlib yum installzlib-devel 安装完成后,重新编译 python2.7[不需要删除,只需要重新

学习搭建一个小网站_3_安装NodeJS模块_建立express

nodejs安装这些模块: express, express-generator, mongodb, mysql 简单步骤:建立目录 d:\js\BlogWebSite cmd->cd d:->mkdir js->cd js->mkdir BlogWebSite->cd BlogWebSite cmd下首先安装全局模块:( -g 参数是全局安装 ) 1. npm install express -g 2. npm install express-generator -g 在j

iptables之ip_conntrack模块

 ip_conntrack模块: 1,基本概念: -允许的最大跟踪连接条目:CONNTRACK_MAX-存储跟踪连接条目列表的哈西表的大小:HASHSIZE-每个哈西表的条目(叫一个bucket),包含了一个链接起来的跟踪连接条目-哈希表大小HASHSIZE,表现为 条目bucket的多少,在iptables启动时在日志中会显示. kernel 用 ip_conntrack 模块来记录 iptables 网络包的状态,并把每条记录保存到 table 里(这个 table 在内存里,可以通过/pr

nginx安装第三方模块

原已经安装好的nginx,现在需要添加一个未被编译安装的模块 举例说明:安装第三方的ngx_cache_purge模块(用于清除指定URL的缓存) nginx的模块是需要重新编译nginx,而不是像apache一样配置文件引用.so 1.wget http://labs.frickle.com/files/ngx_cache_purge-2.0.tar.gz tar -zxvf ngx_cache_purge-2.0.tar.gz cd /data0/software/nginx-1.1.10

python安装markupsafe模块时卡死的解决办法

起因: 升级OS X从10.8到10.9,会发现在安装python的markupsafe模块时一直卡住. 当时的机器环境是: OSX 10.9, XCode 4.6.2, Python 2.7.6, Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn) 界面一直停留在下面的情况 mbp:MarkupSafe-0.23 $ python setup.py install running install running bdis