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

2010年11月10日 星期三

Read ext3/ext4 Partition from Windows

Ext2Read is an explorer like utility to explore ext2/ext3/ext4 files. It now supports LVM2 and EXT4 extents. It can be used to view and copy files and folders. It can recursively copy entire folders. It can also be used to view and copy disk and file


2010年10月28日 星期四

利用 ICMP 模擬 G.729 語音封包來測試 VoIP 品質

G.729 語音壓縮的標準,是採用週期性的方式每 20 ms 產生一個 20 bytes 的語音封包 (Voice Payload),之後當語音封包封裝成IP 格式,其實在裡面已經增加了 3 個 header,分別是 RTP (12 bytes), UDP (8 bytes), IP (20 bytes),共 60 bytes 所以在設定參數如下:

-s size 參數設定為 52 (ICMP 自己會加上 8bytes 在 header , 所以最後大小為 60 bytes)
-i interval 設定為 0.02 (G.729 預設為 20 ms)
-c count 設定為 100 , 即送 100 個封包,此處可視情況增減

需先切換為 root
su -
再下 ping 指令
ping -s 52 -i 0.02 -c 100 Destination IP

如果 ping 的統計結果有出現 packet loss 的情況,可能即為該線路頻寬不足 (小於1M/64k)、不良(雜訊)或者是內部流量過大等情形,即使用者打 VoIP 會有通話斷斷續續的情況。


2010年10月26日 星期二

在Uboot下使用ckermit透過com port來download image file

u-boot的官方網站已經說很清楚了。看這裡:
http://www.denx.de/wiki/view/DULG/UBootCmdGroupDownload#Section_5.9.5.3.

minicom is another popular serial communication program. Unfortunately, many users have reported problems using it with U-Boot and Linux, especially when trying to use it for serial image download. It's use is therefore discouraged.



* 下載 cku211.tar.gz 

* 解壓縮後 編譯: make linux;make install



* 編譯完成後執行 : kermit 


* Kermit的配置範例(可設定於~/.kermrc):
set line /dev/ttyS0
set speed 115200
set carrier-watch off
set handshake none
set flow-control none
robust
set file type bin
set file name lit
set rec pack 1000
set send pack 1000
set window 5


* 連上板子 : connect or c


*  切換 : 按下Ctrl + \  , 再按C 可以跳回kermit; 若欲跳回console可以再輸入c or connect。

* uboot上輸入 :  eraseall b

*  傳送檔案 : send /path/filename



 補充:搭配minicom使用

*使用minicom -s,到"檔案傳輸協定"或"File Transfer protocols"裡的G和H,

     G設定為/usr/local/bin/kermit -i -l %f -b %b -s           Y U Y N N,

     H設定為/usr/local/bin/kermit -i -l %f -b %b -r           N D Y N N。

* 開始傳檔
執行Ctrl+A -> S,接著選完檔案後即可開始傳送檔案了

2010年10月25日 星期一

CHT VDSL CPE device default username/password

* 北部 帳號 cht 密碼 chtnvdsl
* 中部 帳號 cht 密碼 chtcvdsl
* 南部 帳號 cht 密碼chtsvdsl

2010年10月22日 星期五

Fedora 12以root用戶登錄的方法

首先以用戶賬號進入終端,允許root賬號登陸:
  $ su
  $ vi /etc/pam.d/gdm
  刪除其中的一行auth required pam_succeed_if.souser != root quiet
  :wq保存並退出。
  $ vi /etc/pam.d/gdm-passwaord
  刪除其中的一行auth required pam_succeed_if.souser != root quiet
  :wq保存並退出。
  這樣就可以使用root進行GUI登陸了。
  還可以修改/etc/gdm/custom.conf文件,增加下面幾行,啟用root自動登陸
  [daemon]
  AutomaticLoginEnable=true
  AutomaticLogin=user_name
  Fedora 12的網絡服務不能自動啟動,同樣需要修改
  chkconfig --level 35 network on
  如果使用GUI界面去修改網絡配置,貌似那個修改程序有BUG,子網掩碼改完了再打開就變成了192.168.1.1
  同樣,可以在文件中直接修改。
  文件位置:/etc/sysconfig/network-scripts/ifcfg-eth0

MII, GMII, RGMII

基本上,這三個的作用是一樣的
同樣都是連結MAC層和PHY層的介面。區別在於編碼、速度、使用的腳位數、I/O clock的頻率不同。

MII:這是IEEE 802.3u制定出來,應用在Fast Ethernet上,連
接Data link layer中的MAC層和Physical Layer中的PHY層的溝通介面。全名為(Media Independent Interface)。
(這樣的說法有點瑕庛,因為Data link layer有分為MAC層和LLC層,但Physical Layer沒有分其它的層別,統稱為PHY層)

MII使用8B/10B之編碼。所以運作在125Mbps時,可以傳送包含檔頭的100Mbps的資料。
(想成有八條水管,同時有125Mbps的資料流進來,通過了一個闡道,要流到十條水管裡去,這十條水管的平均流速就是125Mbps*8/10=100Mbps。)

IC對PHY做讀寫的時候用一組訊號:MDC(Management Data Control)與MDIO(Management Data Input/Output)。
輸出和輸入各有四個bit的匯流排: Tx[0:3]、Rx[0:3](輸出是指IC到PHY、輸入是指PHY到IC)

MII對於Data Sampling reference用的兩組clock,頻率為25MHz,
這兩個訊號為Tx_CLK和Rx_CLK。(Ethernet頻率為2.5MHz)

通知對方準備輸入資料的輸出和輸入的啟動訊號為:Tx_EN、Rx_EN
輸出、輸入訊號的錯誤通知訊號為:Tx_ER、Rx_ER
得到有效輸入資料的通知訊號為:RX_DV
網路上出現擁塞的Colision訊號為:Col作為carrier回覆用的訊號為:CRS(請參考CSMA/CD)
MII實作的電路電壓可用+5V或是+3.3V

GMII: Gigabit Media Independent Interface,可支授到1Gbps,不同於MII,輸出和輸入各有8bit
Tx:GTXCLK、TxCLK、TxD[0:7]、TxEN、TxER
Rx:RxCLK、RxD[0:7]、RxDV、RxER、COL、CRS、MDC、MDIO

RGMII: Reduced Gigabit Media Independent Interface,顧名思義就是GMII的縮小版(因為減少了PIN腳位數)
和GMII一樣可以支援10/1O0/1000Mbps,只有定義12個訊號,比GMII還少一半:RxC、RxD[0:3]、Rx_CTL、TxC、TxD[0:3]、Tx_CTL

IC控制訊號一樣是透過MDC、MDIO

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