实验综合拓扑图:
注意事项:防火墙由Red Hat Linux 5.4 版本的机器充当,eth0 使用Host-only (vmware 1),eth1 使用Bridge(本地连接),eth2(vmware 2)
前期工作:
iptables 仅能过滤网络层的内容,例如协议、端口等等
如果想要过滤应用层的,需要打上七层协议的补丁包!还需内核支持!
操作步骤如下:
一、重新编译内核
1、合并kernel+layer7补丁
[root@gjp99 ~]# ll
total 48336
-rw------- 1 root root 960 Aug 2 21:30 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 Aug 2 21:41 Desktop
-rw-r--r-- 1 root root 35556 Aug 2 21:30 install.log
-rw-r--r-- 1 root root 4062 Aug 2 21:30 install.log.syslog
-rw-r--r-- 1 root root 435891 Aug 3 13:55 iptables-1.4.2.tar.bz2
-rw-r--r-- 1 root root 128196 Aug 3 13:55 l7-protocols-2008-10-04.tar.gz
-rw-r--r-- 1 root root 48622017 Aug 3 13:55 linux-2.6.25.19.tar.bz2
-rw-r--r-- 1 root root 174790 Aug 3 13:55 netfilter-layer7-v2.20.tar.gz
[root@gjp99 ~]# cd /usr/src/
[root@gjp99 src]# ll
total 24
drwxr-xr-x 3 root root 4096 Aug 2 21:25 kernels
drwxrwxr-x 21 root root 4096 Oct 23 2008 linux-2.6.25.19
drwxr-xr-x 4 1000 1000 4096 Aug 22 2008 netfilter-layer7-v2.20
drwxr-xr-x 7 root root 4096 Aug 2 21:27 redhat
[root@gjp99 src]# cd linux-2.6.25.19/
[root@gjp99 linux-2.6.25.19]# patch -p1 < /usr/src/netfilter-layer7-v2.20/kernel-2.6.25-layer7-2.20.patch
patching file net/netfilter/Kconfig
patching file net/netfilter/Makefile
patching file net/netfilter/xt_layer7.c
patching file net/netfilter/regexp/regexp.c
patching file net/netfilter/regexp/regexp.h
patching file net/netfilter/regexp/regmagic.h
patching file net/netfilter/regexp/regsub.c
patching file net/netfilter/nf_conntrack_core.c
Hunk #1 succeeded at 208 (offset -2 lines).
patching file net/netfilter/nf_conntrack_standalone.c
patching file include/net/netfilter/nf_conntrack.h
patching file include/linux/netfilter/xt_layer7.h
2、配置新内核
shell> cp /boot/config-2.6.18-8.el5 .config //偷个懒,沿用旧的内核配置
shell> make menuconfig
//配置内核时,在“Networking ---> Networking Options ---> Network Packet filtering framework (Netfilter) ”处主要注意两个地方:
1) Code Netfilter Configuration
//将“Netfilter connection tracking suport (NEW)”选择编译为模块(M),网站空间,需选取此项才能看到layer7支持的配置。
//将layer7、string、state、time、IPsec、iprange、connlimit……等编译成模块,根据需要看着办。
2) IP: Netfilter Configuration
//将“IPv4 connection tracking support (require for NAT)”编译成模块。
//将“Full NAT”下的“MASQUERADE target support”和“REDIRECT target support”编译成模块。
3、编译及安装模块、新内核
shell> make && make modules_install && make install
//编译安装成后后,香港服务器,重启选择使用新的内核(2.6.25.19)引导系统
注意这里的ftp 要选上
二、重新编译iptables
1、卸载现有iptables
[root@gjp99 ~]# rpm -e iptables --nodeps
[root@gjp99 ~]# tar jxvf iptables-1.4.2.tar.bz2 -C /usr/src/
2、合并iptables+layer7补丁
[root@gjp99 ~]# cd /usr/src/netfilter-layer7-v2.20/iptables-1.4.1.1-for-kernel-2.6.20forward/
[root@gjp99 iptables-1.4.1.1-for-kernel-2.6.20forward]# ls
libxt_layer7.c libxt_layer7.man
[root@gjp99 iptables-1.4.1.1-for-kernel-2.6.20forward]# cp libxt_layer7.c libxt_layer7.man /usr/src/iptables-1.4.2/extensions/
3、编译安装
[root@gjp99 iptables-1.4.1.1-for-kernel-2.6.20forward]# cd /usr/src/iptables-1.4.2/
[root@gjp99 iptables-1.4.2]# ./configure --prefix=/ --with-ksource=/usr/src/linux-2.6.25.19
[root@gjp99 iptables-1.4.2]# make && make install
4、安装l7-protocols模式包
[root@gjp99 ~]# tar zxvf l7-protocols-2008-10-04.tar.gz -C /etc/
[root@gjp99 ~]# mv /etc/l7-protocols-2008-10-04/ /etc/l7-protocols
5. 加载ftp模块
[root@gjp99 iptables-1.4.2]# modprobe ip_nat_ftp
[root@gjp99 iptables-1.4.2]# lsmod
Module Size Used by
ip_nat_ftp 7361 0
案例配置
拓扑图:
公司有三个部门
工程部门 192.168.2.10--20
软件部门 192.168.2.21--30
经理办 192.168.2.31--40
上班时间 (周一---周五 08:20:00)
工程部门 : 上班时间ftp 不允许http qq 迅雷 下班后无限制