顯示具有 LINUX 標籤的文章。 顯示所有文章
顯示具有 LINUX 標籤的文章。 顯示所有文章

How to dump DNS cache file of BIND9?

之前我們在"如何在 Linux server 上 turn on DNS (BIND) 的 Query logging"的文章中提過 rndc 這個好用的指令,這次也要用到這個小工具來 dump DNS 的 RR cache 資料。

基本上用法很簡單,依據 rndc 的使用說明可以看到如下:
dumpdb [-all|-cache|-zones] [view ...]
Dump cache(s) to the dump file (named_dump.db).
所以我們直接敲入 "rndc dumpdb -cache" 就行了,不過產生的 Cache db 檔並不像說明所列的 named_dump.db 而是 cache_dump.db,下面就是範例:
[root@ns1 named]# ls -alrt /var/named/chroot/var/named/data/
total 24
drwxr-x--- 4 named named 12288 Mar 31 12:23 ..
drwxrwx--- 2 named named 4096 Apr 8 13:24 .
[root@ns1 named]#
[root@ns1 named]# rndc dumpdb -cache
[root@ns1 named]# ls -alrt /var/named/chroot/var/named/data/
total 1376
drwxr-x--- 4 named named 12288 Mar 31 12:23 ..
-rw-r--r-- 1 named named 1379904 Apr 8 13:25 cache_dump.db
drwxrwx--- 2 named named 4096 Apr 8 13:25 .
[root@ns1 named]#
以下是 /var/named/chroot/var/named/data/cache_dump.db 檔案開頭的一小部分,僅供參考:
[root@ns1 named]# less /var/named/chroot/var/named/data/cache_dump.db
;
; Start view _default
;
;
; Cache dump of view '_default'
;
$DATE 20100408052518
; glue
ac. 19164 IN NS A.NIC.ac.
19164 IN NS A.NS13.NET.
19164 IN NS B.NIC.ac.
19164 IN NS B.NIC.IO.
19164 IN NS B.NS13.NET.
19164 IN NS NS1.COMMUNITYDNS.NET.
19164 IN NS NS3.ICB.CO.UK.
; glue
A.nic.ac. 19164 A 64.251.31.177
; glue
b.nic.ac. 15120 A 78.104.145.37
; glue
ae. 42322 NS NS1.AEDNS.ae.
42322 NS NS2.AEDNS.ae.
42322 NS SEC3.APNIC.NET.
42322 NS NS-AE.RIPE.NET.
42322 NS SNS-PB.ISC.ORG.
42322 NS NSEXT-PCH.AEDNS.ae.
; glue
NS1.AEDNS.ae. 42322 A 79.98.120.73
; glue
NS2.AEDNS.ae. 42322 A 79.98.121.73
; glue
NSEXT-PCH.AEDNS.ae. 42322 A 199.4.137.1
; glue
42322 AAAA 2001:500:7d::1
; answer
www.google.ae. 25355 CNAME www.google.com.
; authauthority
bittorrent.am. 32399 NS ns1.everydns.net.
32399 NS ns2.everydns.net.
32399 NS ns3.everydns.net.
32399 NS ns4.everydns.net.
; additional
y.am. 28607 NS ns1.mdnsservice.com.
28607 NS ns2.mdnsservice.com.
28607 NS ns3.mdnsservice.com.
; answer
curinfo.an. 40356 MX 0 wabi.curinfo.an.
; glue
AQ. 120558 NS NS1.DNS.AQ.
120558 NS FLAG.EP.NET.
報告完畢。
(詳全文...)

DNS Query Performance Testing Tool -- "queryperf"

這兩天為了測試 DNS server 的 System capacity, 才發現原來還有 "queryperf" 這個小工具,這是 Bind9 內帶的工具,不過我找了一下,雖然我在一開始裝機時就將 Bind9 的相關 package 都安裝了,不過似乎還是沒找到 "queryperf" 的 command...不過沒關係,找不到就直接裝吧...

首先看一下今天的測試環境,這裡有兩台 DNS server,中間都是 2G channel bonding 的網路:
Master DNS server : RHEL 5.2 (bind-9.3.4-6.P1)
Slave DNS server : RHEL 5.1 (bind-9.3.3-7)

首先我們先到 ISC -- Internet Systems Consortium 的 ftp 站 http://ftp.isc.org/isc/bind9/ 去抓 Bind9 Tarbal file : (找自己需要的版本就好)
[root@ns1 opt]# wget http://ftp.isc.org/isc/bind9/9.3.4-P1/bind-9.3.4-P1.tar.gz
--16:58:53-- http://ftp.isc.org/isc/bind9/9.3.4-P1/bind-9.3.4-P1.tar.gz
Resolving ftp.isc.org... 204.152.184.110, 2001:4f8:0:2::18
Connecting to ftp.isc.org|204.152.184.110|:80...

[root@ns2 opt]# wget http://ftp.isc.org/isc/bind9/9.3.3/bind-9.3.3.tar.gz
--16:56:54-- http://ftp.isc.org/isc/bind9/9.3.3/bind-9.3.3.tar.gz
Resolving ftp.isc.org... 204.152.184.110, 2001:4f8:0:2::18
Connecting to ftp.isc.org|204.152.184.110|:80...
抓回來之後,這裡我們擺在 /opt 底下,然後解壓縮 :
[root@ns1 opt]# tar -zxvf bind-9.3.4-P1.tar.gz
[root@ns2 opt]# tar -zxvf bind-9.3.3.tar.gz
接著我們到 /opt/bind-9.3.4-P1/contrib/queryperf/ 目錄下,這裡就是放 queryperf 的位置。
[root@ns1 opt]# cd bind-9.3.4-P1/contrib/queryperf/
再來是 "sh configure" 以及 "make" 來編譯我們要的 queryperf 指令:
[root@ns1 queryperf]# sh configure
checking for gcc... gcc
checking for C compiler default output... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for library containing res_mkquery... -lresolv
checking for socket in -lsocket... no
checking for inet_ntoa in -lnsl... yes
checking for gethostbyname2... yes
checking for getaddrinfo... yes
checking for getnameinfo... yes
checking for socklen_t... yes
checking for sa_len... no
configure: creating ./config.status
config.status: creating Makefile
[root@ns1 queryperf]# make
gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DHAVE_LIBNSL=1 -DHAVE_GETHOSTBYNAME2=1 -DHAVE_GETADDRINFO=1 -DHAVE_GETNAMEINFO=1 -c queryperf.c
gcc -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DHAVE_LIBNSL=1 -DHAVE_GETHOSTBYNAME2=1 -DHAVE_GETADDRINFO=1 -DHAVE_GETNAMEINFO=1 queryperf.o -lnsl -lresolv -lm -o queryperf
[root@ns1 queryperf]#
接著就可以看到產生了一個新的檔案 "queryperf",這就是我們等一下要用到的指令了。
[root@ns1 queryperf]# ls -alrt
total 292
-rw-rw-r-- 1 10132 wheel 2981 Jul 12 2001 README
-rw-rw-r-- 1 10132 wheel 1831 May 13 2004 configure.in
-rwxrwxr-x 1 10132 wheel 97865 May 13 2004 configure
-rw-rw-r-- 1 10132 wheel 603 Jul 20 2004 Makefile.in
-rw-rw-r-- 1 10132 wheel 50279 Jan 5 2006 queryperf.c
drwxrwxr-x 2 10132 wheel 4096 Jun 28 2007 utils
drwxrwxr-x 2 10132 wheel 4096 Mar 30 17:29 missing
drwxrwxr-x 2 10132 wheel 4096 Mar 30 17:29 input
drwxrwxr-x 11 10132 wheel 4096 Mar 30 17:29 ..
-rw-r--r-- 1 root root 791 Mar 30 17:30 Makefile
-rwxr-xr-x 1 root root 19302 Mar 30 17:30 config.status
-rw-r--r-- 1 root root 8188 Mar 30 17:30 config.log
-rw-r--r-- 1 root root 34692 Mar 30 17:30 queryperf.o
-rwxr-xr-x 1 root root 34059 Mar 30 17:30 queryperf
drwxrwxr-x 5 10132 wheel 4096 Mar 30 17:30 .
README 檔案裡面有簡介如何使用,當然也可以用 -h 來秀一下 useage:
[root@ns1 queryperf]# /opt/bind-9.3.4-P1/contrib/queryperf/queryperf -h

DNS Query Performance Testing Tool
Version: $Id: queryperf.c,v 1.1.1.2.2.5.4.4 2006/01/05 02:06:09 marka Exp $


Usage: queryperf [-d datafile] [-s server_addr] [-p port] [-q num_queries]
[-b bufsize] [-t timeout] [-n] [-l limit] [-f family] [-1]
[-i interval] [-r arraysize] [-u unit] [-H histfile]
[-T qps] [-e] [-D] [-c] [-v] [-h]
-d specifies the input data file (default: stdin)
-s sets the server to query (default: 127.0.0.1)
-p sets the port on which to query the server (default: 53)
-q specifies the maximum number of queries outstanding (default: 20)
-t specifies the timeout for query completion in seconds (default: 5)
-n causes configuration changes to be ignored
-l specifies how a limit for how long to run tests in seconds (no default)
-1 run through input only once (default: multiple iff limit given)
-b set input/output buffer size in kilobytes (default: 32 k)
-i specifies interval of intermediate outputs in seconds (default: 0=none)
-f specify address family of DNS transport, inet or inet6 (default: any)
-r set RTT statistics array size (default: 50000)
-u set RTT statistics time unit in usec (default: 100)
-H specifies RTT histogram data file (default: none)
-T specify the target qps (default: 0=unspecified)
-e enable EDNS 0
-D set the DNSSEC OK bit (implies EDNS)
-c print the number of packets with each rcode
-v verbose: report the RCODE of each response on stdout
-h print this usage
使用上主要有兩個步驟,第一就是先建立一個 RR 測試檔案,裡面的格式也很簡單,就是:
aaa.com NS
bbb.com MX
ccc.com A
這裡我先建兩個含我內部所有 RR record 的測試檔案:
/opt/querytest_list.txt >> 裡面有 1032 筆 record
/opt/querytest_list2.txt >> 裡面有 519120 筆 record

至於指令的用法也很簡單,就是 "./queryperf -s hostname -d test_file",其中 hostname 是被測試的 DNS server IP address 或 hostname,至於 test_file 就是剛剛編輯的 RR file 囉。

建議是直接裝在 Slave 的機器上,去測試 Master 的機器比較不影響效能,雖然我試完發現差異不太大。這裡我直接示範在 Master server 上跑 queryperf 的結果:

先測試 query 1000 筆 record 的結果:
[root@ns1 named]# /opt/bind-9.3.4-P1/contrib/queryperf/queryperf -s localhost -d /opt/querytest_list.txt

DNS Query Performance Testing Tool
Version: $Id: queryperf.c,v 1.1.1.2.2.5.4.4 2006/01/05 02:06:09 marka Exp $

[Status] Processing input data
[Status] Sending queries (beginning with 127.0.0.1)
[Status] Testing complete

Statistics:

Parse input file: once
Ended due to: reaching end of file

Queries sent: 1030 queries
Queries completed: 1030 queries
Queries lost: 0 queries
Queries delayed(?): 0 queries

RTT max: 0.001296 sec
RTT min: 0.000073 sec
RTT average: 0.000344 sec
RTT std deviation: 0.000116 sec
RTT out of range: 0 queries

Percentage completed: 100.00%
Percentage lost: 0.00%

Started at: Wed Mar 30 20:35:04 2010
Finished at: Wed Mar 30 20:35:04 2010
Ran for: 0.020277 seconds

