How To Set Up A Linux Layer 7 Packet Classifier On CentOS 5.1

Introduction

This tutorial will walk you through setting up a Linux layer 7 packet classifier on CentOS 5.1, this can easily be adapted to any other Linux distribution out there.

L7-filter is a classifier for the Linux Netfilter that identifies packets based on patterns in application layer data. This allows correct classification of P2P traffics.
It can classify packets such as Kazaa, HTTP, Jabber, Citrix, Bittorrent, FTP, Gnucleus, eDonkey2000, etc., that uses unpredictable ports as well as standard protocols running on non-standard ports. It complements existing classifiers that match on IP address, port numbers and so on. http://l7-filter.sourceforge.net/

 

1) Download required packages

1.1) Download L7-filter kernel

wget http://downloads.sourceforge.net/l7-filter/netfilter-layer7-v2.19.tar.gz

 

1.2) Download L7-filter userspace

wget http://downloads.sourceforge.net/l7-filter/l7-filter-userspace-0.7.tar.gz

 

1.3) Download L7-filter Protocol definitions

wget http://downloads.sourceforge.net/l7-filter/l7-protocols-2008-04-23.tar.gz

Important Note: Always download the latest version of L7-filter from http://sourceforge.net/project/showfiles.php?group_id=80085

 

1.4) Download Linux Iptables 1.4.0

wget http://www.netfilter.org/projects/iptables/files/iptables-1.4.0.tar.bz2

 

1.5) Download Linux Kernel 2.6.26

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.26.tar.bz2

 

2) Install L7-filter

Open a terminal and do

tar -xvf linux-2.6.26.tar.bz2

tar -xvf netfilter-layer7-v2.19.tar.gz

 

2.1) Apply patch to Linux kernel source

cd linux-2.6.26
patch -p1 < ../netfilter-layer7-v2.19/kernel-2.6.25-layer7-2.19.patch

 

2.2) Apply patch & install iptables 1.4.0

tar -xvf iptables-1.4.0.tar.bz2
cd iptables-1.4.0
patch -p1 < ../netfilter-layer7-v2.19/iptables-1.4-for-kernel-2.6.20forward-layer7-2.19.patch
chmod +x extensions/.layer7-test
make KERNEL_DIR=~/linux-2.6.26
make install KERNEL_DIR=~/linux-2.6.26

 

3) Installing protocol definitions

