Centos6.5下系统编译定制iptables防火墙扩展layer7应用层访问控制功能及应用限制

概述:

 

iptables防火墙是工作在网络层,针对TCP/IP数据包实施过滤和限制,属于典型的包过滤防火墙。以基于网络层的数据包过滤机制为主,同时提供少量的传输层、数据链路层的过滤功能。难以判断数据包对应于何种应用程序(如:QQ、迅雷等)安装netfilter-layer7补丁包的作用是为Linux内核、iptables添加相应的补丁文件,重新编译安装后提供基于应用层(第7层)的扩展功能。通过独立的l7-protocols协议包提供对各种应用层协议的特征识别与定义,便于更新

 

 

对内核中的netfilter,打补丁layer7,重新编译内核

对iptables打补丁,补上layer7模块,重新iptables

 

 

 

 

Packages:

iptables-1.4.12.1.tar.bz2

kernel-2.6.32-431.5.1.el6.src.rpm

l7-protocols-2009-05-28.tar.gz

netfilter-layer7-v2.23.tar.gz

 

1、内核打netfilter补丁

tar -zxvf netfilter-layer7-v2.23.tar.gz -C /usr/src/

useradd mockbuild

rpm -ivh kernel-2.6.32-431.5.1.el6.src.rpm

cd /root/rpmbuild/SOURCES/

tar -jxvf 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

cd /usr/src/linux

patch -p1 < /usr/src/netfilter-layer7-v2.23/kernel-2.6.32-layer7-2.23.patch

 

2、内核配置安装

cp /boot/config-2.6.32-431.el6.x86_64 /usr/src/linux/.config

yum -y install ncurses-devel

make menuconfig

 

 

1)取消模块签名认证

选择[*]  Enable loadable module support —> 取消[ ] Module signature verification (EXPERIMENTAL)

选择-*- Cryptographic API  —> 取消[ ] In-kernel signature checker (EXPERIMENTAL)

2)查看IPV4(IPV6)要支持以下功能

-*- Networking support  —>   Networking options  —>  [*] Network packet filtering framework (Netfilter)  —>  IP: Netfilter Configuration  —>   IPv4 connection tracking support (required for NAT)

   Full NAT

     MASQUERADE target support

     NETMAP target support

     REDIRECT target support

-*- Networking support  —>   Networking options  —>  [*] Network packet filtering framework (Netfilter)  —>  IPv6: Netfilter Configuration

3)开启layer7模块

-*- Networking support  —>   Networking options  —>  [*] Network packet filtering framework (Netfilter)  —>  Core Netfilter Configuration

  Netfilter connection tracking support

<  >  “layer7” match support

  “string” match support

  “time”  match support

  “iprange”  match support

  “connlimit”  match support

  “state”  match support

  “conntrack”  connection  match support

  “mac”  address  match support

  “multiport” Multiple port match support

4)给内核起一个命令便于识别

General setup  —>  (-2.6.28.ywnds) Local version – append to kernel release

 

3、内核编译安装

make

make modules_install

make install

 

4、卸载原有的iptables

cp /etc/init.d/iptables ~/iptables

cp /etc/sysconfig/iptables-config ~/iptables-config

 

cp /etc/sysconfig/iptables ~/iptables-rule

rpm -ve iptables-ipv6 iptables --nodeps

reboot

 

5、安装新的iptables

$ tar xvf iptables-1.4.21.tar.bz2 -C /usr/src/

$ cd /usr/src/iptables-1.4.21

 

# 复制layer7头文件和帮助文件到Iptables目录下(使iptbales能够支持layer7)

$ cp /usr/src/netfilter-layer7-v2.23/iptables-1.4.3forward-for-kernel-2.6.20forward/libxt_layer7.* ./extensions/

 

# 编译安装

$ ./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/

 

# 启动服务.

$ ln -sv /usr/sbin/iptables /sbin/iptables

$ chkconfig --add iptables

$ service iptables start

 

6、安装协议特征包l7-protocol-2009

$ tar xvf l7-protocols-2009-05-28.tar.gz -C /usr/src

$ cd /usr/src/l7-protocols-2009-05-28/

$ make install

$ mkdir -p /etc/l7-protocols

$ cp -R * /etc/l7-protocols

$ service iptables restart

$ ls /etc/l7-protocols/protocols/

#此目录下保存的都是7层过滤支持的所有协议

 

1.开启iptables路由转发功能.

$ sysctl -w net.ipv4.ip_forward=1

2.设置SNAT(固定公网IP).

$ iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -j SNAT --to-source 192.168.60.10

3.不允许转发QQ协议.

$ iptables -A FORWARD -s 192.1681.10.0/24 -m layer7 --l7proto qq -j DROP

4.控制QQ可以使用的时间.

$ iptables -A FORWARD -s 192.168.10.0/24 -m layer7 --l7proto qq -m time --timestart 08:00:00 --timestop 12:00:00 -j DROP

 

你可能感兴趣的:(docker)