给你的主机防火墙添加l7-filter
生活随笔
收集整理的這篇文章主要介紹了
给你的主机防火墙添加l7-filter
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
給你的主機防火墻添加l7-filter ?? ? linux系統自帶的防火墻也可以起到過濾字符串或特定的報文的共能,但是其過濾能力遠遠有限,不能進行一些常用協議及軟件的過濾,如大家最熟悉的QQ、p2p下載協議等,l7-filter 便為我們的防火墻提供了更加強大的過濾功能,對于過濾常見的軟件或協議來說不僅不費吹灰之力,操作還極其方簡單。 ?? ? 我們先來認識一下l7-filter ?? ? l7-filter即7層過濾器,L7過濾器是一個軟件包,它提供了對Linux的Netfilter的子系統可以基于互聯網協議 ,在他們的數據包的應用層數據進行分類的分類。 這個工具的主要目標是使盡可能的識別點對點等節目,使用不可預知的端口號,正因它是為后來才給linux的Netfilter一個軟件包,所以我們要為linux的內核選擇相對應的l7軟件包,對內核打l7補丁,然后重新編輯內核,開啟相應的模塊功能,因為l7是對iptables的功能提升,也需要對iptables打補丁、重新編譯,最終我們再安裝一個協議包,這個協議包里包含了l7能夠進行過濾的協議即可。 ?? ? ?需要準備的壓縮包: ?? ? ?1、linux-2.6.28.10.tar.gz ? 因l7的版本對內核版本的限制,內核的版本不要過新。 ?? ? ?2、iptables-1.4.6.tar.bz2 ? ?iptables的源碼安裝包 ?? ? ?3、netfilter-layer7-v2.22.tar.gz l7的源碼安裝包 ?? ? ?4、l7-protocols-2009-05-28.tar.gz ?l7的協議包 ? 我們直接開始操作:(說明:只要沒有明確操作目錄,就不必切換目錄) 一、對內核的工作 ?? 1、解壓內核和內核補丁: ?? ? ? ? tar xvf linux-2.6.28.10.tar.gz -C ?/usr/src? ?? ? ? ? tar xvf netfilter-layer7-v2.22.tar.gz -C ?/usr/src/ ?? ? ? ? 進入工作目錄 ?? ? ? ? cd /usr/src/? ?? ? ? ? 創建linux-2.6.28.10的連接linux(關于內核編譯的步驟及原理在我博客中有相關的文章,在此不再重復) ?? ? ? ? ln -sv linux-2.6.28.10 linux ?? ? ? ? cd linux ?? ? 2、給內核打補丁 ?? ? ? ? ?patch -p1 < ../netfilter-layer7-v2.22/kernel-2.6.25-2.6.28-layer7-2.22.patch? ?? ? 3、重新配置、編譯、安裝內核 ? ? ?? ? ? ? ?拷貝一個內核配置的樣本 ?? ? ? ? ?cp /boot/config-2.6.18-164.el5 .config ?? ? ? ? ?make menuconfig? ?? ? ? ? ?根據對內核的配置進行如下修改 ? ? ?? ? ? ? ?進入Networking support ?--->Networking options ?--->Network packet filtering framework (Netfilter) ?---> ?Core Netfilter Configuration進行如下修改 ?? ? ? ? ?<M> Netfilter connection tracking support ?? ? ? ? ?<M> ? "string" match support ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ?<M> ? "time" match support? ?? ? ? ? ?<M> ? "layer7" match support? ?? ? ? ? ?<M>iprange" address range match support ?? ? ? ? ?<M> ? "connlimit" match support ?? ? ? ? ?<M> ? "state" match support ?? ? ? ? ?<M> ? "conntrack" connection tracking match support ?? ? ? ? ?<M> ? "mac" address match support ?? ? ? ? ?<M> ? "multiport" Multiple port match support? ?? ? ? ? ?進行完相應的修改之后則保存退出 ?? ? ? ? ? 編譯、安裝內核 ?? ? ? ? ? make ? ? ? ? ? ? ? ? ? 編譯模塊 ?? ? ? ? ? make modules_install ? 安裝內核模塊 ?? ? ? ? ? make install ? ? ? ? ? 安裝內核 ?? ? 3、測試新編譯的內核 ? ? ? ?? ? ? ? ? 用新編譯的內核重新啟動系統,當系統能正常啟動之后再進行下面的操作,不然將出現錯誤提示。 二、編譯安裝iptables ?? ? 1、備份系統原有的iptables啟動腳本和配置文件 ?? ? ? ? ? cp /etc/init.d/iptabless ~/iptables ?將iptables的啟動腳本備份至家目錄 ?? ? ? ? ? cp /etc/sysconfig/iptables-config ~/ ? ?? ? 2、卸載系統原有的與iptables有關的rpm包 ?? ? ? ? ? rpm -e iptables-ipv6 iptables iptstate --nodeps ?? ? 3、解壓、編譯、安裝iptables-1.4.6.tar.bz2 源碼包 ?? ? ? ? ? tar xvf iptables-1.4.6.tar.bz2 -C /usr/src ?? ? ? ? ? cd /usr/src/iptables-1.4.6 ?? ? ? ? ? cp ../netfilter-layer7-v2.22/iptables-1.4.3forward-for-kernel-2.6.20forward/libx_layer7.* ./extensisons/ ?? ? ? ? ? ./configure --prefix=/usr ?--with-ksource=/usr/src/linux ?? ? ? ? ? ?make ?? ? ? ? ? ?make install 三、編譯安裝l7-protocols-2009-05-28.tar.gz協議包 ?? ? ?1、解壓 ?? ? ? ? ? ?tar xvf l7-protocols-2009-05-28.tar.gz? ?? ? ?2、編譯安裝(不需要編譯) ?? ? ? ? ? ?cd l7-protocols-2009-05-28 ?? ? ? ? ? ?make install 四、修改、還原iptables的服務腳本和配置文件 ?? ? ? ? ? ?mv ~/ipitables /etc/rc.d/init.d/ ?? ? ? ? ? ?cd !$ ?? ? ? ? ? ?修改服務腳本 ?? ? ? ? ? ?vim iptables ?? ? ? ? ? ?在莫行模式下輸入 ?? ? ? ? ? ?:%s@/bin/$IPTABLES@/usr/sbin/$IPTABLES@g ?? ? 保存退出 ?? ? ? ? ? ?cp iptables-config /etc/sysconfig/ ? 還原配置文件 ? ?? ? 好了,我們就可以啟動服務了 ? ?? ? ? ? ? ?service iptables start ?? ? 到此我們的l7就安裝成功我們可以簡單練習一下,禁止192.168.10.0/24內的主機上QQ,命令如下: ?? ? ? ? ?iptables -t filter -A FORWARD -s 192.168.10.0/24 -m layer7 --17proto qq -j REJECT? ?? ? ?? ?? ? 至于軟件或協議的控制也是如此的方便。
?
轉載于:https://blog.51cto.com/aceruser/643995
總結
以上是生活随笔為你收集整理的给你的主机防火墙添加l7-filter的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 喜欢linux的朋友加QQ群了17083
- 下一篇: 前序-中序-后序-非递归-实现