tar -xvf l7-protocols-2008-04-23.tar.gz
cd l7-protocols-2008-04-23
mkdir /etc/l7-protocols
cp protocols/* /etc/l7-protocols

 

4) Compiling & installing new linux kernel

cd linux-2.6.26
make menuconfig
make all
make modules_install
make install

Important Note:- You must enable the following options (these are correct for Linux 2.6.26, but they tend to move around a lot, so you may have to go hunting if you have a different kernel version):

* "Network packet filtering framework(Netfilter)" (Networking ? Networking option)
* "Netfilter connection tracking support" (... ? Network packet filtering framework(Netfilter) ? Core Netfilter Configuration)
* "Connection tracking flow accounting" (on the same screen)
* Finally, "Layer 7 match support"
* Optional but highly recommended: Lots of other Netfilter options, notably "FTP support" and other matches. If you don't know what you're doing, go ahead and enable all of them.

 

5) Check GRUB setting

vim /etc/grub.conf

It must look like this:

default=0
timeout=3
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.26)
        root (hd0,0)
        kernel /vmlinuz-2.6.26 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
        initrd /initrd-2.6.26.img
title CentOS (2.6.18-53.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-53.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
        initrd /initrd-2.6.18-53.el5.img

 

6) Finally

Well we are done, restart the system and enjoy.

restart

 

7) Test l7-filter

iptables -m layer7 --help

Have fun!

Share this page:

Suggested articles

8 Comment(s)

Add comment

Comments

By: roka

i get this error when i try to following this toturial after i patch the iptables and write "mak"

plz any one can help me for this problem

 

libipt_layer7.c: In function ?help?:
libipt_layer7.c:41: error: ?IPTABLES_VERSION? undeclared (first use in this function)
libipt_layer7.c:41: error: (Each undeclared identifier is reported only once
libipt_layer7.c:41: error: for each function it appears in.)
libipt_layer7.c: At top level:
libipt_layer7.c:53: warning: no previous prototype for ?parse_protocol_file?
libipt_layer7.c: In function ?parse_protocol_file?:
libipt_layer7.c:55: warning: declaration of ?line? shadows a global declaration
../include/iptables.h:15: warning: shadowed declaration is here
libipt_layer7.c: In function ?pre_process?:
libipt_layer7.c:152: warning: declaration of ?rindex? shadows a global declaration
/usr/include/string.h:308: warning: shadowed declaration is here
libipt_layer7.c: At top level:
libipt_layer7.c:206: warning: no previous prototype for ?readl7dir?
libipt_layer7.c:377: error: variable ?layer7? has initializer but incomplete type
libipt_layer7.c:378: error: unknown field ?name? specified in initializer
libipt_layer7.c:378: warning: excess elements in struct initializer
libipt_layer7.c:378: warning: (near initialization for ?layer7?)
libipt_layer7.c:379: error: unknown field ?version? specified in initializer
libipt_layer7.c:379: error: ?IPTABLES_VERSION? undeclared here (not in a function)
libipt_layer7.c:379: warning: excess elements in struct initializer
libipt_layer7.c:379: warning: (near initialization for ?layer7?)
libipt_layer7.c:380: error: unknown field ?size? specified in initializer
libipt_layer7.c:380: warning: excess elements in struct initializer
libipt_layer7.c:380: warning: (near initialization for ?layer7?)
libipt_layer7.c:381: error: unknown field ?userspacesize? specified in initializer
libipt_layer7.c:381: warning: excess elements in struct initializer
libipt_layer7.c:381: warning: (near initialization for ?layer7?)
libipt_layer7.c:382: error: unknown field ?help? specified in initializer
libipt_layer7.c:382: warning: excess elements in struct initializer
libipt_layer7.c:382: warning: (near initialization for ?layer7?)
libipt_layer7.c:383: error: unknown field ?parse? specified in initializer
libipt_layer7.c:383: warning: excess elements in struct initializer
libipt_layer7.c:383: warning: (near initialization for ?layer7?)
libipt_layer7.c:384: error: unknown field ?final_check? specified in initializer
libipt_layer7.c:384: warning: excess elements in struct initializer
libipt_layer7.c:384: warning: (near initialization for ?layer7?)
libipt_layer7.c:385: error: unknown field ?print? specified in initializer
libipt_layer7.c:385: warning: excess elements in struct initializer
libipt_layer7.c:385: warning: (near initialization for ?layer7?)
libipt_layer7.c:386: error: unknown field ?save? specified in initializer
libipt_layer7.c:386: warning: excess elements in struct initializer
libipt_layer7.c:386: warning: (near initialization for ?layer7?)
libipt_layer7.c:387: error: unknown field ?extra_opts? specified in initializer
libipt_layer7.c:388: warning: excess elements in struct initializer
libipt_layer7.c:388: warning: (near initialization for ?layer7?)
libipt_layer7.c: In function ?libipt_layer7_init?:
libipt_layer7.c:392: warning: implicit declaration of function ?register_match?
make[2]: *** [libipt_layer7.oo] Error 1
make[2]: Leaving directory `/usr/src/iptables-1.4.1.1/extensions'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/usr/src/iptables-1.4.1.1'
make: *** [all] Error 2

By: CamiloJaraba

try to follow my tutorial here in HowtoForge.

CentOS 5.3 + kernel 2.6.28.10 + iptables 1.4.4 + Netfilter 2.22

 Blessings

By: Arnat

My steps are not successful, then I want to do the correct way.
Thank you.


By: Arnat

My steps are not successful, then I want to do the correct way.
Thank you.


By: eri

so this tutorial doesnot work ?

By: Denny

i cant find Layer 7 Debugging output on make menu config, how to solve it?

By: denny

do it

yum install gcc, yum groupinstall "Development Tools" , yum install ncurses-devel , yum install qt-devel , yum install hmaccalc zlib-devel binutils-devel elfutils-libelf-devel

By: Denny

its cool, your tutorial work on me, now, how to make some rule?