iptables防火墙扩展之layer7应用层访问控制

概述:

iptables防火墙是工作在网络层,针对TCP/IP数据包实施过滤和限制,属于典型的包过滤防火墙。以基于网络层的数据包过滤机制为主,同时提供少量的传输层、数据链路层的过滤功能。难以判断数据包对应于何种应用程序(如:QQ、迅雷等)安装netfilter-layer7补丁包的作用是为Linux内核、iptables添加相应的补丁文件,重新编译安装后提供基于应用层(第7层)的扩展功能。通过独立的l7-protocols协议包提供对各种应用层协议的特征识别与定义,便于更新





对内核中的netfilter,打补丁layer7,重新编译内核

对iptables打补丁,补上layer7模块,重新iptables



具体步骤

1、获取并编译内核

# useradd mockbuild

# rpm -ivh kernel-2.6.32-431.5.1.el6.src.rpm

# cd rpmbuild/SOURCES

# tar xf linux-2.6.32-431.5.1.el6.tar.bz2 -C /usr/src

# cd /usr/src

# ln -sv linux-2.6.32-431.5.1.el6 linux

2、给内核打补丁

# tar xf netfilter-layer7-v2.23.tar.gz

# cd /usr/src/linux

# patch -p1 < /root/netfilter-layer7-v2.23/kernel-2.6.32-layer7-2.23.patch

# cp /boot/config-2.6.32-431.el6.x86_64 .config





安装依赖包

# yum install -y ncurses-devel

# make menuconfig

选择需要安装的layer7模块

Networking support -> Networking options -> Network packet filtering framework (Netfilter)-> Core Netfilter Configuration -> "layer7" match support

去掉redhat的验证功能,否则无法编译

Enable loadable module support -> Modulesigature verification (EXPERIMENTAL) -> Module signature verification (EXPERIMENTAL)

关闭核心内核的API

Cryptographic API -> In-kernel signature checker (EXPERIMENTAL)

对内核的名称进行标记修改

General setup -> Local version - append to kernel release 改名-layer7

3、编译并安装内核

安装独立的screen编译窗口进行编译

# yum install -y screen





screen命令:

screen:打开一个新的screen

隐藏:Ctrl+a, d

重新打开隐藏的screen:

显示各screen ID: screen -ls

重新打开: # screen -r Screen_ID





制定内核编译

# make -j 4

# make modules_install

# make install

验证内核是否编译成功

# ls /boot





# vim /boot/grub/grub.conf

将默认启动内核改为定制后的内核

4、重启系统,启用新内核

5、编译iptables

# tar xf iptables-1.4.20.tar.bz2

# cd iptables-1.4.20

# cp /root/netfilter-layer7-v2.23/iptables-1.4.3forward-for-kernel-2.6.20forward/libxt_layer7.* extensions/





备份原iptables服务启动文件及配置文件备用

# cp /etc/rc.d/init.d/iptales /root

# cp /etc/sysconfig/iptables-config /root





卸载原有iptables

# rpm -e iptables iptables-ipv6 --nodeps





对iptables进行编译

# cd /root/iptables-1.4.20

# ./configure --prefix=/usr --with-ksource=/usr/src/linux

# make && make install





# cp /root/iptables /etc/rc.d/init.d/

# cp /root/iptables-config /etc/sysconfig/





启动iptables

# service iptables status

编辑vim /etc/rc.d/init.d/iptables

将文件中 /sbin/$IPTABLES 修改为 /usr/sbin/$IPTABLES

将/sbin/$IPTABLES改为/usr/sbin/$IPTABLES

6、为layer7模块提供其所识别的协议的特征码

解压并安装 l7-protocols-2009-05-28.tar.gz

# tar xf l7-protocols-2009-05-28.tar.gz 

# cd l7-protocols-2009-05-28

# make install

7、使用layer7模块

ACCT的功能已经可以在内核参数中按需启用或禁用。此参数需要装载nf_conntrack模块后方能生效。

# vim /etc/sysctl.conf

net.netfilter.nf_conntrack_acct = 1





# modprobe nf_conntrack

使配置生效

# sysctl -p





l7-filter uses the standard iptables extension syntax 

# iptables [specify table & chain] -m layer7 --l7proto [protocol name] -j [action] 









# iptables -A FORWARD -i eth1 -m layer7 --l7proto qq -j REJECT





注意:

网络防火墙:ip_forward

net.netfilter.nf_conntrack_acct参数只有装载nf_conntrack模块后方能生效





8、配置实验环境,对layer7的功能进行测试

充当路由功能的机器

外网接口:

DEVICE=eth0

ONBOOT=yes

BOOTPROTO=none

IPADDR=192.168.8.15

BROADCAST=192.168.8.255

NETMASK=255.255.255.0

GATEWAY=192.168.8.254

NETWORK=192.168.8.0





DNS配置

/etc/resolve.conf

nameserver 192.168.8.251





内网接口:

# cd /etc/sysconfig/network-scripts/

# cp ifcfg-eth0 ifcfg-eth1





DEVICE=eth1

ONBOOT=yes

BOOTPROTO=none

IPADDR=172.16.1.254

BROADCAST=172.16.1.255

NETMASK=255.255.255.0

NETWORK=172.16.1.0





内网的机器:

172.16.1.10

