2010年11月11日 星期四

iptables with l7-filter

簡介
Linux netfilter的外掛模組,可讓iptables對應用層過濾分析,像是p2p,im,..等
(http://l7-filter.sourceforge.net/)

安裝l7-filter需要以下檔案
Linux kernel source(http://www.kernel.org)
iptables source(http://netfilter.org)
netfilter-layer7(http://sourceforge.net/project/showfiles.php?group_id=80085)
l7-protocols definitions(http://sourceforge.net/project/showfiles.php?group_id=80085)

ps:Kernel compatibility
http://l7-filter.sourceforge.net/kernelcompat

..................................................................................................
安裝步驟

1
先下載所需要的檔案

2
kernel部份
ps:需已安裝過kernel source,並讓/usr/src/linux可指向核心
2.1修正核心patch
用netfilter-layer7-vX.Y/kernel-2.6.*-layer7-X.Y.patch修正核心patch
ps:patch版本必須與目前核心相同,可看netfilter-layer7-vX.Y/readme
2.2重新編譯核心,並增加Layer 7 match support
2.3開始編譯核心
2.4確認開機檔是用新的核心,並reboot

3
iptables部份
3.1修正iptables的patch
用netfilter-layer7-vX.Y/iptables-layer7-X.Y.patch修正iptables source,並安裝修正過的iptables
3.2將iptables指令,指向修正過的iptables
3.3安裝l7-protocols definitions
預設會裝在/etc/l7-protocols/

.......

安裝過程大致如下
1
下載以下檔案後解壓縮到/usr/local/src
netfilter-layer7-v2.0
iptables-1.4.0
l7-protocols-2005-12-16

2.1
cd /usr/src/linux
patch -p1 < /usr/local/src/netfilter-layer7-v2.0/kernel-2.6.13-2.6.14-layer7-2.0.patch
2.2
make mrproper
make oldconfig
會出現 Layer 7 match support (EXPERIMENTAL)... [N/m/?] (NEW) -> 可選m或按enter
make menuconfig
確定是否為 Layer 7 match support
2.3
make clean
make bzImage
make modules
make modules_install
make install
2.4
reboot

3.1
cd /usr/local/src/iptables-1.4.0
patch -p1 < ../netfilter-layer7-v2.0/iptables-layer7-2.0.patch
chmod +x ./extensions/.layer7-test
make clean
make KERNEL_DIR=/usr/src/linux
make install KERNEL_DIR=/usr/src/linux
3.2
cd /sbin
mv iptables iptables.old
ln -s /usr/local/sbin/iptables iptables
3.3
cd /usr/local/src/l7-protocols-2005-12-16
make install

.......................................................................................
用法
-m layer7 --l7proto < protocol> -j < target>
簡介
Linux netfilter的外掛模組,可讓iptables對應用層過濾分析,像是p2p,im,..等
(http://l7-filter.sourceforge.net/)

安裝l7-filter需要以下檔案
Linux kernel source(http://www.kernel.org)
iptables source(http://netfilter.org)
netfilter-layer7(http://sourceforge.net/project/showfiles.php?group_id=80085)
l7-protocols definitions(http://sourceforge.net/project/showfiles.php?group_id=80085)

ps:Kernel compatibility
http://l7-filter.sourceforge.net/kernelcompat

..................................................................................................
安裝步驟

1
先下載所需要的檔案

2
kernel部份
ps:需已安裝過kernel source,並讓/usr/src/linux可指向核心
2.1修正核心patch
用netfilter-layer7-vX.Y/kernel-2.6.*-layer7-X.Y.patch修正核心patch
ps:patch版本必須與目前核心相同,可看netfilter-layer7-vX.Y/readme
2.2重新編譯核心,並增加Layer 7 match support
2.3開始編譯核心
2.4確認開機檔是用新的核心,並reboot

3
iptables部份
3.1修正iptables的patch
用netfilter-layer7-vX.Y/iptables-layer7-X.Y.patch修正iptables source,並安裝修正過的iptables
3.2將iptables指令,指向修正過的iptables
3.3安裝l7-protocols definitions
預設會裝在/etc/l7-protocols/

.......

安裝過程大致如下
1
下載以下檔案後解壓縮到/usr/local/src
netfilter-layer7-v2.0
iptables-1.4.0
l7-protocols-2005-12-16

2.1
cd /usr/src/linux
patch -p1 < /usr/local/src/netfilter-layer7-v2.0/kernel-2.6.13-2.6.14-layer7-2.0.patch
2.2
make mrproper
make oldconfig
會出現 Layer 7 match support (EXPERIMENTAL)... [N/m/?] (NEW) -> 可選m或按enter
make menuconfig
確定是否為 Layer 7 match support
2.3
make clean
make bzImage
make modules
make modules_install
make install
2.4
reboot

3.1
cd /usr/local/src/iptables-1.4.0
patch -p1 < ../netfilter-layer7-v2.0/iptables-layer7-2.0.patch
chmod +x ./extensions/.layer7-test
make clean
make KERNEL_DIR=/usr/src/linux
make install KERNEL_DIR=/usr/src/linux
3.2
cd /sbin
mv iptables iptables.old
ln -s /usr/local/sbin/iptables iptables
3.3
cd /usr/local/src/l7-protocols-2005-12-16
make install

.......................................................................................
用法
-m layer7 --l7proto < protocol> -j < target>
可過濾的protocol可參考http://l7-filter.sourceforge.net/protocols
常見p2p protocol如下
gnutella 可阻擋foxy
bittorrent 可阻擋bittorrent 通訊協定
fasttrack 可阻擋kazaa
edonkey 可阻擋eDonkey,eMule
xunlei 可阻擋迅雷
ex:
在prerouting封鎖即時通
iptables -t mangle -A PREROUTING -m layer7 --l7proto yahoo -j DROP
不讓edonkey能進入本機
iptables -I INPUT -m layer7 --l7proto edonkey -j DROP
封鎖foxy
iptables -t mangle -A PREROUTING -m layer7 --l7proto gnutella -j DROP
iptables -t mangle -A POSTROUTING -m layer7 --l7proto gnutella -j DROP




其他參考
http://l7-filter.sourceforge.net/L7-HOWTO-Netfilter



可過濾的protocol可參考http://l7-filter.sourceforge.net/protocols
常見p2p protocol如下
gnutella 可阻擋foxy
bittorrent 可阻擋bittorrent 通訊協定
fasttrack 可阻擋kazaa
edonkey 可阻擋eDonkey,eMule
xunlei 可阻擋迅雷
ex:
在prerouting封鎖即時通
iptables -t mangle -A PREROUTING -m layer7 --l7proto yahoo -j DROP
不讓edonkey能進入本機
iptables -I INPUT -m layer7 --l7proto edonkey -j DROP
封鎖foxy
iptables -t mangle -A PREROUTING -m layer7 --l7proto gnutella -j DROP
iptables -t mangle -A POSTROUTING -m layer7 --l7proto gnutella -j DROP




其他參考
http://l7-filter.sourceforge.net/L7-HOWTO-Netfilter







from http://systw.net/note/af/sblog/more.php?id=124

How to repair and clone disk with ddrescue

  ddrescue  is a tool that can be used to repair and clone disks on a  Linux system . This includes hard drives, partitions, DVD discs, flas...