Queries per second: 50796.468906 qps

[root@ns1 named]#
再先測試 query 519120 筆 record 的結果:
[root@ns1 named]# /opt/bind-9.3.4-P1/contrib/queryperf/queryperf -s localhost -d /opt/querytest_list2.txt

DNS Query Performance Testing Tool
Version: $Id: queryperf.c,v 1.1.1.2.2.5.4.4 2006/01/05 02:06:09 marka Exp $

[Status] Processing input data
[Status] Sending queries (beginning with 127.0.0.1)
[Status] Testing complete

Statistics:

Parse input file: once
Ended due to: reaching end of file

Queries sent: 519120 queries
Queries completed: 519120 queries
Queries lost: 0 queries
Queries delayed(?): 0 queries

RTT max: 0.002820 sec
RTT min: 0.000042 sec
RTT average: 0.000382 sec
RTT std deviation: 0.000085 sec
RTT out of range: 0 queries

Percentage completed: 100.00%
Percentage lost: 0.00%

Started at: Wed Mar 30 20:36:31 2010
Finished at: Wed Mar 30 20:36:41 2010
Ran for: 10.158483 seconds

Queries per second: 51102.118299 qps

[root@ns1 named]#
最後是在 Slave server 上跑 queryperf 去測試 Master server,先測試 query 1000 筆 record 的結果:
[root@ns2 slaves]# /opt/bind-9.3.3/contrib/queryperf/queryperf -s ns1 -d /opt/querytest_list.txt

DNS Query Performance Testing Tool
Version: $Id: queryperf.c,v 1.1.1.2.2.5.4.4 2006/01/05 02:06:09 marka Exp $

[Status] Processing input data
[Status] Sending queries (beginning with xx.xx.xx.1)
[Status] Testing complete

Statistics:

Parse input file: once
Ended due to: reaching end of file

Queries sent: 1030 queries
Queries completed: 1030 queries
Queries lost: 0 queries
Queries delayed(?): 0 queries

RTT max: 0.000572 sec
RTT min: 0.000128 sec
RTT average: 0.000339 sec
RTT std deviation: 0.000049 sec
RTT out of range: 0 queries

Percentage completed: 100.00%
Percentage lost: 0.00%

Started at: Wed Mar 30 20:42:17 2010
Finished at: Wed Mar 3 20:42:17 2010
Ran for: 0.018820 seconds

Queries per second: 54729.011690 qps

[root@ns2 slaves]#
再先測試 query 519120 筆 record 的結果:
[root@ns2 slaves]# /opt/bind-9.3.3/contrib/queryperf/queryperf -s ns1 -d /opt/querytest_list2.txt

DNS Query Performance Testing Tool
Version: $Id: queryperf.c,v 1.1.1.2.2.5.4.4 2006/01/05 02:06:09 marka Exp $

[Status] Processing input data
[Status] Sending queries (beginning with xx.xx.xx.1)
[Status] Testing complete

Statistics:

Parse input file: once
Ended due to: reaching end of file

Queries sent: 519120 queries
Queries completed: 519120 queries
Queries lost: 0 queries
Queries delayed(?): 0 queries

RTT max: 0.000818 sec
RTT min: 0.000059 sec
RTT average: 0.000330 sec
RTT std deviation: 0.000044 sec
RTT out of range: 0 queries

Percentage completed: 100.00%
Percentage lost: 0.00%

Started at: Wed Mar 30 20:42:51 2010
Finished at: Wed Mar 30 20:43:00 2010
Ran for: 9.113103 seconds

Queries per second: 56964.131756 qps

[root@ns2 slaves]#
這裡我將 Master DNS server 的 IP 馬賽克起來了...由上面的結果可以看的出來,在這一台機器上的每秒最大查詢數量大約在 5萬6千筆左右,以上,報告完畢。

------------------------------------------------------------------------------------
2010/03/31 補充資料:

再查了一下資料發現其實 Bind9 內建的小工具應該是 dnsperf/resperf 才對,用法跟 queryperf 幾乎一樣,有興趣可以參考一下下面的網頁:

Linux Certif - Man dnsperf(1)
Linux Certif - Man resperf(1)

這裡附上一個測試結果以供比較:
[root@ns2 slaves]# /usr/local/nom/bin/dnsperf -s ns1 -d /opt/querytest_list2.txt

DNS Performance Testing Tool

Nominum Version 1.0.1.0

[Status] Processing input data
[Status] Sending queries (to 113.21.80.1)
[Status] Testing complete

Statistics:

Parse input file: once
Ended due to: reaching end of file

Queries sent: 519120 queries
Queries completed: 519120 queries
Queries lost: 0 queries

Avg request size: 52 bytes
Avg response size: 136 bytes

Percentage completed: 100.00%
Percentage lost: 0.00%

Started at: Wed Mar 31 14:59:03 2010
Finished at: Wed Mar 31 14:59:13 2010
Ran for: 9.362073 seconds

Queries per second: 55449.257873 qps

[root@ns2 slaves]#
補充完畢~
(詳全文...)

用 X-manager 連進 Linux server 時出現 GConf Error 怎麼辦?

最近用 X-manager 連進 Linux server 的 X-Window 時,卻一直出現如下圖所示的幾個錯誤訊息,這讓我在登入時很困擾:
其中有四個錯誤訊息分別是:
1. GConf error: Adding client to server's list failed, CORBA error: IDL:omg.org/CORBA/COMM_FAILURE:1.0
All further errors shown only on terminal.
2. An error occurred while loading or saving configuration information for gnome-session. Some of your configuration settings may not work properly.
Detail : Adding client to server's list failed, CORBA error: IDL:omg.org/CORBA/COMM_FAILURE:1.0
3. An error occurred while loading or saving configuration information for Nautilus. Some of your configuration settings may not work properly.
Detail : Adding client to server's list failed, CORBA error: IDL:omg.org/CORBA/COMM_FAILURE:1.0
4. An error occurred while loading or saving configuration information for Print Notifier. Some of your configuration settings may not work properly.
Detail : Adding client to server's list failed, CORBA error: IDL:omg.org/CORBA/COMM_FAILURE:1.0
遇到這種情形,一則是乾脆重新開機,如果是像我這邊的機器屬於重要服務不能中斷的話,那麼還有一個方法,照著下面的步驟吧:
首先:假設是用 root 登入的話,那麼先把 /tmp/ 底下跟 root 相關的檔案都砍掉:
接著,到 root 的目錄下,找到 .gnome 開頭的 3 個目錄 (.gnome, .gnome2, .gnome2_private),一樣,全砍了:
# rm -rf .gnome*
最後,再把 X 重啟一次吧,啥?不知道步驟喔,參考一下上一篇文章"如何在不重開機的情況下 Restart RHEL 的 X window?"吧,簡單的用下面的指令也可以:
# kill -HUP `cat /var/run/gdm.pid`
,重啟完後再用 X-manager 測試一下,果然登入時就不會再有那些亂七八糟的錯誤訊息蹦出來囉,報告完畢~
(詳全文...)

如何在不重開機的情況下 Restart RHEL 的 X window?

最近有一部 RedHat 4 的機器在使用 X manager 登入時一直出現多個 GNOME 的錯誤視窗,雖然不影響登入,但還是覺得很不舒服,想要重啟機器,但因有重要的服務在 in service,只能想辦法直接在不 reboot 機器的情況下重啟 X11了,找了一下,原來在 /usr/sbin 底下就有相關的 script 可用啊:

首先一樣我們列一下這一次的測試環境:RHEL4.5 + X11:
接著我們來秀一下這個實用 script 的內容 (/usr/sbin/gdm-restart):
看到最後那一行了沒?其實我們只要拿那一行來用就夠了,不過這裡我們在重啟服務之前先看一下 X11 的 status 吧:
注意到了嗎?目前的主要 GDM 的 PID 是 4427,接著我們直接用下面的指令來重啟 X11 吧:
# kill -HUP `cat /var/run/gdm.pid`
下面就是重啟後的結果:其中第二部分多了一筆 process:
root 16547 0.0 0.0 12548 2480 ? S 14:39 0:00 \_ /usr/bin/gdm-binary -nodaemon
這是因為我用 X-manager 連進去 server 測試的結果。
重啟完只有最初的 X11 process 的 PID 不變,其餘的 process 都已經重啟了,報告完畢~

2009/08/19 補充:在 RHEL5 上面也是一樣的作法喔~
(詳全文...)

如何在 Linux server 上 turn on DNS (BIND) 的 Query logging?

在 Linux server 上開 BIND DNS service 後,發現似乎在系統的 LOG 檔案 /var/log/messages 裡面只看的到 named service 的啟動/停止訊息,卻看不到一些 Client 端 Query 的 Log,這對初期的 named 設定上來說實在是有些困擾,幸好 BIND 的 utility 中包含一個好用的工具,那就是 rndc,他有很多好用的功能可以用來細部控制 BIND,不過這裡我們只測試一下它 Turn on query logging 的功能:

首先,這裡我們的環境是 RHEL5.2 + BIND 9.3.4:
接著,我們看一下 rndc 有哪些 option 可用:
接下來就簡單了,想要 Turn on query logging 的功能,就使用下面的指令吧:
[root@ns1 named]# rndc querylog
我們來看一下系統的紀錄檔吧:
現在已經開始產生 Client query 的紀錄了。

接下來,再下一次剛剛的指令就可以 Turn off query logging 的功能了:
[root@ns1 named]# rndc querylog
我們再看一次系統的紀錄檔吧:
果然已經停止記錄了~
(詳全文...)

Linux 機器上 SFTP 時出現 "Received message too long xxxxxxxx" 的錯誤訊息

以往每次登入機器時都會用 SecureCRT 去連接機器,順便在 SecureCRT 上設定登入時執行的指令去附帶檢查把機器當下服務執行的狀況給秀出來,但因為登入的機器太多台,不希望每次有變動時就要去每一台有跑 SecureCRT 的電腦上把登入指令更改,因此想偷懶透過修改 /root/.bashrc 內容來讓這些檢查的過程自動化,也就是說讓 client 透過 SSH client 去連接機器時,只要用 root 登入,或切換使用者到 root 就會自動執行 /root/.bashrc 裡面所定義的 script 把機器狀態給秀出來~

當時的 /root/.bashrc 內容如下面範例所示:
[root@KHCFTPS01 ~]# cat ~/.bashrc
# .bashrc
# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias vi='vim'
alias ls='ls --color'

TERM=xterm-color; export TERM;
alias grep='grep --color'

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# Pre-health checking #
/etc/init.d/sys_chk.sh;
[root@KHCFTPS01 ~]#
其中的 /etc/init.d/sys_chk.sh; 那一段就是用來登入後檢查系統的那個小 shell script,測試從其他機器登入或本機變更使用者為 root 後都可正常秀出機器狀態檢查的結果。本來事情到這邊就結束了,但前幾天寫好這一部份後,也用的好好的,而昨天突然發現,要 SFTP 進這些機器都沒回應了,初步以為是防火牆的問題,但查了之後,繞開防火牆直接用兩台機器對測 SFTP 看到出現下面的錯誤訊息:
[root@ns1 ~]# sftp KHCFTPS01
Connecting to KHCFTPS01...
root@KHCFTPS01's password:
Received message too long 1044266528
[root@ns1 ~]#
可是用 SSH 測試卻又能正常登入,這時才想起來前幾天曾在這幾台機器上加上自動狀態檢查的 script,會不會是那個咚咚在搞鬼ㄌㄟ??於是回到機器上去修改 /root/.bashrc 把自動檢查的那一段先 mark 起來,再到 ns1 測試一次 SFTP 到我們的 FTP 機器,這次就可以成功登入了。所以果然是 /etc/init.d/sys_chk.sh 執行的東西太多,吐出太多東西到螢幕上...呵呵,既然知道問題出在哪兒了,山不轉路轉,路不轉嘛那我只好自己轉囉...回到剛才的 /root/.bashrc 中,還記得之前我們曾在 如何讓你的 Linux 色彩更豐富 中提到利用 alias 的作法來節省平常的時間,可以把一些很長的執行字串,改成好敲的短字串,這裡我們就用這種方式把 /etc/init.d/sys_chk.sh 指定給 sck 這個短字串 (sck 只是我覺得順眼的縮寫,請依個人喜好更改),改完的 /root/.bashrc 內容如下面範例所示:
[root@KHCFTPS01 ~]# cat ~/.bashrc
# .bashrc
# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias vi='vim'
alias ls='ls --color'
alias sck='/etc/init.d/sys_chk.sh'

