# uname -r 2.6.32-504.el6.x86_64
下載 kernel-2.6.32-504.el6.src.rpm和iptables-1.4.7-14.el6.src.rpm
http://ftp.redhat.com/redhat/linux/enterprise/6Server/en/os/SRPMS/
下載iptables-1.4.20.tar.bz2
ftp://ftp.netfilter.org/pub/iptables
下載netfilter-layer7-v2.22.tar.gz
http://l7-filter.sourceforge.net/
iptables-1.4.7-14.el6.src.rpm和iptables-1.4.20.tar.bz2隨便用一個就好
爲內核打補丁並重新編譯內核:
# useradd mockbuild #不創建的話下面會警告 # rpm -i kernel-2.6.32-504.el6.src.rpm # cp rpmbuild/SOURCES/linux-2.6.32-504.el6.tar.bz2 linux-2.6.32-504.el6.tar.bz2 # tar xf linux-2.6.32-504.el6.tar.bz2 -C /usr/src #一般在/usr/src下操作內核 # cd /usr/src/ # ls debug kernels linux-2.6.32-504.el6 vboxhost-4.3.26 # ln -sv linux-2.6.32-504.el6 #linux很多應用程序用的到源碼的話會到/usr/src找linux而不是linux-2.6.32-504.el6,所以創建個鏈接 "linux" -> "linux-2.6.32-504.el6" # cd linux # cp /boot/config-2.6.32-504.el6.x86_64 .config複製生成.config文件
退出,退出,保存
# cd # tar xf netfilter-layer7-v2.23.tar.gz -C /usr/src/ # cd /usr/src/linux # patch -p1 < ../netfilter-layer7-v2.23/kernel-2.6.32-layer7-2.23.patch # make menuconfig # yum -y install screen # screen # make
按下Ctrl+a,鬆開,再按d,回到終端
# screen -ls There is a screen on: 11241.pts-0.www(Detached) 1 Socket in /var/run/screen/S-root. # screen -r 11241
在安裝時有可能出現這樣的錯誤
解決方法
# make clean
# make menuconfig
這項關閉
這項關閉
# make # make modules_install # make install # shutdown -r now # uname -r 2.6.32-l7.1
iptables的安裝:
1、下載iptables源碼,打補丁,而後編譯;
2、下載src.rpm格式包,安裝,打補丁,而後重新製作成rpm包;
安裝方法1
# tar xf iptables-1.4.20.tar.bz2 # cp /usr/src/netfilter-layer7-v2.23/iptables-1.4.3forward-for-kernel-2.6.20forward/libxt_layer7.* iptables-1.4.20/extensions/
然後編譯安裝就可以了
安裝方法2
# rpm -ivh iptables-1.4.7-14.el6.src.rpm # cd rpmbuild/SOURCES/iptables-1.4.7/extensions # cp /usr/src/netfilter-layer7-v2.23/iptables-1.4.3forward-for-kernel-2.6.20forward/libxt_layer7.* ./ # cd .. # rm -rf iptables-1.4.7.tar.bz2 # tar jcf iptables-1.4.7.tar.bz2 iptables-1.4.7/* # rm -rf iptables-1.4.7/ # cd ../SPECS/ # ls iptables.spec kernel.spec # vim iptables.spec Release: 15%{?dist}14-->15 #把自己的數字加1就好 --with-kernel=/usr/src/linux --with-kbuild=/usr/src/linux --with-ksource=/usr/src/linux # rpmbuild -bb iptables.spec #要等kernel安裝完成才行
我使用的方法2:
# rpmbuild -bb iptables.spec # cd .. # ls BUILD BUILDROOT RPMS SOURCES SPECS SRPMS # cd RPMS/x86_64/ # ls iptables-1.4.7-15.el6.x86_64.rpm iptables-devel-1.4.7-15.el6.x86_64.rpm iptables-debuginfo-1.4.7-15.el6.x86_64.rpm iptables-ipv6-1.4.7-15.el6.x86_64.rpm # rpm -qa | grep iptables iptables-1.4.7-14.el6.x86_64 iptables-ipv6-1.4.7-14.el6.x86_64 # rpm -Uvh iptables-1.4.7-15.el6.x86_64.rpm iptables-ipv6-1.4.7-15.el6.x86_64.rpm #升級這兩個rpm包就可以,升級完成,則iptables能使用layer7 # tar xf l7-protocols-2009-05-28.tar.gz #使layer7可以識別相關協議 # cd l7-protocols-2009-05-28 # make install # cd /etc/l7-protocols/protocols/
ACCT的功能已經可以在內核參數中按需啓用或禁用。
net.netfilter.nf_conntrack_acct = 1
# sysctl -a | grep acct kernel.acct = 4230 net.netfilter.nf_conntrack_acct = 0 # sysctl -w net.netfilter.nf_conntrack_acct=1 net.netfilter.nf_conntrack_acct = 1 # iptables -A FORWARD -m layer7 --l7proto ssh -j REJECT #現在ssh不能使用