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. 树莓派上使用mdk3对无线热点进行DoS攻击

    写在前面 你必须确保你的无线网卡支持监听模式(混淆模式),树莓派板载的无限网卡是不支持的.所以你必须额外安装一个支持监听模式的USB无线网卡. 安装mdk3 安装sudo apt install md ...

  2. A1036. Boys vs Girls

    This time you are asked to tell the difference between the lowest grade of all the male students and ...

  3. ZOJ_3950_How Many Nines 解题报告及如何对程序进行测试修改

    The 17th Zhejiang University Programming Contest Sponsored by TuSimple Solution: #include <stdio. ...

  4. 对程序进行package封装

    一.package包 格式:package 代码必须写在源代码文件的第一句, 约定俗成使用公司域名的倒写,之后再加其他. for example: package cn.chuanzhiboke.te ...

  5. vs2010中使用 git

    在没有使用git之前的,我很苦恼.因为我的代码有时在办公室做,有时也带回家做.做了一些时间,放在哪,要用的时间就不知道家里的还是办公室的是新版本了.甚至出现了旧版本把新版本覆盖的乌龙事情.有了git只 ...

  6. ubuntu14安装node0.12.7

    1. 官网下载linux系统二进制文件, 链接如下: https://nodejs.org/ 2. 解压到/opt/目录 3. 设置node环境变量 export NODE_HOME=/opt/nod ...

  7. IDEA如何自动提示并补全syso和main呢?

    myeclipse使用若干年了,syso和main也被打过无数遍,切换到IDEA开发工具中,一按,天啦,竟然没有自动补全,顿时觉得IDEA弱爆了,经过摸索之后,IDEA终结没有令人失望.可以通过配置L ...

  8. VBScript入门篇

    VBScript入门篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.定义一个过程 定义一个过程:可以将相同的操作的代码提取出来,方便其他人来调用这段代码,可以减少你的代码的重 ...

  9. H5利用canvas实现海报功能

    最近接到一个需求,微信中用户上传图片生成海报.这个需求比较常规,实现思路也比较简单,通过利用用户的input输入,对所上传的图片进行处理,最后通过第三方库html2canvas合成对应的图片即可.思路 ...

  10. CentOS6.8下Jenkins+maven+tomcat+git+shell自动构建、部署web应用环境的搭建

    参考资料:http://www.cnblogs.com/cheng95/p/6542036.html http://www.cnblogs.com/software-test/p/7068278.ht ...