TERM=xterm-color; export TERM;
alias grep='grep --color'

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi

# Pre-health checking #
sck;
[root@KHCFTPS01 ~]#
這時候再試一次 SFTP 果然就不再出現 "Received message too long 1044266528" 的問題囉~而且平時沒事也可以隨時直接敲入 sck (前面提到過,sck 只是我覺得順眼的縮寫,請依個人喜好更改)這個指令來做個機器狀態檢查,人生又擱係彩色ㄟ囉~
(詳全文...)

用 Tftpd32 接收 LINUX 送來的 SYSLOG

為了驗證機器可以送 System log 訊息到指定的 EMS server,只好先在自己的電腦上跑個 Syslog server 來收,這裡稟持本人愛用綠色軟體的習慣,推薦大家可以使用上一篇所介紹的 Tftpd32 來作為 Syslog server,有興趣可以去參觀一下(首頁在此)。而今天要驗證的 Agent 機器 OS 是 RHEL ES5.2,裡面就有 syslog Daemon 的 (service 的名稱就是 syslog 不是 syslogd 喔,待會兒要重啟服務時會用到) 所以不用另外安裝 Agent 程式。

待會兒要編輯 /etc/syslog.conf 這個主要的檔案,所以我們先列一下裡面的主要格式:
在 /etc/syslog.conf 裡的每一行都有兩個部分組成,一個是 "SELECTOR",另一個是 "ACTION"。整行組合起來就是指:當符合 "SELECTOR" 事件發生時,就採取 "ACTION" 所指定的方式來記錄這個事件。

而 "SELECTOR" 是由 facility.priority 組合而成的,其中 priority 是指事件的優先等級,分成八個不同的等級,依優先順序由低至高分別為:
debug --> info --> notice --> warn (=warning) --> err (=error) --> crit --> alert --> emerg --> panic (=emerg)。
至於 Facility 則是 syslog.conf 中用來描素事件產生子系統的關鍵字。這些在 syslog.conf 的 說明中都有提到,可以用 "man syslog.conf" 去看看詳細的說明。UNIX 系統中內定的 facility 基本上包括 auth、authpriv、cron、daemon、kern、lpr、mail、mark、news、 security(same as auth)、syslog、user、uucp、local0 ~ local7 等。這些 facility 所代表的程式,隨著 UNIX 系統種類的不同,會有些差異,但大同小異啦。下面是 facility 的意義:
* auth, authpriv:與認證有關的系統,例如 login, su 等需驗證的服務
* uucp: UUCP系統
* daemon:與各個 daemon 有關的系統
* kern :核心(kernel)系統
* lpr:列印相關的系統
* mail:與郵件有關的系統
* news:與新聞群組有關的系統
* syslog:與 syslogd本身相關的系統
* user:一般使用者的系統
* local0 ~ local7:保留, 做為特別設定使用的
所以我們接著編輯 /etc/syslog.conf 檔案,在這裡我們只新增一行新的如下來做個測試:
[root@KHCDNSS01 named]# vi /etc/syslog.conf
kern.*;daemon.warn;auth,authpriv.notice;cron.err @10.19.0.194
這裡我準備將系統 kernel 的所有訊息以及各個 Daemon 在 Warning 等級以上,認證部分的訊息在 Notice 以上還有 Cron job 在 Error 等級以上的訊息都送出來,其中 @10.19.0.194 代表將前面所定義的訊息傳送到遠端的 syslog server (IP address: 10.19.0.194),也就是跑著 Tftpd32 的電腦囉~

P.S. 另外的應用啦:如果選端收 syslog 的機器安裝的 OS 也是 LINUX server 的話,那遠端機器上要多加一個動作:
編輯 vi /etc/sysconfig/syslog 檔案,將 SYSLOGD_OPTIONS="-m 0" 變更為 SYSLOGD_OPTIONS="-m 0 -r" (增加 -r remote) 參數 ,存檔,重啟 syslog service.
[root@KHCDNSS01 named]# vi /etc/syslog.conf
kern.*;daemon.warn;auth,authpriv.notice;cron.err @10.19.0.194
[root@KHCDNSS01 named]# service syslog restart
Shutting down kernel logger: [ OK ]
Shutting down system logger: [ OK ]
Starting system logger: [ OK ]
Starting kernel logger: [ OK ]
[root@KHCDNSS01 named]# service syslog status
syslogd (pid 15144) is running...
klogd (pid 15147) is running...
所以我們可以在 Syslog server (跑 Tftpd32 的那台機器啦) 上收到來自剛剛測試機器上 restart syslog daemon 的 kernel syslog 送過來如下圖所示:

讓我們再試一次關於 kernel 的 syslog,這次我們拿兩張網卡中的其中一張,將它重起看看會發生什麼事?(P.S. 這裡兩張網卡有做 channel bonding 所以我可以隨便把其中一張網卡 down 下來,如果你的環境不是這樣,就不要隨便拿網卡來玩喔,免得連不進去囉)
[root@KHCDNSS01 named]# ifconfig eth1 down; ifconfig eth1 up;
一樣到 Syslog server 上收到來自剛剛測試機器上 eth1 down 以及 up 後 kernel infomation 的 syslog 送過來如下圖所示:

接著,我們再做個小測試,在測試機器上面搞個 daemon 的 warning syslog 來玩玩,這裡我們拿 snmpd 來做範例:
[root@KHCDNSS01 named]# service dhcpd restart
Stopping dhcpd: [ OK ]
Starting dhcpd: [ OK ]
再回到 Syslog server 上收到來自剛剛測試機器上 restart dhcpd daemon 後在帶起 dhcpd daemon warning 的 syslog 送過來如下圖所示:

接著我們測試一下關於系統登入認證的 syslog,首先我們先測試 auth,authpriv.notice; 的這種設定方式,接著我們到另一台嘗試登入測試機器,並故意第一次敲錯密碼然後第二次敲正確的密碼登入再以 exit 登出測試機器,接著我們可以在 Syslog server 上發現只收到來自剛剛測試機器上 auth,authpri notice 關於有某個 user 從某一台機器嘗試登入失敗的 syslog 送過來,至於正確敲入密碼登入及登出的部分就沒有 syslog 送出了,如下圖所示:

[root@KHCBKPS01 ~]# ssh 10.15.25.13
root@10.15.25.13's password:
Permission denied, please try again.
root@10.15.25.13's password:
Last login: Thu Jun 4 18:54:37 2009 from 10.15.25.51
[root@KHCDNSS01 named]# exit
logout

Connection to 10.15.25.13 closed.
[root@KHCBKPS01 ~]#
再來我們再測試一下 auth,authpriv.info; 的這種設定方式,接著我們到另一台嘗試登入測試機器,重複剛才的測試步驟,接著我們就可以在 Syslog server 上收到來自剛剛測試機器上 auth,authpri information 關於有某個 user 從某一台機器嘗試登入失敗,然後正確登入以及登出的 syslog 送過來如下圖所示:

[root@KHCBKPS01 ~]# ssh 10.15.25.13
root@10.15.25.13's password:
Permission denied, please try again.
root@10.15.25.13's password:
Last login: Thu Jun 4 18:56:44 2009 from 10.15.25.51
[root@KHCDNSS01 named]# exit
logout

Connection to 10.15.25.13 closed.
[root@KHCBKPS01 ~]#
以上只是一些簡單的使用範例,至於實際組合,就看個人的需求自行變更囉~
(詳全文...)

Linux Channel Bonding -- 實作合併網卡

一直想把這一篇寫完,但卻找不出時間,剛好手邊有機器要做 Channel Bonding,就順便實作順便貼上來分享一下囉,簡單講,在 Linux 上,允許把多個網路介面用一個叫 "bonding" 的 kernel module 以及 Channel bonding interface 來綁成一個 single channel,當然你可以將兩個網卡或更多的網卡綁成一個來用,簡單講就是增加頻寬,達到備援機制~

其實 Channel Bonding 的作法很簡單,只要編輯幾個檔案,再將網路重啟便可,這裡我們的環境是在一台 RHEL5 ES 的機器上要將 eth0 與 eth1 做成 bond0,那麼我們就需要編輯如下的檔案:
[root@KHCDNSS01 ~]# vi /etc/sysconfig/network-scripts/ifcfg-bond0
DEVICE=bond0
BOOTPROTO=none
ONBOOT=yes
NETWORK=10.15.25.0
NETMASK=255.255.255.0
IPADDR=10.15.25.13
USERCTL=no
P.S. 其中 bond0 的 0 視你的需求而定,這裡可以是 1, 2, 3....隨你高興。

