Layer7应用层过滤功能

一.需求描述

重新编译Linux内核,添加l7-filter应用层过滤补丁

重新编译iptables,添加l7-filter应用层过滤补丁

设置过滤规则,禁止使用QQ、MSN等聊天工具

设置过滤规则,禁止使用BT、电驴等下载工具

二.实现思路

重新编译内核

重新编译iptables

使用新的iptables程序设置应用层过滤策略

三.重新编译安装Linux内核

(1)解压释放netfilter-layer和Linux内核源代码包

image

image 

使用patch工具合并补丁包:

image

(2)重新配置内核编译参数,添加state机制及layer7支持:

在Linux内核的配置步骤中,所涉及的配置项相当繁琐,为了减少调试时间及避免给当前的主机系统造成过多影响,这里将直接使用当前RHEL5系统的内核配置文件作为参照,在此基础上添加新的配置内容。内核配置文件将更新到隐藏文件“.config”中。

image

在配置界面中的操作

方向键 áa?à 用于定位功能项、菜单项

菜单项 <Select>、<Exit>、<Help>

空格键用于选择配置类型

对不同功能的配置选择

[ ]:空选时表示不需要在新内核中使用该功能

[ M ]:表示将此项功能编译为模块,以便在需要时加载

[ * ]:将此项功能直接编入新内核,作为新内核的一部分

image

image 

image

image

Code Netfilter Configuration 网络过滤代码配置

image

将“Netfilter connection tracking support”编为模块

image

"layer7" match support

image

"string" match support

image

time” match support

image

“iprange” address range match support

image

“Connlimit” match support

image

“state”match support

image

返回:

image

IP: Netfilter Configuration IP包过滤功能配置

image

将“IPv4 connection tracking support (require for NAT)”功能编为模块

image

将“Full NAT”部分的“MASQUERADE target support”、“REDIRECT target support”等功能也编译为模块

image

image

image

保存退出:

image

编译内核的模块文件、执行程序

执行 make 命令即可

image

安装编译好的模块文件

执行 make modules_install 命令

模块文件将安装到 /lib/modules/2.6.28.8/ 目录

image

安装编译好的内核执行程序

执行 make install 命令

内核执行程序将复制为 /boot/vmlinuz-2.6.28.8

image

查看文件:

image

查看大小:

image

修改grub.conf配置,重启并以新内核进入系统:

image

image

使用新内核启动(2.6.28.8 on an i686)

image

先卸载原有的iptables软件包

可以根据提示的依赖关系卸载相关的各软件包

或者忽略依赖关系卸载几个主要的软件包即可

image

合并补丁,并编译安装新的iptables工具

image

image

image

image

image

解包后直接执行“make install”命令即可

image

image