L7-filter 安装

L7-filter (Application Layer Packet Classifier for Linux), 是 Linux netfilter 的外挂模块, 它能让 Linux 的 iptables 支持 Layer 7 (Application 应用层) 封包过滤功能, 限制 P2P、实时通讯等使用动态端口口的网络软件.

以下是在 Fedora Core 3 的安装过程:

下载 Layer 7 Patches & Protocol definitions

下载点:

http://sourceforge.net/project/showfiles.php?group_id=80085
(Ref: http://l7-filter.sourceforge.net/HOWTO#Get)

分别下载并解包至 /usr/local/src, 本篇以 l7-protocols-2005-12-16 和 netfilter-layer7-v2.0 为例

先安装 Layer 7 Protocol definitions:

cd /usr/local/src/l7-protocols-2005-12-16
make install

安装 kernel source

依需求选择下载点:

·         http://www.kernel.org/pub/linux/kernel/ (Linux kernel source 官方下载点)

·         ftp://ftp.isu.edu.tw/pub/Linux/Fedora/linux/core/3/SRPMS/ (FC3 原始核心原码下载)

·         ftp://ftp.isu.edu.tw/pub/Linux/Fedora/linux/core/updates/3/SRPMS/ (FC3 新版核心原码下载)

Fedora Core 系列 kernel.src.rpm 操作备忘:

wget ftp://ftp.isu.edu.tw/pub/Linux/Fedora/linux/core/3/SRPMS/kernel-2.6.9-1.667.src.rpm
rpm -ivh kernel-2.6.9-1.667.src.rpm
cd /usr/src
tar -jxf ./redhat/SOURCES/linux-2.6.9.tar.bz2
ln -s linux-2.6.9 linux

重新编译、安装 Layer 7 Patches 更新过的 kernel source

cd /usr/src/linux
patch -p1 < /usr/local/src/netfilter-layer7-v2.0/kernel-2.6.13-2.6.14-layer7-2.0.patch (选用与核心版本对应的 patch 檔)
make oldconfig (如果之前已经有编译过 kernel source, 需先执行 make mrproper)

重点: Layer 7 match support (EXPERIMENTAL)... [N/m/?] (NEW) -> m

(亦可全部按 Enter 接受默认值, 再 make menuconfig 进行调整)

make menuconfig (若需进一步设定 kernel config 才执行; make menuconfig 需求套件: ncurses-devel)

重点 (以 kernel 2.6.13 为例, 不同的核心版本排列方式不一定相同):

Code maturity level options --> [*] Prompt for development and/or incomplete code/drivers

Networking --> Networking options -->
    [*] Network packet filtering (replaces ipchains) -->
        IP: Netfilter Configuration -->
            <M> Connection tracking (required for masq/NAT)
            [*] Connection tracking flow accounting
            <M> IP tables support (required for filtering/masq/NAT)
            <M> Layer 7 match support

make bzImage (kernel 2.4 需先执行 make dep)
make modules
make modules_install
make install

安装 Layer 7 Patches 更新过的 iptables

http://netfilter.org/ 下载 iptables source

解包至 /usr/local/src, 本篇以 iptables-1.3.4 为例

cd /usr/local/src/iptables-1.3.4
patch -p1 < ../netfilter-layer7-v2.0/iptables-layer7-2.0.patch
chmod +x ./extensions/.layer7-test
make KERNEL_DIR=/usr/src/linux
make install KERNEL_DIR=/usr/src/linux

若原本已安装 iptables 套件的处理
cd /sbin
mv iptables iptables.old
ln -s /usr/local/sbin/iptables iptables

chkconfig iptables on
vi /boot/grub/menu.lst (改成预设以新的 kernel 开机)
reboot

使用 iptables layer-7 filter

iptables -t mangle -A PREROUTING -m layer7 --l7proto yahoo -j DROP (禁止 Yahoo! Messenger 封包)

L7-filter 支持的所有通讯协议: L7-filter Supported Protocols

亦可使用 -j MARK 参数搭配 QoS 带宽管理, 详情可参考: cbq.init 设定手札

iptables 封包过滤图: http://linux-ip.net/nf/nfk-traversal.png


后记 1. - make oldconfig 的奥秘

make oldconfig 会比对旧的 kernel config, 带入先前的设定值来产生新的 kernel config, 这样就不用在 make menuconfig 的时候改太多设定. 旧的 kernel config 通常可以在这两个地方找到:

·         /boot/config-2.x.x-x

·         /usr/src/linux/.config (如果这个 kernel source 之前有编译过的话)

后记 2. - Trustix 2.2 安装备忘

以 swup 安装 kernel source 需先修改 swup 配置文件:

vi /etc/swup/swup.conf --> 批注 exclude_pkg_regexp = "kernel.*"
swup --install kernel-source

经前述程序安装完成后, iptables 使用 layer7 参数时会出现错误讯息:

iptables v1.3.4: Couldn't load match `layer7':/usr/local/lib/iptables/libipt_layer7.so: undefined symbol: __guard

任何版本的 iptables 都会出现相同的错误讯息, 目前尚未找出解决办法...


参考数据:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值