接著編輯要被綁訂的網卡介面,這裡要綁訂的是 eth0 跟 eth1 所以就編輯這兩個檔囉:
[root@KHCDNSS01 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
# Broadcom Corporation NetXtreme II BCM5708 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:22:19:50:BC:7E
ONBOOT=yes
MASTER=bond0
SLAVE=yes

USERCTL=no
[root@KHCDNSS01 ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1
# Broadcom Corporation NetXtreme II BCM5708 Gigabit Ethernet
DEVICE=eth1
BOOTPROTO=none
HWADDR=00:22:19:50:BC:80
ONBOOT=yes
MASTER=bond0
SLAVE=yes

USERCTL=no
[root@KHCDNSS01 ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=KHCDNSS01
GATEWAY=10.15.25.254
再來是編輯 /etc/modprobe.conf 檔案:(這個檔案在 RHEL3 是在:/etc/modules.conf 而在 RHEL4 以後的版本則在:/etc/modprobe.conf)
[root@KHCDNSS01 ~]# vi /etc/modprobe.conf
alias eth0 bnx2
alias eth1 bnx2
alias scsi_hostadapter megaraid_sas
alias scsi_hostadapter1 ata_piix
alias bond0 bonding
options bond0 miimon=100
P.S. 這裡要注意一下喔,假如你想綁兩個以上的話,那 option 這一行的後面要再多加一個選項喔:max_bonds=3,這代表我要將三個網卡綁成一個 Channel...像下面這樣:
options bond0 miimon=100 max_bonds=3
接著只要重啟一下網路就行了,在這之前我們先看一下目前的網路狀況:
[root@KHCDNSS01 ~]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:22:19:50:BC:7E
inet addr:10.15.25.13 Bcast:10.15.25.255 Mask:255.255.255.0
inet6 addr: fe80::222:19ff:fe50:bc7e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:48374222 errors:0 dropped:0 overruns:0 frame:0
TX packets:4928117 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3254586862 (3.0 GiB) TX bytes:561588414 (535.5 MiB)
Interrupt:169 Memory:f8000000-f8012100

eth1 Link encap:Ethernet HWaddr 00:22:19:50:BC:80
inet6 addr: fe80::222:19ff:fe50:bc80/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:12 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:128 (128.0 b) TX bytes:3354 (3.2 KiB)
Interrupt:169 Memory:f4000000-f4012100

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:27284 errors:0 dropped:0 overruns:0 frame:0
TX packets:27284 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:19766775 (18.8 MiB) TX bytes:19766775 (18.8 MiB)

sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
接著我們就重啟一下網路吧:
[root@KHCDNSS01 ~]# service network restart
Shutting down interface eth0: /etc/sysconfig/network-scripts/ifdown-eth: line 101: /sys/class/net/bond0/bonding/slaves: No such file or directory
[ OK ]
Shutting down interface eth1: /etc/sysconfig/network-scripts/ifdown-eth: line 101: /sys/class/net/bond0/bonding/slaves: No such file or directory
[ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface bond0: [ OK ]
[root@KHCDNSS01 ~]#
剛設定完 Channel Bonding 後的第一次重啟看到的這些錯誤訊息是正常的,下次再重啟就不會在看到這些訊息了...我們先看一下 Bonding 的狀態吧:
[root@KHCDNSS01 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28, 2008)

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:22:19:50:bc:7e

Slave Interface: eth1
MII Status: up
Link Failure Count: 0
Permanent HW addr: 00:22:19:50:bc:80
我們順便看一下網路卡的狀況吧:
[root@KHCDNSS01 ~]# mii-tool -v
eth0: negotiated 100baseTx-FD, link ok
product info: vendor 00:08:18, model 54 rev 6
basic mode: autonegotiation enabled
basic status: autonegotiation complete, link ok
capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
eth1: negotiated 100baseTx-FD, link ok
product info: vendor 00:08:18, model 54 rev 6
basic mode: autonegotiation enabled
basic status: autonegotiation complete, link ok
capabilities: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
advertising: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
link partner: 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
[root@KHCDNSS01 ~]# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: g
Wake-on: d
Link detected: yes
[root@KHCDNSS01 ~]# ethtool eth1
Settings for eth1:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: g
Wake-on: d
Link detected: yes
[root@KHCDNSS01 ~]#
再來我們看一下目前網卡的 IP 為何:是不是多了一個 bond0 的介面了啊?
[root@KHCDNSS01 ~]# ifconfig -a
bond0 Link encap:Ethernet HWaddr 00:22:19:50:BC:7E
inet addr:10.15.25.13 Bcast:10.15.25.255 Mask:255.255.255.0
inet6 addr: fe80::222:19ff:fe50:bc7e/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:42 errors:0 dropped:0 overruns:0 frame:0
TX packets:76 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8088 (7.8 KiB) TX bytes:20800 (20.3 KiB)

eth0 Link encap:Ethernet HWaddr 00:22:19:50:BC:7E
inet6 addr: fe80::222:19ff:fe50:bc7e/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:23 errors:0 dropped:0 overruns:0 frame:0
TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4548 (4.4 KiB) TX bytes:10601 (10.3 KiB)
Interrupt:169 Memory:f8000000-f8012100

eth1 Link encap:Ethernet HWaddr 00:22:19:50:BC:7E
inet6 addr: fe80::222:19ff:fe50:bc7e/64 Scope:Link
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:19 errors:0 dropped:0 overruns:0 frame:0
TX packets:36 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3540 (3.4 KiB) TX bytes:10199 (9.9 KiB)
Interrupt:169 Memory:f4000000-f4012100

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:27284 errors:0 dropped:0 overruns:0 frame:0
TX packets:27284 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:19766775 (18.8 MiB) TX bytes:19766775 (18.8 MiB)

sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[root@KHCDNSS01 ~]#
接著我們做個小試驗,把 eth0 跟 eth1 的網路線拔插個幾次看看,我發現每次的拔插大概掉一個封包,所以兩條網路線各五次的拔插共掉了 10 個封包,不過 session 倒是不會斷:
[root@KHCDNSS01 ~]# cat /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.2.4 (January 28, 2008)

Bonding Mode: load balancing (round-robin)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0

Slave Interface: eth0
MII Status: up
Link Failure Count: 5
Permanent HW addr: 00:22:19:50:bc:7e

Slave Interface: eth1
MII Status: up
Link Failure Count: 5
Permanent HW addr: 00:22:19:50:bc:80
[root@KHCDNSS01 ~]#
以上,報告完畢~
(詳全文...)

要如何在 Linux 和 Solaris 上 capture the network packets?

之前寫到過在 linux 機器上面跑 Ethereal 來抓封包,不過這 Ethereal 都已經進版到 Wireshark 了,所以乾脆再把這方便的指令記錄一下當作備檔,順便也列一下幾個好用的抓封包的指令來做為參考:

首先是 Wireshark,在這裡因為機器多半跑在 run level 3 ,所以我還是用指令來秀就好,先看一下 tshark 有什麼用法:
Usage: tshark [options] ...

Capture interface:
-i (interface) name or idx of interface (def: first non-loopback)
-f (capture) packet filter in libpcap filter syntax
-s (snaplen) packet snapshot length (def: 65535)
-p don't capture in promiscuous mode
-y (link) link layer type (def: first appropriate)
-D print list of interfaces and exit
-L print list of link-layer types of iface and exit

Capture stop conditions:
-c (packet) stop after n packets (def: infinite)
-a (autostop) ... duration:NUM - stop after NUM seconds
filesize:NUM - stop this file after NUM KB
files:NUM - stop after NUM files
Capture output:
-b (ringbuffer) ... duration:NUM - switch to next file after NUM secs
filesize:NUM - switch to next file after NUM KB
files:NUM - ringbuffer: replace after NUM files
Input file:
-r (infile) set the filename to read from (no pipes or stdin!)

Processing:
-R (read) packet filter in Wireshark display filter syntax
-n disable all name resolutions (def: all enabled)
-N (name) enable specific name resolution(s): "mntC"
-d (layer_type)==(selector),(decode_as_protocol) ...
"Decode As", see the man page for details
Example: tcp.port==8888,http
Output:
-w (outfile|-) set the output filename (or '-' for stdout)
-F (output) set the output file type, default is libpcap
an empty "-F" option will list the file types
-V add output of packet tree (Packet Details)
-S display packets even when writing to a file
-x add output of hex and ASCII dump (Packet Bytes)
-T pdml|ps|psml|text|fields
format of text output (def: text)
-e (field) field to print if -Tfields selected (e.g. tcp.port);
this option can be repeated to print multiple fields
-E(fieldsoption)=(value) set options for output when -Tfields selected:
header=y|n switch headers on and off
separator=/t|/s|(char) select tab, space, printable character as separator
quote=d|s|n select double, single, no quotes for values
-t ad|a|r|d|dd|e output format of time stamps (def: r: rel. to first)
-l flush standard output after each packet
-q be more quiet on stdout (e.g. when using statistics)
-X (key):(value) eXtension options, see the man page for details
-z (statistics) various statistics, see the man page for details

Miscellaneous:
-h display this help and exit
-v display version info and exit
-o (name):(value) ... override preference setting
這裡秀了不少相關的參數,不過一般我們用不了這麼多,我就用最簡單的例子來示範一下就好:

下面這個範例示範最常用到就是抓 eth0 的封包並寫到 /tmp/test.cap 去:
[root@KHCDNSS01 ~]# tshark -i eth0 -w /tmp/test.cap
Running as user "root" and group "root". This could be dangerous.
Capturing on eth0
145
[root@KHCDNSS01 ~]#
如果要讀出這個 .cap 檔,可以用 -r 的參數,或者直接把檔案抓下來在自己的電腦上用 Wireshark 去開啟,不過有時就是急著要在機器上直接檢視所抓取的封包的結果,那就用 -S 吧,讓存檔的時候還順便把結果秀在螢幕上來檢視:
[root@KHCDNSS01 ~]# tshark -i eth0 -w /tmp/test.log -S
Running as user "root" and group "root". This could be dangerous.
Capturing on eth0
0.000000 IntelCor_11:57:ec -> UscInfor_00:00:00 LLC U, func=UI; SNAP, OUI 0x020000 (Unknown), PID 0x0001
0.013780 IntelCor_0c:9c:e3 -> UscInfor_00:00:00 LLC U, func=UI; SNAP, OUI 0x020000 (Unknown), PID 0x0001
0.019267 IntelCor_0c:5e:84 -> UscInfor_00:00:00 LLC U, func=UI; SNAP, OUI 0x020000 (Unknown), PID 0x0001
0.026100 IntelCor_0c:a2:40 -> UscInfor_00:00:00 LLC U, func=UI; SNAP, OUI 0x020000 (Unknown), PID 0x0001
0.106711 IntelCor_11:57:ec -> UscInfor_00:00:00 LLC U, func=UI; SNAP, OUI 0x020000 (Unknown), PID 0x0001
0.125997 IntelCor_0c:5e:84 -> UscInfor_00:00:00 LLC U, func=UI; SNAP, OUI 0x020000 (Unknown), PID 0x0001
0.149380 10.255.131.253 -> 10.15.25.13 NTP NTP client
0.149424 10.15.25.13 -> 10.255.131.253 NTP NTP server
0.213424 IntelCor_11:57:ec -> UscInfor_00:00:00 LLC U, func=UI; SNAP, OUI 0x020000 (Unknown), PID 0x0001
0.232625 IntelCor_0c:5e:84 -> UscInfor_00:00:00 LLC U, func=UI; SNAP, OUI 0x020000 (Unknown), PID 0x0001
0.321434 IntelCor_11:57:ec -> UscInfor_00:00:00 LLC U, func=UI; SNAP, OUI 0x020000 (Unknown), PID 0x0001
0.340753 IntelCor_0c:5e:84 -> UscInfor_00:00:00 LLC U, func=UI; SNAP, OUI 0x020000 (Unknown), PID 0x0001
0.428148 IntelCor_11:57:ec -> UscInfor_00:00:00 LLC U, func=UI; SNAP, OUI 0x020000 (Unknown), PID 0x0001
0.447482 IntelCor_0c:5e:84 -> UscInfor_00:00:00 LLC U, func=UI; SNAP, OUI 0x020000 (Unknown), PID 0x0001
14 packets captured
[root@KHCDNSS01 ~]#
不過這樣的封包訊息很難對時間對吧?那我們變換一下隊形,加上時間戳記在每個封包前面好了,這樣也比較方便檢視:
[root@KHCDNSS01 ~]# tshark -i eth1 -ta -w /tmp/test.log -S
Running as user "root" and group "root". This could be dangerous.
Capturing on eth1
22:52:38.637125 SunMicro_9b:ab:99 -> Broadcast ARP Who has 172.24.132.9? Tell 172.24.132.5
22:52:38.637154 SunMicro_9b:ab:99 -> Broadcast ARP Who has 172.24.132.7? Tell 172.24.132.5
22:52:38.642615 SunMicro_d0:3e:07 -> Broadcast ARP Who has 172.24.4.8? Tell 172.24.4.9
22:52:38.645906 SunMicro_1a:4e:3b -> Broadcast ARP Who has 172.24.4.87? Tell 172.24.4.84
22:52:38.646316 SunMicro_1a:b6:37 -> Broadcast ARP Who has 172.24.4.87? Tell 172.24.4.86
22:52:38.650723 172.24.128.202 -> 172.24.4.44 UDP Source port: 3020 Destination port: 34734
22:52:38.657893 172.24.4.7 -> 172.24.4.44 TCP 706 > login [ACK] Seq=0 Ack=0 Win=24820 Len=0
22:52:38.657904 172.24.4.44 -> 172.24.4.7 Rlogin Data: Capturing on eth0\r\n22:52:38.637125 SunMicro_9b:ab:99 -> Broadcast ARP Who has 172.24.132.9? Tell 172.24.132.5\r\n22:52:38.6371
22:52:38.672427 172.24.128.202 -> 172.24.4.44 UDP Source port: 3020 Destination port: 34732
再列出另一種我比較喜歡的時間格式:
[root@KHCDNSS01 ~]# tshark -i eth1 -tad -w /tmp/test.log -S
Running as user "root" and group "root". This could be dangerous.
Capturing on eth1
2009-04-26 22:57:47.071895 172.24.128.202 -> 172.24.4.44 UDP Source port: 3020 Destination port: 34732
2009-04-26 22:57:47.073645 172.24.128.202 -> 172.24.4.44 UDP Source port: 3020 Destination port: 34734
2009-04-26 22:57:47.089852 172.24.4.7 -> 172.24.4.44 TCP 706 > login [ACK] Seq=0 Ack=0 Win=24820 Len=0
2009-04-26 22:57:47.089863 172.24.4.44 -> 172.24.4.7 Rlogin Data: Capturing on eth0\r\n2009-04-26 22:57:47.071895 172.24.128.202 -> 172.24.4.44 UDP Source port: 3020 Destination port: 34732\r\n200
2009-04-26 22:57:47.098563 SunMicro_9b:ad:c9 -> Broadcast ARP Who has 172.24.132.9? Tell 172.24.132.2
2009-04-26 22:57:47.098599 SunMicro_9b:ad:c9 -> Broadcast ARP Who has 172.24.132.7? Tell 172.24.132.2
2009-04-26 22:57:47.116810 172.24.128.202 -> 172.24.4.44 UDP Source port: 3020 Destination port: 34732
2009-04-26 22:57:47.137607 172.24.4.14 -> 172.24.4.44 UDP Source port: 3020 Destination port: 34730
2009-04-26 22:57:47.138241 172.24.4.28 -> 172.24.4.44 UDP Source port: 3030 Destination port: 34726
不過這樣的封包訊息又太精簡了,看不習慣對吧,那我們再變換一下隊形,這樣應該會更方便檢視:(加上 -V 把封包的 detail 訊息秀出來,加上 -x 後把 output 用 hex 和 ASCII 給 dump 出來,現在是不是清楚多了?)
[root@KHCDNSS01 ~]# tshark -i eth0 -Vta -x
Running as user "root" and group "root". This could be dangerous.
Capturing on eth0
Frame 1 (104 bytes on wire, 104 bytes captured)
Arrival Time: Apr 26, 2009 18:56:34.406686000
[Time delta from previous captured frame: 0.000000000 seconds]
[Time delta from previous displayed frame: 0.000000000 seconds]
[Time since reference or first frame: 0.000000000 seconds]
Frame Number: 1
Frame Length: 104 bytes
Capture Length: 104 bytes
[Frame is marked: False]
[Protocols in frame: eth:llc:data]
IEEE 802.3 Ethernet
Destination: UscInfor_00:00:00 (01:00:5e:00:00:00)
Address: UscInfor_00:00:00 (01:00:5e:00:00:00)
.... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)
.... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
Source: IntelCor_11:57:ec (00:1c:c0:11:57:ec)
Address: IntelCor_11:57:ec (00:1c:c0:11:57:ec)
.... ...0 .... .... .... .... = IG bit: Individual address (unicast)
.... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
Length: 90
Logical-Link Control
DSAP: SNAP (0xaa)
IG Bit: Individual
SSAP: SNAP (0xaa)
CR Bit: Command
Control field: U, func=UI (0x03)
000. 00.. = Command: Unnumbered Information (0x00)
.... ..11 = Frame type: Unnumbered frame (0x03)
Organization Code: Unknown (0x020000)
Protocol ID: 0x0001
Data (82 bytes)
Data: 01011201020000635FFE001CC01157EC01800319112A0000...

0000 01 00 5e 00 00 00 00 1c c0 11 57 ec 00 5a aa aa ..^.......W..Z..
0010 03 02 00 00 00 01 01 01 12 01 02 00 00 63 5f fe .............c_.
0020 00 1c c0 11 57 ec 01 80 03 19 11 2a 00 00 00 00 ....W......*....
0030 00 00 00 00 00 05 0f 49 6e 74 65 72 4e 45 54 2d .......InterNET-
0040 50 72 69 2d 42 6b 00 00 00 1c c0 0c a2 40 00 00 Pri-Bk.......@..
0050 00 00 00 00 00 0c 11 86 f9 ba 00 07 29 5e 4f 88 ............)^O.
0060 4c c8 04 85 e2 ff c3 f9 L.......

Frame 2 (104 bytes on wire, 104 bytes captured)
Arrival Time: Apr 26, 2009 18:56:34.427783000
[Time delta from previous captured frame: 0.021097000 seconds]
[Time delta from previous displayed frame: 0.021097000 seconds]
[Time since reference or first frame: 0.021097000 seconds]
Frame Number: 2
Frame Length: 104 bytes
Capture Length: 104 bytes
[Frame is marked: False]
[Protocols in frame: eth:llc:data]
IEEE 802.3 Ethernet
Destination: UscInfor_00:00:00 (01:00:5e:00:00:00)
Address: UscInfor_00:00:00 (01:00:5e:00:00:00)
.... ...1 .... .... .... .... = IG bit: Group address (multicast/broadcast)
.... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
Source: IntelCor_0c:5e:84 (00:1c:c0:0c:5e:84)
Address: IntelCor_0c:5e:84 (00:1c:c0:0c:5e:84)
.... ...0 .... .... .... .... = IG bit: Individual address (unicast)
.... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
Length: 90
Logical-Link Control
DSAP: SNAP (0xaa)
IG Bit: Individual
SSAP: SNAP (0xaa)
CR Bit: Command
Control field: U, func=UI (0x03)
000. 00.. = Command: Unnumbered Information (0x00)
.... ..11 = Frame type: Unnumbered frame (0x03)
Organization Code: Unknown (0x020000)
Protocol ID: 0x0001
Data (82 bytes)
Data: 01011001020000DC8C04001CC00C5E84017F0318112A0000...

0000 01 00 5e 00 00 00 00 1c c0 0c 5e 84 00 5a aa aa ..^.......^..Z..
0010 03 02 00 00 00 01 01 01 10 01 02 00 00 dc 8c 04 ................
0020 00 1c c0 0c 5e 84 01 7f 03 18 11 2a 00 00 00 01 ....^......*....
0030 00 01 00 00 00 07 0d 41 53 4e 2d 53 65 63 2d 42 .......ASN-Sec-B
0040 72 69 63 6b 00 00 00 00 00 1c c0 0c 9c e3 00 00 rick............
0050 00 00 00 00 00 0c 11 86 f9 bb 00 05 e3 0c 4e a3 ..............N.
0060 fd 42 49 17 bb 9e bd 64 .BI....d

Frame 3 (90 bytes on wire, 90 bytes captured)
Arrival Time: Apr 26, 2009 18:56:34.444956000
[Time delta from previous captured frame: 0.017173000 seconds]
[Time delta from previous displayed frame: 0.017173000 seconds]
[Time since reference or first frame: 0.038270000 seconds]
Frame Number: 3
Frame Length: 90 bytes
Capture Length: 90 bytes
[Frame is marked: False]
[Protocols in frame: eth:ip:udp:ntp]
Ethernet II, Src: 02:00:00:dc:8c:04 (02:00:00:dc:8c:04), Dst: 00:22:19:50:bc:7e (00:22:19:50:bc:7e)
Destination: 00:22:19:50:bc:7e (00:22:19:50:bc:7e)
Address: 00:22:19:50:bc:7e (00:22:19:50:bc:7e)
.... ...0 .... .... .... .... = IG bit: Individual address (unicast)
.... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
Source: 02:00:00:dc:8c:04 (02:00:00:dc:8c:04)
Address: 02:00:00:dc:8c:04 (02:00:00:dc:8c:04)
.... ...0 .... .... .... .... = IG bit: Individual address (unicast)
.... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)
Type: IP (0x0800)
Internet Protocol, Src: 10.255.131.253 (10.255.131.253), Dst: 10.15.25.13 (10.15.25.13)
Version: 4
Header length: 20 bytes
Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)
0000 00.. = Differentiated Services Codepoint: Default (0x00)
.... ..0. = ECN-Capable Transport (ECT): 0
.... ...0 = ECN-CE: 0
Total Length: 76
Identification: 0x284a (10314)
Flags: 0x00
0... = Reserved bit: Not set
.0.. = Don't fragment: Not set
..0. = More fragments: Not set
Fragment offset: 0
Time to live: 27
Protocol: UDP (0x11)
Header checksum: 0xc53f [correct]
[Good: True]
[Bad : False]
Source: 10.255.131.253 (10.255.131.253)
Destination: 10.15.25.13 (10.15.25.13)
User Datagram Protocol, Src Port: ntp (123), Dst Port: ntp (123)
Source port: ntp (123)
Destination port: ntp (123)
Length: 56
Checksum: 0x4170 [correct]
[Good Checksum: True]
[Bad Checksum: False]
Network Time Protocol
Flags: 0x0b
00.. .... = Leap Indicator: no warning (0)
..00 1... = Version number: reserved (1)
.... .011 = Mode: client (3)
Peer Clock Stratum: unspecified or unavailable (0)
Peer Polling Interval: invalid (0)
Peer Clock Precision: 1.000000 sec
Root Delay: 0.0000 sec
Root Dispersion: 0.0000 sec
Reference Clock ID: NULL
Reference Clock Update Time: NULL
Originate Time Stamp: NULL
Receive Time Stamp: NULL
Transmit Time Stamp: NULL