DNS:192.168.8.251

GAWEWAY:172.16.1.254





配置192.168.8.251

# vim /etc/sysctl.conf

打开防火墙转发功能

net.ipv4.ip_forward = 1





sysctl -p 使配置生效





在防火墙上添加规则,对来自内网 172.16.1.0网段的机器进行源地址转换

# iptables -t nat -A POSTROUTING -s 172.16.1.0/24 -j SNAT --to-source 192.168.8.15





通过测试发现可以正常访问网站和QQ





添加限制QQ的规则

# iptables -A FORWARD -m layer7 --l7proto qq -j REJECT





再次登录QQ发现超时,说明layer7的协议限制生效了





添加对http的限制,发现网页也无法正常打开

# iptables -A FORWARD -m layer7 --l7proto http -j REJECT





-j LOG 

--log-prefix "":指定日志前缀信息

注意:如果同样的内容要做过滤,日志规则一定放在过滤规则之前。

centos6.5下系统编译定制iptables防火墙扩展layer7应用层访问控制功能及应用限制QQ2016上网的更多相关文章

  1. 使用iptables防火墙限制web的访问PV

    使用iptables防火墙限制web的访问PV #!/bin/bash while true;do awk '{print $1}' /tmp/test/access.log| grep -v &qu ...

  2. CentOS6.9下手动编译并安装Python3.7.0

    CentOS6.9默认安装的python版本为2.6.6,若想安装python3以上版本,只能手工编译安装 下面介绍Python-3.7.0版本的手动编译并安装的步骤 1.下载Python-3.7.0 ...

  3. centos6.8下搭建编译openwrt的环境

    1. 安装必要软件 su root yum install zlib-devel zlib-static -y 2. 编译openwrt 请参考这里

  4. linux下安装编译php的curl扩展

    curl扩展的位置(需要编译的版本)/root/install/php-5.5.24/ext/curl 1.进入对应的扩展目录 # cd /root/install/php-5.5.24/ext/cu ...

  5. iptables防火墙常用配置介绍

    参考地址 http://www.cnblogs.com/metoy/p/4320813.html http://netfilter.org/ iptables http://man.chinaunix ...

  6. Centos iptables防火墙设置

    iptables的基本语法格式 iptables [-t 表名] 命令选项 [链名] [条件匹配] [-j 目标动作或跳转]说明:表名.链名用于指定iptables命令所操作的表和链,命令选项用于指定 ...

  7. 配置linux-Fedora系统下iptables防火墙

    参考地址:https://blog.csdn.net/zhangjingyi111/article/details/78902820 本篇文章为实验课过程记录,较为简略. 1.查看系统是否安装ipta ...

  8. 编译内核实现iptables防火墙layer7应用层过滤 (三)

    在前面的两篇文章中我们主要讲解了Linux防火墙iptables的原理及配置规则,想博友们也都知道iptables防火墙是工作在网络层,针对TCP/IP数据包实施过滤和限制,属于典型的包过滤防火墙.以 ...

  9. CentOS6.5_64bit下编译安装MySQL-5.6.23

    转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/44785511 ************************************** ...

随机推荐

  1. [bzoj4709][柠檬]

    bzoj4709 思路 首先,最优秀的分法一定是每段两端都是这一段中最多的那个,否则可以把不是的那个踢出去单独成段肯定会更优秀.然后就成了将这个序列分段,保证每段两端元素相同的最大收益和. 用a[i] ...

  2. source insight的使用方法逆天整理

    http://www.cnblogs.com/ningskyer/articles/4038501.html A. why SI: 为什么要用Source Insight呢?因为她比完整的IDE要更快 ...

  3. AS3.0:给图片添加滤镜模糊与斜角效果

    滤镜可应用于任何显示对象(即,从 DisplayObject 类继承的对象), 例如 MovieClip.SimpleButton.TextField 和 Video 对象,以及 BitmapData ...

  4. mysql 删除以某字符串开头的表

    Select 'SET FOREIGN_KEY_CHECKS = 0;'unionSelect CONCAT( 'drop table ', table_name, ';' )FROM informa ...

  5. python写GUI

    图形用户界面 本文利用wxpython wx包中的方法都是以大写的字幕开头 import wx def load(event): file = open(filename.GetValue()) co ...

  6. promise用法详解

    es6的promise可谓是异步书写的一大福音,过去异步js书写是函数嵌套函数的方式,promise出现后书写异步js代码就变得美观得多了 以前的写法:回调函数不停嵌套 ajax('/banners' ...

  7. excel自动化翻译2

    Python爬虫视频教程零基础小白到scrapy爬虫高手-轻松入门 https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.482434a6E ...

  8. php-fpm sock文件权限设置

    在编译php-fpm时,若没有指定fpm用户,在配置文件中也没有指定用户,则sock文件会由root(启动php-fpm的用户)创建,其权限是srw-rw----. 而nginx一般由nginx用户启 ...

  9. weblogic/tomcat Get乱码【转】

    引用自:http://www.cnblogs.com/1995hxt/p/4982835.html  (非常清晰) 其它好文 tomcat和weblogic设置编码方式 tomcat解决方案 在con ...

  10. web.py 模板错误记录

    错误信息 Traceback (most recent call last): File , in process return self.handle() File , in handle retu ...