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. luogu P2181 对角线

    题目大意: 给一个n边形,求出在所有任意三条对角线都不相交于同一个点的情况下,交点个数是多少.(即交点个数最多是多少) 分析: 题目很水,但是公式不好想. 由于任意三条对角线不会交于一点,所以所有的交 ...

  2. C++中const关键字的使用方法,烦透了一遍一遍的搜,总结一下,加深印象!!!

    之前一直在学习C/C++,关于const的使用,这里出现一点,那里出现一点.知识用时方恨少,这一段时间正好各种笔试题,其中关于const的用法也是层出不穷,所以疲于在书本上各种翻,这里汇总一下,加深自 ...

  3. poj3070_斐波那契数列(Fibonacci)

    用矩阵求斐波那契数列,快速幂log(n),只用求最后4位(加和乘的运算中前面的位数无用) #include <stdio.h> #include <stdlib.h> int ...

  4. 受限玻尔兹曼机(Restricted Boltzmann Machine,RBM)

    这篇写的主要是翻译网上一篇关于受限玻尔兹曼机的tutorial,看了那篇博文之后感觉算法方面讲的很清楚,自己收获很大,这里写下来作为学习之用. 原文网址为:http://imonad.com/rbm/ ...

  5. kubernetes控制器之DaemonSet

    转载于https://blog.csdn.net/bbwangj/article/details/82867472 什么是 DaemonSet? DaemonSet 确保全部(或者一些)Node 上运 ...

  6. LoadRunner进行参数化的九种方式取值和连接数据库取值

    一.连接mysql数据库取值 1.首先安装odbc驱动 链接: https://pan.baidu.com/s/1WAYd4ygQqIrbB08S01hSkg 提取码: gdfs 2.操作步骤如下图: ...

  7. CPU密集型和I/O密集型区别

    CPU密集型 一些进程绝大多数时间在计算上,称为计算密集型(CPU密集型)computer-bound.一些大量循环的代码(例如:图片处理.视频编码.人工智能等)就是CPU密集型. I/O密集型 有一 ...

  8. Shell标准输出、标准错误

    shell中可能经常能看到:>/dev/null 2>&1 eg:sudo kill -9 ps -elf |grep -v grep|grep $1|awk '{print $4 ...

  9. Windows服务BAT命令-安装、卸载、启动、停止

    1.安装服务 %SystemRoot%\Microsoft.NET\Framework\v4.0.30319\installutil.exe D:\WiseMES\MES.WindowsService ...

  10. ThinkPHP 3.2 用户注册邮箱验证帐号找回密码

    一.前言 当然现在有的网站也有手机短信的方式找回密码,原理就是通过发送验证码来验明正身,和发送邮件验证一样,最终还是要通过重置密码来完成找回密码的流程. 本文将使用PHP+Mysql+jQuery来实 ...