0000 00 22 19 50 bc 7e 02 00 00 dc 8c 04 08 00 45 00 .".P.~........E.
0010 00 4c 28 4a 00 00 1b 11 c5 3f 0a ff 83 fd 0a 0f .L(J.....?......
0020 19 0d 00 7b 00 7b 00 38 41 70 0b 00 00 00 00 00 ...{.{.8Ap......
0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0050 00 00 00 00 00 00 00 00 00 00 ..........
對了,補充一下,當在抓封包時在 /var/log/messages 裡面常會出現一堆如下所列的訊息:
kernel: device eth0 entered promiscuous mode
kernel: device eth0 left promiscuous mode
這代表你的網卡處於"混雜模式時",在同一個 broadcast segment 下的封包,都會被監聽,如果你的 LAN 是用 HUB 來接,那整個 LAN 的封包都會被監聽,若你的 LAN 是用 switch 接,一般來說就只能看到自己和 broadcast 的封包。

假如你不想在 /var/log/messages 裡面再看到這些訊息的話,可以再加上一個 -p 的參數,就好了...

當然如果還要加上一些 filter 的話就只需依想要過濾的條件去設定就行了,舉例來說,我想過濾只抓關於 RTSP 的封包就好:
[root@KHCDNSS01 ~]# tshark -i eth1 -Vtad -x -p port rtsp
Running as user "root" and group "root". This could be dangerous.
Capturing on eth1
Frame 1 (74 bytes on wire, 74 bytes captured)
Arrival Time: Apr 26, 2009 23:39:12.773857000
Time delta from previous packet: 0.000000000 seconds
Time since reference or first frame: 0.000000000 seconds
Frame Number: 1
Packet Length: 74 bytes
Capture Length: 74 bytes
Protocols in frame: eth:ip:tcp
Ethernet II, Src: 00:15:60:a3:f4:67, Dst: 00:15:60:a3:f8:e5
Destination: 00:15:60:a3:f8:e5 (00:15:60:a3:f8:e5)
Source: 00:15:60:a3:f4:67 (00:15:60:a3:f4:67)
Type: IP (0x0800)
Internet Protocol, Src Addr: 172.24.4.44 (172.24.4.44), Dst Addr: 172.24.4.14 (172.24.4.14)
Version: 4
Header length: 20 bytes
Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)
0000 00.. = Differentiated Services Codepoint: Default (0x00)
.... ..0. = ECN-Capable Transport (ECT): 0
.... ...0 = ECN-CE: 0
Total Length: 60
Identification: 0x03e6 (998)
Flags: 0x04 (Don't Fragment)
0... = Reserved bit: Not set
.1.. = Don't fragment: Set
..0. = More fragments: Not set
Fragment offset: 0
Time to live: 64
Protocol: TCP (0x06)
Header checksum: 0xd66b (correct)
Source: 172.24.4.44 (172.24.4.44)
Destination: 172.24.4.14 (172.24.4.14)
Transmission Control Protocol, Src Port: 57606 (57606), Dst Port: rtsp (554), Seq: 0, Ack: 0, Len: 0
Source port: 57606 (57606)
Destination port: rtsp (554)
Sequence number: 0 (relative sequence number)
Header length: 40 bytes
Flags: 0x0002 (SYN)
0... .... = Congestion Window Reduced (CWR): Not set
.0.. .... = ECN-Echo: Not set
..0. .... = Urgent: Not set
...0 .... = Acknowledgment: Not set
.... 0... = Push: Not set
.... .0.. = Reset: Not set
.... ..1. = Syn: Set
.... ...0 = Fin: Not set
Window size: 5792
Checksum: 0x57d2 (correct)
Options: (20 bytes)
Maximum segment size: 1460 bytes
SACK permitted
Time stamp: tsval 2080473562, tsecr 2080479415
NOP
Window scale: 0 (multiply by 1)

0000 00 15 60 a3 f8 e5 00 15 60 a3 f4 67 08 00 45 00 ..`.....`..g..E.
0010 00 3c 03 e6 40 00 40 06 d6 6b ac 18 04 2c ac 18 .(..@.@..k...,..
0020 04 0e e1 06 02 2a 01 28 82 3c 00 00 00 00 a0 02 .....*.(.(......
0030 16 a0 57 d2 00 00 02 04 05 b4 04 02 08 0a 7c 01 ..W...........|.
0040 81 da 7c 01 98 b7 01 03 03 00 ..|.......
綜合以上所說的,其實我一般最常用的便是類似下面組合起來的 command 囉:
[root@KHCDNSS01 ~]# tshark -i eth0 -Vtad -x icmp -p -w /tmp/test.log -S
Running as user "root" and group "root". This could be dangerous.
Capturing on eth0
Frame 1 (98 bytes on wire, 98 bytes captured)
Arrival Time: Apr 27, 2009 10:53:50.326876000
[Time delta from previous captured frame: 0.000000000 seconds]
[Time delta from previous displayed frame: 0.000000000 seconds]
[Time since reference or first frame: 0.000000000 seconds]
Frame Number: 1
Frame Length: 98 bytes
Capture Length: 98 bytes
[Frame is marked: False]
[Protocols in frame: eth:ip:icmp:data]
Ethernet II, Src: 00:22:19:50:bc:7e (00:22:19:50:bc:7e), Dst: All-HSRP-routers_04 (00:00:0c:07:ac:04)
Destination: All-HSRP-routers_04 (00:00:0c:07:ac:04)
Address: All-HSRP-routers_04 (00:00:0c:07:ac:04)
.... ...0 .... .... .... .... = IG bit: Individual address (unicast)
.... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
Source: 00:22:19:50:bc:7e (00:22:19:50:bc:7e)
Address: 00:22:19:50:bc:7e (00:22:19:50:bc:7e)
.... ...0 .... .... .... .... = IG bit: Individual address (unicast)
.... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
Type: IP (0x0800)
Internet Protocol, Src: 10.15.25.13 (10.15.25.13), Dst: 192.168.161.5 (192.168.161.5)
Version: 4
Header length: 20 bytes
Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)
0000 00.. = Differentiated Services Codepoint: Default (0x00)
.... ..0. = ECN-Capable Transport (ECT): 0
.... ...0 = ECN-CE: 0
Total Length: 84
Identification: 0x0000 (0)
Flags: 0x04 (Don't Fragment)
0... = Reserved bit: Not set
.1.. = Don't fragment: Set
..0. = More fragments: Not set
Fragment offset: 0
Time to live: 64
Protocol: ICMP (0x01)
Header checksum: 0xb5df [correct]
[Good: True]
[Bad : False]
Source: 10.15.25.13 (10.15.25.13)
Destination: 192.168.161.5 (192.168.161.5)
Internet Control Message Protocol
Type: 8 (Echo (ping) request)
Code: 0 ()
Checksum: 0x866f [correct]
Identifier: 0x7a27
Sequence number: 1 (0x0001)
Data (56 bytes)
Data: 3E1EF549D4FC040008090A0B0C0D0E0F1011121314151617...

0000 00 00 0c 07 ac 04 00 22 19 50 bc 7e 08 00 45 00 .......".P.~..E.
0010 00 54 00 00 40 00 40 01 b5 df 0a 0f 19 0d c0 a8 .T..@.@.........
0020 a1 05 08 00 86 6f 7a 27 00 01 3e 1e f5 49 d4 fc .....oz'..)..I..
0030 04 00 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 ................
0040 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 .......... !"#$%
0050 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 &'()*+,-./012345
0060 36 37 67

1 packets captured
[root@KHCDNSS01 ~]#
既然說到在 Linux 上使用 Wireshark, 那在 Solaris 上面呢?簡單來說你可以使用 snoop 跟 tcpdump,不過個人是偏好 snoop 啦,下面先簡單列一下可用的選項:
Usage: snoop
[ -a ] # Listen to packets on audio
[ -d device ] # Listen on interface named device
[ -s snaplen ] # Truncate packets
[ -c count ] # Quit after count packets
[ -P ] # Turn OFF promiscuous mode
[ -D ] # Report dropped packets
[ -S ] # Report packet size
[ -i file ] # Read previously captured packets
[ -o file ] # Capture packets in file
[ -n file ] # Load addr-to-name table from file
[ -N ] # Create addr-to-name table
[ -t r|a|d ] # Time: Relative, Absolute or Delta
[ -v ] # Verbose packet display
[ -V ] # Show all summary lines
[ -p first[,last] ] # Select packet(s) to display
[ -x offset[,length] ] # Hex dump from offset for length
[ -C ] # Print packet filter code
[ -q ] # Suppress printing packet count
[ -r ] # Do not resolve address to name

[ filter expression ]
其實簡單說起來,用法跟 Wireshark 大同小異啦,比方說,下面是我常用的一個指令,用來檢查 NTP client 有沒有過來做 NTP 的同步,當然也可以把 filter 的部分改成其他的用法,比方說用 "bootp" 來取代掉 "port ntp" 的部分,就可以檢查 DHCP Client 有沒有來 request IP...其他的選項部分跟 Wireshark 其實差異不大,-d 是用來指定抓封包的 interface,-P 一樣可以避免網卡處於"混雜模式",-r 是不要解析 IP address,-v 是秀出詳細的 packet,而 -ta 則是秀出時間戳記.....
47ksh# snoop -vVta -r -d bge0 -P -x5 port ntp
Using device /dev/bge0 (non promiscuous)
ETHER: ----- Ether Header -----
ETHER:
ETHER: Packet 11 arrived at 18:21:4.42140
ETHER: Packet size = 90 bytes
ETHER: Destination = 0:14:4f:a9:83:50,
ETHER: Source = 0:1a:f0:bc:b6:6d,
ETHER: Ethertype = 0800 (IP)
ETHER:
IP: ----- IP Header -----
IP:
IP: Version = 4
IP: Header length = 20 bytes
IP: Type of service = 0xc0
IP: xxx. .... = 6 (precedence)
IP: ...0 .... = normal delay
IP: .... 0... = normal throughput
IP: .... .0.. = normal reliability
IP: .... ..0. = not ECN capable transport
IP: .... ...0 = no ECN congestion experienced
IP: Total length = 76 bytes
IP: Identification = 0
IP: Flags = 0x0
IP: .0.. .... = may fragment
IP: ..0. .... = last fragment
IP: Fragment offset = 0 bytes
IP: Time to live = 254 seconds/hops
IP: Protocol = 17 (UDP)
IP: Header checksum = 757e
IP: Source address = 10.16.25.34, 10.16.25.34
IP: Destination address = 10.17.25.32, 10.17.25.32
IP: No options
IP:
UDP: ----- UDP Header -----
UDP:
UDP: Source port = 123
UDP: Destination port = 123 (NTP)
UDP: Length = 56
UDP: Checksum = F8E2
UDP:
NTP: ----- Network Time Protocol -----
NTP:
NTP: Leap = 0x0 (OK)
NTP: Version = 3
NTP: Mode = 3 (client)
NTP: Stratum = 3 (secondary reference)
NTP: Poll = 6
NTP: Precision = 238 seconds
NTP: Synchronizing distance = 0x0000.0064 (0.001526)
NTP: Synchronizing dispersion = 0x0000.040d (0.015823)
NTP: Reference clock = 10.17.25.32 (10.17.25.32)
NTP: Reference time = 0xcda00550.6bbe484f (2009-04-27 18:20:00.42087)
NTP: Originate time = 0xcda00550.6b9f8000 (2009-04-27 18:20:00.42040)
NTP: Receive time = 0xcda00550.6bbe484f (2009-04-27 18:20:00.42087)
NTP: Transmit time = 0xcda00590.6bc46a2c (2009-04-27 18:21:04.42097)


0: 8350 001a f0bc b66d 0800 45c0 004c 0000 .P.....m..E..L..
16: 0000 fe11 757e 0a10 1922 0a11 1920 007b ....u~..."... .{
32: 007b 0038 f8e2 1b03 06ee 0000 0064 0000 .{.8.........d..
48: 040d 0a11 1920 cda0 0550 6bbe 484f cda0 ..... .?.Pk.HO.?
64: 0550 6b9f 8000 cda0 0550 6bbe 484f cda0 .Pk?...?.Pk.HO.?
80: 0590 6bc4 6a2c ..k.j,

^C
root@KHXDNSS1:/etc/domain
好囉,就先寫到這兒吧~

---------- 補充於 2009/04/30 -------------
追加補充個我常用的 filer,因為常需要分析 AAA server 間的 Radius protocol,所以常會這麼下指令:(這些是在 Linux OS 上的指令)
[root@TEST01 ~]# tshark -Vtad -p -i bond1 -x -z "radius,rtd,ip.addr==xx.xx.xx.xx" -w /tmp/AAA-radius.cap -S
或者是:
[root@TEST01 ~]# tshark -Vtad -p -i bond1 -x -z radius,rtd. -w /tmp/AAA-radius.cap -S
又或者是乾脆就這麼用:
[root@TEST01 ~]# tshark -Vtad -p -i bond1 -x port radius -w /tmp/AAA-radius.cap -S
對了,加上這個 -z 的參數,在抓完封包時,會多出如下的處理訊息:
RADIUS Response Time Delay (RTD) Statistics:
Filter for statistics:
Duplicate requests: 3
Duplicate responses: 0
Open requests: 3
Discarded responses: 0
Type | Messages | Min RTD | Max RTD | Avg RTD | Min in Frame | Max in Frame |
Overall | 1 | 1.53 msec | 1.53 msec | 1.53 msec | 11 | 11 |
Access | 1 | 1.53 msec | 1.53 msec | 1.53 msec | 11 | 11 |
OK,補充完畢...
(詳全文...)

Many ntpd "Invalid argument" messages in /var/log/messages

今天檢查機器時發現 /var/log/messages 裡面有一大堆 ntpd 的 "Invalid argument" 訊息,才想到前兩天把這兩台機器的 IP address 變更網段後,只有重啟 network 的 service,忘了把 ntpd 也重啟,幾天沒連線倒是在 log 檔多了一大票的錯誤訊息,以前這種訊息多半是在 ADSL 撥接 Dynamic IP 的 interface 上發生,因為有時撥接斷線後重新撥接,然後這個 interface 上的 IP address 通常就變動了,然後這個錯誤訊息就會發生囉,最簡單的解決方法就是把 ntpd 重啟一下吧~

首先看一下,這就是一直重複出現的訊息:
[root@KHCBKPS01 ~]# tail -3 /var/log/messages
Mar 18 10:18:47 KHCBKPS01 ntpd[5137]: sendto(10.15.25.13) (fd=21): Invalid argument
Mar 18 10:35:53 KHCBKPS01 ntpd[5137]: sendto(10.15.25.13) (fd=21): Invalid argument
Mar 18 10:52:58 KHCBKPS01 ntpd[5137]: sendto(10.15.25.13) (fd=21): Invalid argument
OK,現在將 ntpd 重啟吧:
[root@KHCBKPS01 ~]# service ntpd restart
Shutting down ntpd: [ OK ]
ntpd: Synchronizing with time server: [ OK ]
Starting ntpd: [ OK ]
在 restart ntpd 時順便看一下 log 檔:
[root@KHCBKPS01 ~]# tail -f /var/log/messages
Mar 18 11:02:35 KHCBKPS01 ntpd[5137]: ntpd exiting on signal 15
Mar 18 11:02:35 KHCBKPS01 ntpdate[9708]: step time server 10.15.25.13 offset 0.039707 sec
Mar 18 11:02:35 KHCBKPS01 ntpd[9710]: ntpd 4.2.2p1@1.1570-o Thu Jan 17 18:14:09 UTC 2008 (1)
Mar 18 11:02:35 KHCBKPS01 ntpd[9711]: precision = 1.000 usec
Mar 18 11:02:35 KHCBKPS01 ntpd[9711]: Listening on interface wildcard, 0.0.0.0#123 Disabled
Mar 18 11:02:35 KHCBKPS01 ntpd[9711]: Listening on interface wildcard, ::#123 Disabled
Mar 18 11:02:35 KHCBKPS01 ntpd[9711]: Listening on interface lo, ::1#123 Enabled
Mar 18 11:02:35 KHCBKPS01 ntpd[9711]: Listening on interface eth1, xxxx::xxx:xxxx:xxxx:xxxx#123 Enabled
Mar 18 11:02:35 KHCBKPS01 ntpd[9711]: Listening on interface lo, 127.0.0.1#123 Enabled
Mar 18 11:02:35 KHCBKPS01 ntpd[9711]: Listening on interface eth1, aaa.bb.ccc.dd#123 Enabled
Mar 18 11:02:35 KHCBKPS01 ntpd[9711]: kernel time sync status 0040
Mar 18 11:02:35 KHCBKPS01 ntpd[9711]: frequency initialized 52.117 PPM from /var/lib/ntp/drift
Mar 18 11:05:48 KHCBKPS01 ntpd[9711]: synchronized to 10.15.25.13, stratum 5
Mar 18 11:05:48 KHCBKPS01 ntpd[9711]: kernel time sync disabled 0001
觀察一段時間,已經和 NTP server 同步了,發現 /var/log/messages 檔也不再出現 "Invalid argument" 訊息囉,既然講到 NTP,那就順便把跟 NTP 相關幾個有用的指令也列一下好了:
[root@KHCBKPS01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
=========================================
*KHCDNSS01 LOCAL(0) 5 u 25 64 17 0.212 -0.532 0.347
[root@KHCBKPS01 ~]# ntpq
ntpq> association

ind assID status conf reach auth condition last_event cnt
=========================================
1 38739 9624 yes yes none sys.peer reachable 2
ntpq> quit
[root@KHCBKPS01 ~]# ntpstat
synchronised to NTP server (10.15.25.13) at stratum 6
time correct to within 951 ms
polling server every 64 s
[root@KHCBKPS01 ~]# ntpdc -c kerninfo
pll offset: -0.00049 s
pll frequency: 52.583 ppm
maximum error: 0.013646 s
estimated error: 0.000188 s
status: 0001 pll
pll time constant: 2
precision: 1e-06 s
frequency tolerance: 512 ppm
[root@KHCBKPS01 ~]# ntpdc -c sysinfo
system peer: KHCDNSS01
system peer mode: client
leap indicator: 00
stratum: 6
precision: -20
root distance: 0.00017 s
root dispersion: 0.20419 s
reference ID: [10.15.25.13]
reference time: cd6b4bfa.65ce0142 Wed, Mar 18 2009 18:31:22.397
system flags: auth monitor ntp kernel stats
jitter: 0.000214 s
stability: 0.000 ppm
broadcastdelay: 0.003998 s
authdelay: 0.000000 s
(詳全文...)

RHEL 5 上要如何用 XDMCP 方式 Remote Login?

在之前的文章中我們用 X-Manager 示範過怎麼去連上 Linux 機器的 XDMCP session (請參考:以 X-Manager 來連 Linux 的圖形介面) ,不過當時的 OS 為 RHEL 4 ES,這次的幾台機器改成 RHEL 5 之後,可不能直接照著同樣的步驟改了,因為那樣是不 work 的啦....

其實在 RHEL 5 上只要修改一個檔案就可以達到這個目的,修改 /etc/gdm/custom.conf 文件,在 [xdmcp] 這行下加入了 Enable=1 或者 Enable=true,如果在這時存檔離開,並重新開機的話,其實已經可以用 X-Manager 來連線了,但卻只能用 SSH 的方式,而用 XDMCP session 則會出現不允許 remote system administrator login 的訊息,這不是我們要的結果,所以在剛剛的 /etc/gdm/custom.conf 文件中,我們這次修改三個段落:
[daemon]
RemoteGreeter=/usr/libexec/gdmgreeter
[security]
AllowRemoteRoot=true
[xdmcp]
Enable=true
[gui]
[greeter]
[chooser]
[debug]
一樣,修改完後存檔離開並重新開機,然後我們再試一次看看,前面如何建立一個 XDMCP session 的步驟請先參考上一篇 以 X-Manager 來連 Linux 的圖形介面,這次有正常看到如本機般的登入畫面了吧:

其實,剛剛修改 /etc/gdm/custom.conf 的選項中的第一行 [daemon] 部分也可以透過修改下面圖片所示的地方來達成:
1. 首先到 System > Administration > Login Screen:
2. 接著到 Remote tab 的 Style 中下拉式選單選擇 "Same as Local":
3. 接著移到 Security tab 的 Security 選項將 "Allow remote system administrator login" 勾選起來吧(這裡便是剛剛修改 /etc/gdm/custom.conf 的 [security] 部分):
4. 然後就是重新開機之後便可用 X-Manager 以 XDMCP session 連進去囉...搞定,收工~
(詳全文...)

要怎麼在 RHEL 5 上面架 DNS server 啊?

最近裝的幾台機器都是 RHEL5 的,而 RHEL5 跟之前用的 RHEL4 在架設 DNS Server 的時候,差異還真是不小啊,預設的 Zone files 和 Configuration file 呢?阿怎麼都找不到啊?該不是還要我自己一個檔一個檔的產生吧?當然不會啦,原來是一般安裝沒有裝到 system-config-bind, bind 及 bind-chroot 套件罷了,好吧,那就一步一步來吧~

步驟1. 先安裝一下相關的套件囉:
1-1. 安裝 system-config-bind 套件來產生 named.conf 範例檔:
[root@KHCDNSS02 ~]# yum install system-config-bind
1-2. 安裝 bind 及 bind-chroot 套件
[root@KHCDNSS02 ~]# yum groupinstall "DNS Name Server"

步驟2. 再來就是複製相關的檔案到 Bind Chroot 目錄 /var/named/chroot/ 下:
2-1. 先複製 named.conf 範例檔:
[root@KHCDNSS02 ~]# cp -p /usr/share/system-config-bind/profiles/default/named.conf /var/named/chroot/etc/
2-2. 複製相關 zone files 範例檔至 bind chroot 目錄下:
[root@KHCDNSS02 ~]# cp -p /usr/share/system-config-bind/profiles/default/named/* /var/named/chroot/var/named/
2-3. 複製 bind root 檔至 bind chroot 目錄下:
[root@KHCDNSS02 ~]# cp -p /usr/share/doc/bind-9.3.3/sample/var/named/named.root /var/named/chroot/var/named/
2-4. 把 owner 更改為 named:
[root@KHCDNSS02 ~]# chown -R named /var/named/chroot
2-5. 最後再把 named.conf 建立連結到 /etc 下:
[root@KHCDNSS02 ~]# ln -s /var/named/chroot/etc/named.conf /etc/named.conf
步驟3. 再來就是開始編輯 named.conf 檔的內容了:
[root@KHCDNSS02 ~]#vi /var/named/chroot/etc/named.conf
步驟4. 最後是新增需要用的網域正反解的 zone files 囉~

當然,如果也可以用圖形化的介面來配置 DNS 啦,點擊面版上的 System > Administration > Server Settings > Domain Name System 如下圖所示:進去之後便可以看到圖形化的配置畫面囉,剩下的就是慢慢設定了:
註解一下:為了不要每次切換到 zone files 所在的區域時都要敲一大串字,所以決定偷懶設定個 alias 如下:1. 編輯一下 ~/.bashrc 檔:
[root@KHCDNSS02 chroot]# vi ~/.bashrc
2. 加入下面這一行:
alias cdn='cd /var/named/chroot/var/named/; echo -n "Current PATH : ";pwd'
3. 登出再登入一次,測試一下 cdn 這個指令:
[root@KHCDNSS02 chroot]# cdn
Current PATH : /var/named/chroot/var/named
[root@KHCDNSS02 named]# ls -al
total 64
drwxr-x--- 4 named named 4096 Mar 4 22:20 .
drwxr-x--- 6 named named 4096 Feb 19 05:20 ..
drwxrwx--- 2 named named 4096 Aug 26 2004 data
-rw-r--r-- 1 named root 208 Mar 4 22:20 localdomain.zone
-rw-r--r-- 1 named root 195 Mar 4 22:20 localhost.zone
-rw-r--r-- 1 named root 427 Mar 4 22:20 named.broadcast
-rw-r--r-- 1 named root 1266 Mar 4 22:20 named.conf
-rw-r--r-- 1 named root 424 Mar 4 22:20 named.ip6.local
-rw-r--r-- 1 named root 426 Mar 4 22:20 named.local
-rw-r--r-- 1 named root 1892 Mar 4 22:13 named.root
-rw-r--r-- 1 named root 427 Mar 4 22:20 named.zero
drwxrwx--- 2 named named 4096 Jul 27 2004 slaves
[root@KHCDNSS02 named]#
這樣很方便吧~
(詳全文...)

忘記 Linux Server 上 root 用戶的密碼怎麼辦?

今天在機房接到同事來電問說某台機器 root 的 password 是什麼?啥?沒人記得喔?啊ㄌㄟ,真是糟糕,猜一下常用的密碼,發現依然登入不了,這可怎麼辦ㄌㄟ?

其實當忘記了 Linux Server 上的 root 密碼時,可以用以下面的方法來修復:
基本上這個方法適用於 GRUB,而 LILO 很久沒用過了,如果有人記得可以幫忙留個意見吧...

1. 首先就是重啟你那已經忘記密碼的機器,等到開機後,先停留在 GRUB 開機選單的畫面,移動到 linux 開機的選項上,按 e 編輯,我裝 RH EL5,所以選單像下面這樣:
GNU GRUB version 0.97C
Red Hat Enterprise Linux Server (2.6.18-92.el5) << 移到這裡按 e
Other
2. 等出下一頁選單,移動到 kernel 選項上,再按一次 e 編輯,像下面這樣:
root (hd0,2)
kernel /vmlinuz-2... ro root=/dev/VolGroup00/LogVol00 rhgb quiet << 按 e
initrd /initrd-2.6.18-92.el5.img
3. 等跳出下面一頁選單時,在 quiet 的後面先空一格,再加上 single,然後按 enter:
LogVol00 rhgb quiet single
4. 此時會回到上一頁的 GRUB 開機選單,按 b 即可 boot 到 single user mode 囉。

5. 進入單人模式後,用 passwd 的指令,即可更改 root 的密碼,然後重新開機就好囉,報告完畢~
(詳全文...)

Linux Server /var/spool/clientmqueue 目錄下產生大量文件的解決方法

今天在檢查兩台 AAA server 時才發現居然 / 已經到了 94% 了,SNMP server 上滿滿都是從這兩台機器上送來的 Alarm Traps;這可真是糟糕,趕快查一下到底是啥東西佔了這麼多硬碟空間...
[root@KHXAAAS2 ~]# df -h;
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 4.0G 3.6G 237M 94% /
/dev/sda1 1012M 40M 921M 5% /boot
none 4.0G 0 4.0G 0% /dev/shm
/dev/sda3 4.0G 41M 3.7G 2% /inactive_root
/dev/sda6 21G 78M 19G 1% /others
/NFSDB/radacct 537G 384M 509G 1% /opt/AAA-6.1.8-20081202/run/radacct
KHXDB:/DB/accounting 537G 384M 509G 1% /NFSDB/radacct
首先到 / 下面用 du -sh * 來查詢一下目前的 / 的使用狀態:
[root@KHXAAAS2 ~]# cd /
[root@KHXAAAS2 /]# du -sh *
5.6M bin
6.4M boot
216K dev
44M etc
32K home
20K inactive_root
8.0K initrd
97M lib
16K lost+found
16K media
8.0K misc
8.0K mnt
247M NFSDB

1.3G opt
2.0M others
du: cannot read directory `proc/857/task': No such file or directory
du: cannot read directory `proc/857/fd': No such file or directory
916M proc
2.0M root
176K rpm
18M sbin
0 selinux
8.0K srv
0 sys
336K tmp
2.0G usr

1.5G var
很明顯的,/opt 跟 /var 佔了很大的空間,/opt 我安裝了幾個大的 AAA service 在裡面,先慢點處理,這個 /var 佔據了 1.5G 實在有點奇怪了,繼續往下查...
[root@KHXAAAS2 /]# cd /var
[root@KHXAAAS2 var]# du -sh *
12K account
2.2M cache
16K crash
28K db
32K empty
16K ftp
300K gdm
41M lib
8.0K local
132K lock
42M log
4.0K mail
24K net-snmp
8.0K nis
8.0K opt
8.0K preserve
276K run

1.5G spool
8.0K tmp
8.0K tux
2.1M www
24K yp
看來 spool 的目錄下有問題,繼續...
[root@KHXAAAS2 var]# cd spool/
[root@KHXAAAS2 spool]# ls -al
total 6404
drwxr-xr-x 13 root root 4096 Jun 12 2008 .
drwxr-xr-x 23 root root 4096 Jun 12 2008 ..
drwxr-xr-x 2 root root 4096 Jun 12 2008 anacron
drwx------ 3 daemon daemon 4096 Jun 12 2008 at

drwxrwx--- 2 smmsp smmsp 6443008 Dec 24 12:53 clientmqueue
drwx------ 2 root root 4096 Dec 24 11:49 cron
drwx--x--- 3 root sys 4096 Jun 12 2008 cups
drwxr-xr-x 2 root root 4096 Aug 13 2004 lpd
drwxrwxr-x 2 root mail 4096 Aug 13 2004 mail
drwx------ 2 root mail 4096 Jan 23 2007 mqueue
drwxr-xr-x 2 rpm rpm 4096 Aug 2 2007 repackage
drwxr-xr-x 2 root root 4096 Sep 5 2007 up2date
drwxrwxrwt 2 root root 4096 Oct 5 2004 vbox

[root@KHXAAAS2 spool]# du -sh *
32K anacron
20K at

1.5G clientmqueue
16K cron
16K cups
8.0K lpd
8.0K mail
8.0K mqueue
8.0K repackage
8.0K up2date
8.0K vbox
[root@KHXAAAS2 spool]# cd clientmqueue/
[root@KHXAAAS2 clientmqueue]# du -sh *
-bash: /usr/bin/du: Argument list too long
看起來,這個 /var/spool/clientmqueue 的目錄下的東西太多了,連 du 的指令都下不了,我們用 ls 來看一下好了...
[root@KHXAAAS2 clientmqueue]# ls
dfm5C422X2007728 dfmA8CE2sU014445 dfmAQIX3He008540 dfmBF1O3tM024344 qfm9U9325M025071 qfmAHFp3o7008591 qfmB5MG2ik015455 dfm5D421x8008729 dfmA8CF2ex014725 dfmAQIY3JM008766 dfmBF1P2CK024575 qfm9U942p8025326 qfmAHFq22Z008848 qfmB5MH2dU015683 dfm5D4222i021334 dfmA8Cf2Oe022040 dfmAQIZ2lS008993 dfmBF1p2T6030541 qfm9U953gs025583 qfmAHFQ2RH002131 qfmB5Mh2Zw021688 dfm5DK23Jv003790 dfmA8CG2TR015000 dfmAQJ02LM014708 dfmBF1q22Z030769 qfm9U962PF025835 qfmAHFR22P002445 qfmB5Mi3jw021934 dfm5EK22jL009067 dfmA8Cg3uP022313 dfmAQJ13b6014942 dfmBF1Q2Tk024802 qfm9U972GP026084 qfmAHFr2PM009102 qfmB5MI3sc015914 dfm5OK314c006681 dfmA8Ch291022592 dfmAQJ23VT015171 dfmBF1r3jO030995 qfm9U983lb026334 qfmAHFs2XF009366 qfmB5MJ2hf016139 dfm5PK323O007690 dfmA8CH2so015312 dfmAQJ32Tu015402 dfmBF1R3xM025033 qfm9U992mX026621 qfmAHFS3sD002719 qfmB5Mj3Ia022161 dfm5QK32Ur008747 dfmA8Ci25T022861 dfmAQJ420C015631 dfmBF1s2LO031226 qfm9U9A20p026912 qfmAHFT2AP002970 qfmB5MK2P7016366 dfm5RK335g022157 dfmA8CI2UK015587 dfmAQJ52GN015858 dfmBF1S3st025260 qfm9U9a31w001040 qfmAHFt2ha009618 qfmB5Mk2SN022392 dfm5SK32xd023117 dfmA8Cj23T023137 dfmAQJ62Dm016089 dfmBF1T2Qt025491 qfm9U9B2aF027174 qfmAHFU2RT003229 qfmB5Ml2Ab022619 dfm5UK31gY007333 dfmA8CJ34Q015865 dfmAQJ72B4016316 dfmBF1t2RL031453 qfm9U9b2dR001296 qfmAHFu3dG009875 qfmB5ML2kM016594 dfm61K328o008143 dfmA8Ck20E023413 dfmAQJ82fO016547 dfmBF1U250025718 qfm9U9c22o001541 qfmAHFv30Z010126 qfmB5Mm2Gk022851 dfm62K32BT010023 dfmA8CK3r4016134 dfmAQJ93WG016775 dfmBF1u39e031684 qfm9U9C29A027419 qfmAHFV3pd003482 qfmB5MM2ZI016827 dfm63K32ia011151 dfmA8CL2dQ016417 dfmAQJa2On023080 dfmBF1v2Gh031911 qfm9U9d2Wa001793 qfmAHFW2J4003739 qfmB5Mn2fg023079 dfm64K32E5011955 dfmA8Cl3SM023691 dfmAQJA3DY017002 dfmBF1V2s6025962 qfm9U9D3p9027670 qfmAHFw2XB010386 qfmB5MN3Wi017052 dfm65K31uZ012771 dfmA8CM27o016689 dfmAQJB2YJ017245 dfmBF1w2pd032138 qfm9U9E2uC027923 qfmAHFX2Ep003993 qfmB5Mo3oH023305 dfm67K31mg029851 dfmA8Cm39g023966 dfmAQJb3pV023307 dfmBF1W2tF026190 qfm9U9e2Xh002049 qfmAHFx2kM010637 qfmB5MO3oS017280 dfm68K310Y030656 dfmA8CN2BY016971 dfmAQJC2qs017472 dfmBF1X3iF026417 qfm9U9F2kZ028177 qfmAHFY2Zm004250 qfmB5MP2jh017506 ^C
看起來真的是太多了,只好先用 Ctrl+C 中斷一下,不過幸好這些檔案產生的原因都是由於有某個用戶 (通常是 root 啦)新增了某個 cron job,而 cron job 裡面程序有輸出內容,這些內容會以 mail 的方式發給剛剛建立 cron job 的用戶,假如這時 sendmail 沒有啟動便會產生這些 queue 檔,基本上並不是什麼重要的檔案,一句話,殺無赦就對了~

不過由於這個目錄下的檔案太多,用 rm 的指令通常會得到像剛剛 du 所看到的錯誤訊息:
-bash: /bin/rm: Argument list too long
看來直接用 rm 是殺不掉了,沒關係,那就用下面的指令吧:
[root@KHXAAAS2 clientmqueue]# pwd
/var/spool/clientmqueue
[root@KHXAAAS2 clientmqueue]# ls | xargs rm -f
[root@KHXAAAS2 clientmqueue]# ls -al
total 6316
drwxrwx--- 2 smmsp smmsp 6443008 Dec 24 13:18 .
drwxr-xr-x 13 root root 4096 Jun 12 2008 ..
看吧,用了 ls | xargs rm -f 果然輕鬆的就殺掉這一堆的檔案囉,在檢查一下硬碟的使用狀況:
[root@KHXAAAS2 clientmqueue]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 4.0G 2.9G 956M 76% /
/dev/sda1 1012M 40M 921M 5% /boot
none 4.0G 0 4.0G 0% /dev/shm
/dev/sda3 4.0G 41M 3.7G 2% /inactive_root
/dev/sda6 21G 78M 19G 1% /others
/NFSDB/radacct 537G 384M 509G 1% /opt/AAA-6.1.8-20081202/run/radacct
KHXDB:/DB/accounting 537G 384M 509G 1% /NFSDB/radacct

[root@KHXAAAS2 clientmqueue]#
看吧,果然清空之後,使用空間多了很多...不過這只是治標,不是治本,重點是要記得去把那個兇手,也就是那個 cron job 的最後加上一段 > /dev/null 2>&1,例如:
[root@KHXAAAS2 ~]# crontab -l
* * * * * /etc/init.d/snmp_cron.sh > /dev/null 2>&1
這樣就可以避免問題再次重複發生囉...OK,報告完畢~
(詳全文...)