Tuesday, March 09, 2010

ITHome: 無線網路安全拉警報

詳見:

正所謂害人之心不可有,防人之心不可無,這是篇好文章,你還在使用WEP或是WPA-PSK嗎?趕緊更換policy吧!

帽客計畫用Aircrack-ng來破解WEP method看看,當然一定是破解我自己的AP囉。

Monday, March 08, 2010

Wednesday, March 03, 2010

RHEL6

首先,真是好久沒有寫blog了!不是帽客懶而是最近公司的project還蠻緊的,所以無暇更新腦中的知識於blog上。

今天下午稍可喘息,想想Redhat曾對外宣稱2010 Q1會發表RHEL6,可是現在怎麼還是沒消息呢?
上google找了找,看一看,目前最新的版本是RHEL 5.5 beta,然後RHEL6預計要在Fedora13後release。(for details: Redhat Enterprise Linux wiki

看來還得等一陣子。

Monday, February 01, 2010

買到國際版的Porter... Orz

帽客想說背個好一點的包包吧,加上目前在台灣Porter包還蠻多人背的,品質應該很不錯,結果上星期五跑去忠孝SOGO買了一款不便宜的Porter包(大約快六張小朋友),沒想到這是International Porter....老實說買之前我根本沒做功課,誰知道台灣與日本Porter會有這段恩怨呢?哈~苦笑中。

我現在只期望雖品質沒日製的好(網路上大家都這麼說 Orz),但也能讓我操個三年吧!暗藍色的顏色我還蠻喜歡的說,雖然它是International... 再次Orz.

Thursday, January 28, 2010

Apple iPad announced

Apple總算是對外發表了Apple iPad平板式電腦,成為世界第一的Mobile vendor後讓我們看看iPad是否也可以很成功!

Friday, January 22, 2010

強大的awk

透過awk找出系統帳號中誰的預設shell是屬於bash,並統計有幾筆。
[root@centos bin]# awk -F: 'BEGIN{count=0};/bash/{count++}/bash/{print $1};END{print "TOTAL="count}' /etc/passwd
root
u1
u2
law
mysql
TOTAL=5

Thursday, January 21, 2010

To setup IPSec in CentOS 5.4

這是一篇很精簡的設定方法,更詳細的步驟與說明建議還是至OpenSwan網站查詢。

Test Environment:
(172.17.1.100) IPSec VPN1 (10.12.95.3) ----- (10.12.95.2) IPSec VPN2 (172.17.2.100)

1. 安裝:
# yum install openswan*
2. 透過sysctl.conf修改Kernel參數:
修改Kernel相關參數,使得之後跑ipsec verify時不會出錯。
# vi /etc/sysctl.conf
*********************************************************************
# example entries for /etc/sysctl.conf
# forwarding is needed for subnet or l2tp connections
net.ipv4.ip_forward = 1

# rp_filter is stupid and cannot deal decrypted packets "appearing out of
# nowhere"
net.ipv4.conf.default.rp_filter = 0

# when using 1 interface for two networks, and in some other cases with
# NETKEY, the kernel thinks it can be clever but breaks things.
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.conf.all.log_martians = 0
net.ipv4.conf.default.log_martians = 0

# these are non-ipsec specific security policies you should use
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
*********************************************************************
#sysctl -p
3. 套用並修改範例:
# cp/usr/share/doc/openswan-doc*/examples /etc/ipsec.d/hosttohost.conf
# vi /etc/hosttohost.conf
*********************************************************************
# sample connections
# This file is RCSID $Id: examples,v 1.5 1999/12/13 02:38:16 henry Exp $

# sample tunnel (manually or automatically keyed)
# Here we just use ESP for both encryption and authentication, which is
# the simplest and often the best method.
conn sample
# left security gateway (public-network address)
left=10.12.95.3
# next hop to reach right
#leftnexthop=10.44.55.66
# subnet behind left (omit if left end of the tunnel is just the s.g.)
leftsubnet=172.17.1.0/24
# right s.g., subnet behind it, and next hop to reach left
right=10.12.95.2
#rightnexthop=10.88.77.66
rightsubnet=172.17.2.0/24
# (manual) SPI number
#spi=0x200
# (manual) encryption/authentication algorithm and parameters to it
esp=3des-md5-96
#espenckey=[192 bits]
#espauthkey=[128 bits]
authby=secret
auto=add
*********************************************************************
4. 新增PSK:
# vi /etc/ipsec.secrets
*********************************************************************
include /etc/ipsec.d/*.secrets
10.12.95.3 10.12.95.2 : PSK "1234567890"
10.12.95.2 10.12.95.3 : PSK "1234567890"
5. 修改/etc/ipsec.conf
# vi /etc/ipsec.conf
*********************************************************************
# /etc/ipsec.conf - Openswan IPsec configuration file
#
# Manual: ipsec.conf.5
#
# Please place your own config files in /etc/ipsec.d/ ending in .conf

version 2.0 # conforms to second version of ipsec.conf specification

# basic configuration
config setup
# Debug-logging controls: "none" for (almost) none, "all" for lots.
# klipsdebug=none
# plutodebug="control parsing"
# For Red Hat Enterprise Linux and Fedora, leave protostack=netkey
protostack=netkey
nat_traversal=yes
virtual_private=
oe=off
# Enable this if you see "failed to find any available worker"
nhelpers=0

#You may put your configuration (.conf) file in the "/etc/ipsec.d/" and uncomment this.
include /etc/ipsec.d/*.conf

PS. 另外一邊的VPN gateway與以上的架設方法都一樣,只是將/etc/hosttohost.conf中的left與right的資訊對調即可。

6. 啟動IPSec:
# /etc/init.d/ipsec start
/usr/libexec/ipsec/addconn Non-fips mode set in /proc/sys/crypto/fips_enabled
ipsec_setup: Starting Openswan IPsec U2.6.21/K2.6.18-164.6.1.el5...
ipsec_setup: multiple ip addresses, using 10.12.95.3 on eth0
ipsec_setup: /usr/libexec/ipsec/addconn Non-fips mode set in /proc/sys/crypto/fips_enabled

7. 執行IPSec verify:
# ipsec verify
Checking your system to see if IPsec got installed and started correctly:
Version check and ipsec on-path [OK]
Linux Openswan U2.6.21/K2.6.18-164.6.1.el5 (netkey)
Checking for IPsec support in kernel [OK]
NETKEY detected, testing for disabled ICMP send_redirects [OK]
NETKEY detected, testing for disabled ICMP accept_redirects [OK]
Checking for RSA private key (/etc/ipsec.secrets) [OK]
Checking that pluto is running [OK]
Two or more interfaces found, checking IP forwarding [OK]
Checking NAT and MASQUERADEing [N/A]
Checking for 'ip' command [OK]
Checking for 'iptables' command [OK]

Opportunistic Encryption DNS checks:
Looking for TXT in forward dns zone: centos.example.com [MISSING]
Does the machine have at least one non-private address? [FAILED]

8. 建立IPSec tunnel:
# ipsec auto --up sample
104 "sample" #1: STATE_MAIN_I1: initiate
003 "sample" #1: received Vendor ID payload [Openswan (this version) 2.6.21 ]
003 "sample" #1: received Vendor ID payload [Dead Peer Detection]
003 "sample" #1: received Vendor ID payload [RFC 3947] method set to=109
106 "sample" #1: STATE_MAIN_I2: sent MI2, expecting MR2
003 "sample" #1: NAT-Traversal: Result using RFC 3947 (NAT-Traversal): no NAT detected
108 "sample" #1: STATE_MAIN_I3: sent MI3, expecting MR3
003 "sample" #1: received Vendor ID payload [CAN-IKEv2]
004 "sample" #1: STATE_MAIN_I4: ISAKMP SA established {auth=OAKLEY_PRESHARED_KEY cipher=aes_128 prf=oakley_sha group=modp2048}
117 "sample" #2: STATE_QUICK_I1: initiate
004 "sample" #2: STATE_QUICK_I2: sent QI2, IPsec SA established tunnel mode {ESP=>0xca7bd686 <0x193e1d71 xfrm="3DES_0-HMAC_MD5" natoa="none" natd="none" dpd="">
9. 測試:
# ping 172.17.2.100 -I 172.17.1.100 -c 10
PING 172.17.2.100 (172.17.2.100) from 172.17.1.100 : 56(84) bytes of data.
64 bytes from 172.17.2.100: icmp_seq=1 ttl=64 time=1.65 ms
64 bytes from 172.17.2.100: icmp_seq=2 ttl=64 time=0.716 ms
64 bytes from 172.17.2.100: icmp_seq=3 ttl=64 time=1.16 ms
64 bytes from 172.17.2.100: icmp_seq=4 ttl=64 time=1.41 ms
64 bytes from 172.17.2.100: icmp_seq=5 ttl=64 time=1.24 ms
64 bytes from 172.17.2.100: icmp_seq=6 ttl=64 time=1.17 ms
64 bytes from 172.17.2.100: icmp_seq=7 ttl=64 time=1.52 ms
64 bytes from 172.17.2.100: icmp_seq=8 ttl=64 time=0.544 ms
64 bytes from 172.17.2.100: icmp_seq=9 ttl=64 time=0.796 ms
64 bytes from 172.17.2.100: icmp_seq=10 ttl=64 time=1.58 m
Note:
此次使用的版本分別為:
openswan-doc-2.6.21-5.el5_4.1
openswan-2.6.21-5.el5_4.1
不同的版本間,example configure file有點差異,需請注意。

To setup Socks Server in CentOS5.4

工作需求,所以去架設了Socks4/5 Server來使用,在CentOS上安裝起來很容易且配置上也沒有多大的難度,在此筆記一下。

1. 抓取ss5 tarball檔:
預設的repos似乎沒有ss5,故自己抓個tarball檔下來安裝。
wget http://softlayer.dl.sourceforge.net/project/ss5/ss5/3.7.9-1/ss5-3.7.9-1.tar.gz
tar zxvf ss5-3.7.9-1.tar.gz
2. 安裝:
[root@server2 src]# tar zxvf ss5-3.7.9-1.tar.gz
[root@server2 ss5-3.7.9]# ./configure
[root@server2 ss5-3.7.9]# make
[root@server2 ss5-3.7.9]# make install
3. 配置:
找到auth與permit並將註解取消,注意我並沒有enable使用者需做認證的機制。
[root@server2 ~]# vi /etc/opt/ss5/ss5.conf
# SHost SPort Authentication
auth 0.0.0.0/0 - -
# Auth SHost SPort DHost DPort Fixup Group Band ExpDate
permit - 0.0.0.0/0 - 0.0.0.0/0 - - - - -
4. 啟動:
[root@server2 ~]# chkconfig --add ss5
[root@server2 ~]# chkconfig ss5 on
[root@server2 ~]# /etc/init.d/ss5 start
doneting ss5... [ OK ]
[root@server2 ~]#
5. 測試:
最後可透過FireFox來測試Socks4/5.
工具->選項->進階->設定->手動設定Proxy:
SOCKS主機: x.x.x.x Port: 1080
並選擇SOCKS v4或是SOCKS v5

Monday, January 11, 2010

To implement NFSv2,NFSv3 and NFSv4

NFSv2, NFSv3與NFSv4在Linux 2.6.x的kernel上,預設都是有支援的,不同的是需要對於server或client之前下達不同的參數以區別,以下分別就不同版本的實作簡單敘述:

1. NFS v3:
Server: exportfs *:/tmp
Client: mount 192.168.0.254:/tmp /mnt/nfs

2. NFS v2:
Server: exportfs *:/tmp
Client: mount -o nfsvers=2 192.168.0.254:/tmp /mnt/nfs

3. NFS v4:
Server: exportfs -o fsid=o *:/tmp
Client: mount -t nfs4 192.168.0.254:/tmp /mnt/nfs
References:
http://www.redhat.com/docs/manuals/enterprise/RHEL-4-Manual/ref-guide/s1-nfs-client-config.html
http://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-nfs.html

Wednesday, January 06, 2010

Path MTU discovery

What's Path MTU discovery:
http://en.wikipedia.org/wiki/Path_MTU_discovery

預設Linux box是把pmtud的機制打開的,可透過以下的kernel參數檢查:
cat /proc/sys/net/ipv4/ip_no_pmtu_disc
0 代表pmtud enable (default)
1 代表pmtud disable
以下是我實驗時的環境:

Remote Server (mtu=1500) ----- (mtu=1400) Linux NAT Box (mtu=1400) ----- Client (mtu=1500)

1. 從Client往Server端送出icmp packet size大於1400bytes但小於1500bytes的包,for example 1450 bytes, DF=1
2. Linux NAT Box將會回報封包需要分片!並透過icmp unreachable包告訴Client,本機的mtu為1400bytes
opensuse:~ # ping 10.12.64.220 -s 1450
PING 10.12.64.220 (10.12.64.220) 1450(1478) bytes of data.
From 10.12.95.3: icmp_seq=1 Frag needed and DF set (mtu = 1400)
From 10.12.95.3 icmp_seq=1 Frag needed and DF set (mtu = 1400)
1458 bytes from 10.12.64.220: icmp_seq=2 ttl=63 time=2.85 ms
1458 bytes from 10.12.64.220: icmp_seq=3 ttl=63 time=4.97 ms
1458 bytes from 10.12.64.220: icmp_seq=4 ttl=63 time=3.48 ms
此後將會保持一段時間不需要detect。

Monday, December 14, 2009

[Shell script] 自動開啟或關閉 vsftpd匿名登入機制

1 #!/bin/bash
2
3 vsftp_conf="/etc/vsftpd/vsftpd.conf"
4
5 if [ -f $vsftp_conf ]; then
6 if [ $# -ne 1 ]; then
7 echo "Parameters is not allow"
8 echo "usage: $0 on or $0 off"
9 exit 1
10 fi
11
12 case "$1" in
13 on) CMD='YES';;
14 off) CMD='NO';;
15 *)
16 echo "format error!"
17 exit 1
18 ;;
19 esac
20
21 if [ $CMD = 'YES' ]; then
22 sed 's/^.*anonymous_enable=.*/anonymous_enable=YES/' $vsftp_conf > /tmp/$$.vsftpd.conf
23 mv -f /tmp/$$.vsftpd.conf $vsftp_conf
24 /etc/init.d/vsftpd restart
25 else
26 sed 's/^.*anonymous_enable=.*/anonymous_enable=NO/' $vsftp_conf > /tmp/$$.vsftpd.conf
27 mv -f /tmp/$$.vsftpd.conf $vsftp_conf
28 /etc/init.d/vsftpd restart
29 fi
30 else echo "$vsftp_conf is not exist"
31 fi

說明:
列5 先判斷/etc/vsftpd/vsftpd.conf是否存在,若不存在則回報檔案不存在。(列30)
列6 判斷所傳入的引數是否為1個,若不是則回報錯誤並結束。 (列7~10)
列12-19 使用case,判斷是on, off或是格式有誤。
列21-24 若為on則設定anonymous_enable=YES,並重新啟動vsftpd。
列25-28 若為off則設定anonymous_enable=NO,並重新啟動vsftpd。

測試:
1. 允許匿名登入:
[root@centos bin]# ./vsftpd.sh on
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@centos bin]# ftp localhost
Connected to localhost.localdomain.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (localhost:root): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>

2. 不允許匿名登入:
[root@centos bin]# ./vsftpd.sh off
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
[root@centos bin]# ftp localhost
Connected to localhost.localdomain.
220 (vsFTPd 2.0.5)
530 Please login with USER and PASS.
530 Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type
Name (localhost:root): ftp
331 Please specify the password.
Password:
530 Login incorrect.
Login failed.
ftp>
References:

Friday, December 11, 2009

TestShell Studio

今天下午參加了派恩科技所舉辦的新世代電子與網通產品自動化測試技術研討會,見識到了QualiSystems所研發的TestShell tools其強調並不需要programming的能力就能完成自動化測試的工作,讓我印象最為深刻的就是TestShell Studio,它能結合多種網通測試設備(IXIA,SmartBits and etc),自訂commands,遠端控制DUT,錄製Web access action等等強大的功能以加快測試的速度!AWESOME!

只要把你腦海中的想法透過滑鼠Drag-&-drop,整個測試流程就完成了!我想這對於網通廠商來說是個非常有力的測試工具,也值得每個網通QA學習。

美中不足的是......
1. 沒有提供Trial version
2. 目前似乎沒有for Linux的版本

Wednesday, December 09, 2009

Google Chrome for Linux and Mac OSX goes beta!

Google Chrome for Linux與Mac OSX終於出Beta版了,在Linux方面提供了Debian/Ubuntu/Fedora/OpenSUSE的deb與rpm,而在Mac OSX呢,很遺憾地PPC的user還是被遺忘了,剛好我就是PPC的user @@||

Anyway,在Linux下與Firefox V3.5.5相比,Google Chrome運行起來的確是讓我感覺到有快一點,不過目前發現到有兩個缺點:

1. 預設的中文字型不好看。
2. 即使我已經裝了Adobe flash player,還是不能播放Youtube的影片。
有興趣的人可以試用看看唷!


Monday, November 30, 2009

emesene 1.5.1 - "awesome" bugfix edition has been released!

曾幾何時,當我從Pidgin跳槽至emesene時感覺到非常順手好用,但是唯一的缺點就是emesene常常回報對方收不到我的訊息,有時真覺得有點惱人,所以這陣子又跳回去使用Pidgin,雖然沒那麼好看但至少穩定。

Well,今天連到emesene official website發現到v1.5.1已經正式release了,並且也修正了送不出訊息的問題,好樣的重新拿回來使用!

嘿!不過目前還沒有OpenSUSE 11.2的rpm檔,先用tarball了。

Friday, November 27, 2009

How to configure mirror port on Cisco 2960G switch

碰到了就紀錄一下囉~
# monitor session 1 source interface Gi 0/11
# monitor session 1 destination interface Gi 0/10
如此一來port 10就會成為port 11的mirror port。


判斷service是否可使用TCP wrappers

在Linux系統中,針對service比較簡單的安全政策可透過TCP wrappers來做管理,但是有些service是可被TCP wrappers控管的,有些則不是,如何判斷呢?其實只要用ldd命令來查看service是否有利用到libwrap wrapper library就可以囉!以下舉幾個例子:
1. OpenSSH:
[root@centos ~]# ldd /usr/sbin/sshd | grep libwrap
libwrap.so.0 => /lib/libwrap.so.0 (0x003f9000)
2. NFS:
[root@centos ~]# ldd /usr/sbin/rpc.nfsd | grep libwrap
3. Apache:
[root@centos ~]# ldd /usr/sbin/httpd | grep libwrap
由上可知OpenSSH可由TCP wrappers託管,但是NFS與Apache則不行。(有自己的安全機制)

回憶起以前考RHEL3時是用死記的方法記下那些service可以被TCP wrappers託管,現在年紀大了記憶體不足,只好靠些小技巧來幫助。

Thursday, November 26, 2009

Netifera

Netifera是一套for Linux與MAC OSX的網路環境偵測軟體,使用起來非常簡單易懂。
帽客安裝在CentOS5.4下,從安裝到使用上沒有發生什麼問題,且整體跑起來感覺很流暢!值得推薦給大家使用。

What is Netifera?
Netifera is a new modular open source platform for creating network security tools. This project provides many advantages for both security developers and researchers who want to implement new tools as well as the community of users of these tools.
Netifera website
Netifera quick guide
Download Netifera

Thursday, November 19, 2009

如何透過ISO檔,更新CentOS

之前介紹過如何透過ISO檔升級OpenSUSE,身為紅帽與蜥蜴系的愛好者,當然也要介紹一下如何透過ISO檔升級CentOS(應該也可用於Redhat與Fedora)。

Step1. 建立掛載點:
# mkdir -p /mnt/iso/1
Step2. 掛載ISO檔:
# mount -o loop /mnt/nfs/CentOS-5.4*.iso /mnt/iso/1
Step3. 安裝createrepo套件:
# yum install createrepo
Step4. 產生來源repository:
# cd /mnt/iso
# createrepo .
Step5. 建立新repository設定檔:
# vi /etc/yum.repos.d/centos54.repo
[CentOS5.4 Repository]
baseurl=file:///mnt/iso
enabled=1
Step6. 準備升級:
先將原本的repos全部rename成xxx.repo.bak
# yum clean all
# yum update
成功的話就可看到下圖顯示準備更新成CentOS5.4的套件:


Wednesday, November 18, 2009

學習Linux CLI 的好站

想學習Linux CLI嗎?以下的網站非常值得閱讀或是當作線上工具書:
LinuxCommand
O'Reilly's Linux Command Directory
The Linux CookBook
Ols3 shell script
Also please let me know your favorite websites for learning Linux command line in the comments.

Tuesday, November 17, 2009

Fedora 12 即將release!

Oh.. Fedora12預計於.....2009.11.17 release (不就是今天嗎? 逃~),太久沒注意Fedora project了,明天download下來在VirtualBox上跑看看吧。

BTW, 最近真是OS的大混戰呀! 打得激烈!
Apple MAC OSX 10.6.2 [未使用,好想用呀~哭]
CentOS 5.4 [使用中]
Ubuntu 9.10 [未使用]
OpenSUSE 11.2 [使用中]
Fedora 12 [快要出了]
Windows 7 [恩...]

Friday, November 13, 2009

升級OpenSUSE 11.1至11.2之雜記

OpenSUSE 11.2已經於11.12日正式release了,雖然說11.1目前在S10e上跑得挺順的,但是手癢的我還是決定給它升級看看,以往我會選擇重新安裝的方法來升級,反正/home是配置到另外一個partition,系統重新安裝也不會讓資料遺失,但是總覺得要重新調整到自己習慣的桌面設定太浪費時間了,於是這一次我選擇透過將software repositories指定成OpenSUSE 11.2的方法來安裝:

Step1. Yast->Software->Software Repositories->Add->Local ISO Image添加OpenSUSE11.2镜像。
Step2. 手動移除OpenSUSE 11.1的repositories
Step3. # zypper dup
遺憾的是.....我竟然在X Window幹下此等蠢事,zypper dup會將有衝突的軟件強制刪除,沒想到在Firefox開啟的狀態下,造成系統crash導致更新尚未完成!重開機後整個系統爛掉,唉!我可不能panic呀,冷靜下來進入failsafe mode重新再執行一次zypper dup,沒想到卻回報無法找到來源,原來還需要讓Kernel把loop的模組掛起來,於是便執行modprobe loop,如此一來就可以繼續升級的動作了。

沒想到升級完後,只有保留了kernel-2.6.27.37-0.1-pae而竟然沒有安裝上新的kernel-2.6.31.5-0.1-desktop,導致無法進入GNOME..... anyway透過zypper再裝上新版的kernel吧,裝上後一切搞定,可以正常進入GNOME,目前嘗試使用看看。

Update1_新增OpenSUSE 11.2的repositories:
# zypper ar http://ftp.gwdg.de/pub/linux/misc/packman/suse/11.2/ packman
# zypper ar http://download.opensuse.org/distribution/11.2/repo/oss/ opensuse11.2_oss
# zypper ar http://download.opensuse.org/distribution/11.2/repo/non-oss/opensuse_11.2_non-oss
# zypper ar http://download.opensuse.org/update/11.2/ opensuse11.2_update
Update2_安裝S10e(Broadcom Corporation BCM4312 802.11b/g)的wireless module:
# zypper in broadcom-wl*

Friday, October 30, 2009

CentOS 5.4 now is available to download!

令人喜愛的CentOS5.4正式release囉!趕緊來download.... :)

CentOS 5.4 release notice
Download site

如果已經安裝了之前的版本,則可透過以下的命令線上更新系統:
# yum list updates
# yum update

Thursday, October 29, 2009

備份利器: rsnapshot

rsnapshot與我之前用rsync備份的方法比較起來看來是更加地簡單好用了,有興趣的朋友可參考以下的文章作個測試:
How To Backup Local Unix Host Using rsnapshot rsync Utility
How To Backup Remote Linux Host Using rsnapshot rsync Utility

Thursday, October 22, 2009

Clone HD in the VirtualBox

錯誤方法:
copy / paste original vdi檔。


正確方法:
Windows->cmd->vboxmanage clonehd "original vdi" "new vdi"


之後匯入新的vdi檔就不會造成UUID重複的問題了。

Monday, October 19, 2009

Install FreeMind in OpenSUSE 11.1

在OSX下習慣用FreeMind紀錄一些自己的ideas,但我的末代"老"白iBook G4它老人家重達2.2Kg在加上一些書籍,我實在是背不動了,所以就將S10e安裝成OpenSUSE帶去上班用,索性也來裝個FreeMind來使用吧,沒想到,它真的不是很好安裝,很多套件不論是官方的repository或是packman repository都沒有,只好手動自己找一找裝一裝了。(忽然想起多年前在RHEL3.0要裝K3b support燒錄mp3的壯烈情況。)

裝完了之後,遇到了中文亂碼的問題,參考了佑子窩 blogger所提供的方法很順利的解決了。
不過OpenSUSE與Ubuntu有個地方不一樣:
OpenSUSE: ln -s /usr/share/fonts/truetype/uming.ttf
Ubuntu: ln -s /usr/share/fonts/truetype/arphic/uming.ttf

[Shell script] Select選單語法練習

1. 以選單方式,提供要刪除哪一個檔案 (a1, a2, a3, a4 and a5)
2. 只有當user輸入y/Y時,才會將檔案刪除。
#!/bin/bash
select VAR in a1 a2 a3 a4 a5 exit
do
case $VAR in
a1) read -p "Delete a1? (y/Y/n/N)" FLAG
if [ $FLAG = y -o $FLAG = Y ]; then
rm -f ./a1
fi;;
a2) read -p "Delete a2? (y/Y/n/N)" FLAG
if [ $FLAG = y -o $FLAG = Y ]; then
rm -f ./a2
fi;;
a3) read -p "Delete a3? (y/Y/n/N)" FLAG
if [ $FLAG = y -o $FLAG = Y ]; then
rm -f ./a3
fi;;
a4) read -p "Delete a4? (y/Y/n/N)" FLAG
if [ $FLAG = y -o $FLAG = Y ]; then
rm -f ./a4
fi;;
a5) read -p "Delete a5? (y/Y/n/N)" FLAG
if [ $FLAG = y -o $FLAG = Y ]; then
rm -f ./a5
fi;;
exit) exit;;
esac
done

Friday, October 16, 2009

[Shell script] 遞迴

#!/bin/bash
function re () {
local tmp
tmp=$1
if [ $tmp -eq 1 ]; then
total=1
else
re $(($tmp-1))
total=$(($tmp*$total))
fi
}


read -p "Data=" VAR
re $VAR
echo "$VAR!=$total"
太久沒寫了腦袋打結了一下。

Thursday, October 15, 2009

Fine Tuning Firefox

參考了以下的文章在OpenSUSE 11.1下調整了FireFox的參數,感覺有改善!
Fine Tuning Firefox

順便找到備份FF的軟體:
FEBE

最後附上OpenSUSE 11.1美美的桌面環境。

Wednesday, October 07, 2009

OpenSUSE 11.2 roadmap

沒意外的話應該在今年的11月12號OpenSUSE 11.2就會release了,我還蠻喜歡OpenSUSE team的roadmap。

Milestone -> Release Candidate -> Gold Master
http://en.opensuse.org/Roadmap/11.2

如何幫助測試OpenSUSE: http://en.opensuse.org/Testing/

Sunday, October 04, 2009

Free Partition Manager for Windows

I find a good partition management tool for Windows series OS.
EASEUS Partition Master it's very useful, and Home user edition is free!

Tested on Lenovo S10e netbook and it's works.

Tuesday, September 29, 2009

Shell script 練習

看到Ols3前輩出的練習題,故嘗試寫看看,題目是這個樣子的:
# 把 以下資料檔 d1.txt d2.txt 予以整合
d1.txt
====================
abc:12
bob:25
cdc:36
OK:121
Tomy:99
Jack:108

d2.txt
====================
Jack:9
cdc:8
OK:11
Tomy:22
bob:5
abc:88

試寫一 script 來處理 d1.txt d2.txt 使其變成

abc:12:88
bob:25:5
cdc:36:8
Jack:108:9
OK:121:11
Tomy:99:22

My script:
#!/bin/bash

for VAR1 in `cat ./d1.txt | sort`
do
for VAR2 in `cat ./d2.txt | sort`
do
if [ `echo $VAR1 | cut -d: -f1` = `echo $VAR2 | cut -d: -f1` ]; then
echo $VAR1\:`echo $VAR2 | cut -d: -f2`
fi
done
done

References:

Thursday, September 24, 2009

Powerful web application and network load testing tool: curl-loader

找到了一個還蠻強大的web application與network load testing的工具: curl-loader
curl-loader是based on Linux並號稱可以提供類似SpirentAvalanche與IXIA loader的功能(IXIA用過,但是IXIA loader我可是沒用過 XD),同時間透過curl-loader可以產生上萬筆的clients來產生實際的HTTP或是FTP的流量,重點是透過它的configure file,curl-loader會自動的幫你bind IP,真是貼心的設計呀,使用之前最好是依照它的建議更改些Linux預設的參數,當然如果要產生big real flow那就要使用高檔點的機器囉,帽客實際上跑了一下,發現到當產生30K HTTP clients時,會將dual core(Intel C2D E4500)的CPU resource全部吃光光!

建議調整的參數:
ulimit -n 100000
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
echo 100000 > /proc/sys/fs/file-max
echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
echo 0 > /proc/sys/net/ipv4/conf/ethX/rp_filter
echo "109568 109568 109568" > /proc/sys/net/ipv4/tcp_mem

Monday, September 21, 2009

Wednesday, September 16, 2009

Linux上常見的Load Balancer Project

常見的有:
Linux Virtual Server
Ultra Monkey
Red Hat Cluster Suite
High-Availability Linux

References:

Friday, September 11, 2009

OSX 10.5.x 重大更新通知

OSX剛剛提醒我目前有更新囉,這次的更新還不小,有iTunes, QuickTime, Java for MAC與Security update。

Wednesday, September 09, 2009

只印出本次登入所輸入的命令

Linux系統預設上可透過history(bash內建的指令)看到以前與本次登入所輸入的所有命令,而當使用者登出系統後系統會自動將本次登入時所輸入的所有命令新增到 ~/.bash_history中,至於最多紀錄多少筆則要取決於HISTSIZE/HISTFILESIZE設定為多少(兩者預設應該都是1000),所以排除舊的命令歷史記錄,新的紀錄應該會從1001開始,於是乎可以利用以下簡單的方法列印出目前登入所輸入的所有指令:

# history | while read cmd; do set -- $cmd; if [ $1 -gt 1000 ]; then echo "$1:$2";fi; done
1001:history
1002:set
1003:history
1004:ifconfig
1005:history

Note:
1. 預設上HISTFILESIZE是設定~/.bash_history可紀錄多少筆,預設是1000,假設今天設定成2000則代表~/.bash_history可存放2000筆記錄,於是乎上面的指令就必需改成這樣:
# history | while read cmd; do set -- $cmd; if [ $1 -gt 2000 ]; then echo "$1:$2";fi; done

2.若~/.bash_history未滿1000筆時,那就要特別注意判斷的條件了。

Wednesday, August 26, 2009

HTTP Server Benchmark Test Tool: WBox

WBox aims to help you having fun while testing HTTP related stuff. You can use it to perform many tasks, including the following:

- Benchmarking how much time it takes to generate content for your web application.
- Web server and web application stressing.
- Testing virtual domains configuration without the need to alter your local resolver.
- Check if your redirects are working correctly emitting the right HTTP code.
- Test if the HTTP compression is working and if it is actually serving pages faster.
- Use it as a configuration-less HTTP server to share files! (see the server mode documentation at the end of the Wbox tutorial in this page, but it's as simple as % wbox servermode webroot /tmp)

Wbox is free software under the GPL version 2 license and was written in ANSI C (POSIX runtime required) by Salvatore 'antirez' Sanfilippo

使用過後,個人感覺比ab強大好用!

Thursday, July 30, 2009

Deny SSH brute attack via iptables

iptables rules:
#iptables -A INPUT -p tcp --dport 22 -i ethx -m state --state NEW -m recent --set
#iptables -A INPUT -p tcp --dport 22 -i ethx -m state --state NEW -m recent --update --seconds 60 --hitcount 5 -j DROP
如此一來,本機於1分鐘內收到超過5個以上的SSH連線需求時,第5個SSH connection就會被drop掉.

緊接著用hping測試連續送出n個TCP port 22 SYN,看看第5個SSH connection是否會被drop:


Reference:
http://www.cyberciti.biz/tips/linux-unix-bsd-openssh-server-best-practices.html
http://tuxtraining.com/2009/06/23/stop-ssh-brute-force-attack-using-susefirewall

Thursday, July 23, 2009

Suspend Linux to swap

分享一個在console下將Linux系統休眠到swap的方法:

Tested on CentOS5.3:
Step1. 設定STD(suspend to disk)到swap:
[root@localhost ~]# fdisk -l
Disk /dev/hda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1          13      104391   83  Linux
/dev/hda2              14         842     6658942+  83  Linux
/dev/hda3             843         907      522112+  82  Linux swap / Solaris
/dev/hda4             908        1044     1100452+   5  Extended
/dev/hda5             908         972      522081   83  Linux
[root@localhost ~]# ls -ld /dev/hda3
brw-r----- 1 root disk 3, 3 Jul 23  2009 /dev/hda3

由此得知swap partition的major與minor ID是3.3,接著修改參數如下 (預設是0:0):
[root@localhost power]# echo "3:3" > /sys/power/resume 

Step2. 啟動休眠:
[root@localhost ~]# echo "disk" > /sys/power/state 

此時系統將立刻進入休眠狀態,並於下次重開機時回到剛剛的環境。

Step3. 設定永久suspend到swap:
修改/boot/grub/grub.conf並設定Kernel參數如下:
kernel /vmlinuz-2.6.18-128.2.1.el5 ro root=LABEL=/ rhgb quiet resume=/dev/hda3

Tuesday, July 14, 2009

善用tmpfs當Firefox的cache

現在的電腦記憶體很夠用, Redhat/CentOS預設又將/dev/shm當成tmpfs掛載起來, 所以也就別辜負了它的美意吧! 把它拿來當成Firefox cache的RAMDisk用吧!

至於如何將Firefox的cache指定到/dev/shm呢? 實作上非常簡單, 只要開啟Firefox並於網址列上輸入about:config, 然後點擊滑鼠右鍵->新增->字串後輸入: browser.cache.disk.parent_directory, 內容則輸入/dev/shm就完成了.


成功的話, 當使用Firefox瀏覽網頁時就會看到/dev/shm會新增Cache目錄.
當然系統重新開機後, cache就會消失了!
Note: Redhat/CentOS預設並不特別指定/dev/shm的大小為何, 記憶體剩下多少就允許/dev/shm使用, 如果想要改變此行為的話可開啟/dev/fstab,找到mount /dev/shm的那一列並修改如下:
tmpfs /dev/shm tmpfs defaults,size=100M 0 0
以上希望對大家使用Linux有幫助.

Thursday, July 02, 2009

Compress and encrypt directory in Linux

直接進入實作步驟~
Compress tools: tar
Data encrypt tools: AES Crypt (http://www.aescrypt.com/)

Objective-1, To backup /etc and encrypt it:
1. 壓縮並加密/etc:
# tar cvf - /etc | aescrypt -e -p 123456 -> etc.tar.aes
(-e: encrypt, -p password)

2. 測試etc.tar.aes是否有加密:
[root@localhost ~]# file etc.tar.aes
etc.tar.aes: data
[root@localhost ~]# tar tvf etc.tar.aes
tar: This does not look like a tar archive
tar: Skipping to next header
tar: Archive contains obsolescent base-64 headers
tar: Read 300 bytes from etc.tar.aes
tar: Error exit delayed from previous errors
測試結果發現到etc.tar.aes已經被AES加密了,故無法直接以tar觀看壓縮檔的內容。

Objective-2 To decrypt and uncompress data:
1. 將壓縮檔解密:
# aescrypt -d -p 123456 etc.tgz.aes 
解密後會新增一檔案為etc.tar
2. 解壓縮:
# tar xvf etc.tar
如此一來便可解開加密過後的壓縮檔了。

其它在Linux上常見的加密工具還有openssl與gpg。

Monday, June 29, 2009

20個Linux系統/網路偵測的好工具

發現到一篇介紹20個Linux系統/網路偵測工具的好網頁,挺多我沒有使用過的,所以特別收錄起來,FYI。

Sunday, June 21, 2009

Free online file conversion: Zamzar

很多人為了轉換檔案格式,總是會在電腦上裝載各種轉換的軟體,甚至有時收到了不能讀取的檔案時就更是令人感到心煩了,比如Office 2007的docx,像我的Linux與OSX都沒辦法讀取docx的文件,偏偏有人就是很喜歡寄給我但也總不能去請人家去轉換好再寄給我吧,此時只好自己開啟Windows的office 2007來看,挺浪費時間,嘿嘿~不過今天真是個好日子,讓我發現了一個能解決我這種困擾的服務,Zamzar!

Zamzar它是一個免費的線上格式轉換的服務,不論您使用那種OS(事實上跟OS一點關係都沒有),只要將檔案透過Web browser上傳後,選擇想轉換成的檔案格式,它就會幫你將檔案轉換好並透過mail告訴你檔案下載的連結,真的是非常之方便呀!目前檔案的上限為100MB,而能轉換的格式真是包山包海呀!


Wednesday, June 10, 2009

[Shell script] Remote Services watchdog

以下的script是針對偵測到對方的service沒有正常運作時則發mail給所指定的使用者,請參考:

#!/bin/bash

SRVLIST='192.168.0.100:80
192.168.0.100:53'
MAILACCOUNT="root@server1.example.com"

for SRV in `echo $SRVLIST`
do
 IP=`echo $SRV | cut -d: -f1`
 PORT=`echo $SRV | cut -d: -f2`
 nc -w 1 $IP $PORT > /dev/null 2>&1 || echo "Port $PORT on Server $IP is failed" | mail -s "Error: Service failed" $MAILACCOUNT
done

Monday, June 08, 2009

Install AWstats on CentOS 5.x

What's AWstats?
AWStats is a free powerful and featureful tool that generates advanced web, streaming, ftp or mail server statistics, graphically. This log analyzer works as a CGI or from command line and shows you all possible information your log contains, in few graphical web pages. It uses a partial information file to be able to process large log files, often and quickly. It can analyze log files from all major server tools like Apache log files (NCSA combined/XLF/ELF log format or common/CLF log format), WebStar, IIS (W3C log format) and a lot of other web, proxy, wap, streaming servers, mail servers and some ftp servers.
http://awstats.sourceforge.net/

安裝步驟:
1. 於rpmfind.net 搜尋並下載awstat*rpm for RHEL5.x (awstats-6.9-2.el5.rf.noarch.rpm)
2. # rpm -ivh awstat*rpm
3. 修改/etc/httpd/conf/httpd.conf:
AddHandler cgi-script .cgi .pl
4. 修改/etc/httpd/conf.d/awstats.conf :
Alias /awstats/icon/ /var/www/awstats/icon/
ScriptAlias /awstats/ /var/www/awstats/
        DirectoryIndex awstats.pl
        Options ExecCGI
        Order allow,deny
        Allow from all
#       order deny,allow
#       deny from all
#       allow from 127.0.0.1
5. 將/etc/awstats/awstats.localhost.localdomain.conf改成/etc/awstats/awstats.IPADDRESS.conf (e.g., IPADDRESS=192.168.0.1)

6.手動執行/etc/cron.hourly/00awstats
如此一來就馬上有資料產生了,之後就交給system crontable更新吧!

7. 開啟瀏覽器並輸入 http://192.168.0.1/awstats/awstats.pl,成功的話應該會看到以下的畫面:

Note: awstats.IPADDRESS.conf 有許多參數可調整,請參考裡面的說明。

Sunday, June 07, 2009

帽客剛整理好的桌面

剛整理好,乾淨了一些,拍個照紀錄一下。


Saturday, June 06, 2009

[Shell script] Services watchdog

這隻script的功能就是當偵測到所指定的port於本機沒有啟動的話,就會將它自動重啟,放在cron table裡定時檢查吧!

#!/bin/bash

SRVLIST='80:/etc/init.d/httpd
25:/etc/init.d/postfix
22:/etc/init.d/sshd
110:/etc/init.d/dovecot'

for SRV in `echo $SRVLIST`
do
 nc -w 1 localhost `echo $SRV | cut -d: -f1` > /dev/null 2>&1 && echo "Port $SRV fine" || `echo $SRV|cut -d: -f2` restart
done


[Shell script] Monitor process cpu loading and count

1. 當process CPU loading超過90%, 就先行刪除:
#!/bin/bash
CPULOADING=90
ps auxh | \
while read pro
do
set -- $pro
if [ `echo $3 | cut -d"." -f1` -gt $CPULOADING ]; then
kill $2
fi
done

2.當process數目超過50時, 就先行刪除:
#!/bin/bash
PSCOUNT=50
ps axh -o "cmd" | sort | uniq -d -c | \
while read ps
do
set -- $ps
if [ $1 -gt $PSCOUNT ]; then
killall $2
fi
done

Reference: Linux網路安全管理與監控

Friday, June 05, 2009

[Shell script] Monitor Disk space

#!/bin/bash
USAGE_SPACE=20

df | grep '[0-9]%' | egrep 'sd|hd' | \
while read line 
do
# if [ `echo $line | awk -F" " '{ print $5 }' | cut -d% -f1` -gt "$USAGE_SPACE" ]; then
# echo "Disk space of `echo $line | awk -F" " '{ print $6}'` belongs to `hostname` is over $USAGE_SPACE%" | mail -s "HD DISK is not enough" $USER
# fi

set -- $line
if [ `echo $5 | cut -d% -f1` -gt $USAGE_SPACE ]; then
echo "Disk space of `echo $6` belongs to `hostname` is over $USAGE_SPACE%" | mail -s "HD DISK is not enough" $USER
fi
done

Remark的部份是小弟以前的做法,利用awk去filter出硬碟使用的百分比與目錄名稱,但拜讀了新書"Linux 網路安全管理與監控",學到了可透過set --$line方便取出某行的資料為引數使用,好用!


Sunday, May 31, 2009

Eason Chen Moving on stage 21 part II

昨晚陪老婆去台北小巨蛋聽陳奕迅Moving on stage 21 part II的演唱會,老實說我並非Eason的歌迷,對他的歌比較熟悉的是只有K歌之王,你的背包,婚禮的祝福(這張專輯我有買)。
整體聽下來我可以了解為何老婆這麼喜歡Eason了,他真的很有實力,歌曲確實能打動人心, 感覺上他真的唱得很賣力,連唱了四個小時吧!有幸能參加這種實力派歌手的演唱會真是我們的幸福,可惜我只聽到11:00多就先行離場回家去哄小朋友睡覺了,不然真的很想跟Eason待到最後。

Anyway Eason期待你下一次再來台北開唱!婚禮的祝福真是太好聽了!

Wednesday, May 20, 2009

Moving SUSE Linux to another system

工作用的一台PC可能太過老舊,常常跑到一半就system freeze,懷疑是熱當,然而剛好有一台idle的機器,想說就將hard drive換到那台機器就好了,本以為應該會很順利,沒想到系統重開時SUSE回報:
waiting for device /dev/hda2 to appear
waiting for device /dev/hda4 to appear
然後整個系統就停止了.... 事情似乎沒有我想像得單純..... :p
進入rescue mode查看hard drive也沒損壞呀? 只好上google查看看吧~

後來查到原來是當更換到另一台機器時,由於主機板上的controller是不一樣的! SUSE需要重新make initrd, Redhat不用! 呵呵.... 整個救援的方法如下:

hard drive partition information:
/dev/hda1 -> /boot
/dev/hda2 -> swap
/dev/hda3 -> /home
/dev/hda4 -> /

1. 利用SUSE安裝光碟進入rescue mode
2. 將root partition掛載: mount /dev/hda4 /mnt
3. 將rescue mode的/dev與/proc分別掛載到 /mnt/dev與/mnt/proc: mount --bind /dev /mnt/dev; mount --bind /proc /mnt/proc
4. 將目前的rescue mode的single-root轉成實際上的root partition: chroot /mnt
5. 將/boot掛載: mount /dev/hda1 /boot
6. 切換到/boot目錄,並執行mkinitrd: cd /boot; mkinitrd

Accomplished!

Monday, May 18, 2009

快速取得路由路徑資訊

在Linux下,要確定或查看到某一個destination的方法,比較傳統的方法是執行route -n 或是netstat -rn取得routing table後,再以肉眼判斷讀出,不過我看過有些人管控的機器其routing table內容非常之可怕! 眼睛可能會看到"脫窗", 所幸我今天發現到了一個新的指令可以幫助苦命的IT/MIS.

# ip route get x.x.x.x
-> 系統就會回報到x.x.x.x會經由哪個gateway出去, e.g.,
ip route get 168.95.1.1
168.95.1.1 via 192.168.1.254 dev br0 src 192.168.1.100
cache mtu 1500 advmss 1460 hoplimit 64
解讀: 從src 192.168.1.100到dst 168.95.1.1是透過192.168.1.254出去

Tuesday, May 12, 2009

[Shell script] 讓/etc/passwd更利於閱讀

#!/bin/bash
IFS=:
echo "System User list:"
echo "-------------------------------------"
while read username shapass uid gid comm home shell
do
echo "UserName:$username"
echo " 1.password:$shapass"
echo " 2.uid:$uid"
echo " 3.gid:$gid"
echo " 4.comment:$comm"
echo " 5.home:$home"
echo " 6.default shell:$shell"
echo "------------------------------------"
done < /etc/passwd

參考Linux-101 Hacks, hack 88. Read data file fields inside a shell script

Monday, May 11, 2009

Get Ready for openSUSE Community Week!

The first openSUSE Community Week is just around the corner. May 11 through May 17 we’ll be hosting live sessions in IRC to help grow the openSUSE Community.
Community week is all about helping new contributors get started with openSUSE and getting existing contributors together to mentor new contributors, and working together on major projects.
We’ll be hosting a week of IRC tutorials, Q&A’s, and jam sessions on a number of topics. Learn to work with the testing/QA team, create packages, work with the openSUSE Build Service, help work on the wiki, or get involved with the GNOME and KDE teams. There’s something for everybody.


Schedule:
http://en.opensuse.org/Community_Week

Tuesday, May 05, 2009

Ubuntu and Upstart

Ubuntu與Fedora都採用了upstart模擬跑SysV. 但是OpenSUSE11.1/SLES11 whereas.... 還是採用大家熟悉的SysV, 讓我們來看看Novell的concern吧:

http://en.opensuse.org/Ubuntu_and_Upstart

是不是差點沒說出脫褲子放屁~ XD

Thursday, April 23, 2009

wget useful parameters

遇到了所以在此做個紀錄,雜記一下:

# wget -r -np -A img,txt,gz,pcap,cap http://xxx.xxx.xxx
-r --recursive
-np --no-parent
-A --accept=LIST
-> 如此一來就會對xxx.xxx.xxx的網站以遞迴的方式,抓取以img,txt,gz,pcap與cap類型的檔案,其它的都會忽視。

更多的參數可透過wget --help或是man wget獲得更進一步的資訊。

Monday, April 13, 2009

忽視記錄指定的指令於history中

上次介紹可用HISTCONTROL="ignorespace"來忽視開頭為"空白"的指令記錄於history中,今天再提供另一種可行的方法,當看到特定的指令時,也將不記錄於history中,實作的方法如下:

Usage: HISTIGNORE="cmd1:cmd2"

Example1: 忽視記錄pwd,useradd,userdel,passwd等指令:
# export HISTIGNORE="pwd:useradd:userdel:passwd"

Example2: 開機即套用:
Redhat/SUSE: echo 'export HISTIGNORE="pwd:useradd:userdel:passwd"' >> /etc/profile
Note: 如果系統不允許重開機,可以透過source /etc/profile來生效。

Friday, April 10, 2009

不紀錄開頭為space的指令於history中

直接來看如何實作吧!
舉個常會碰到的例子, 如果在console下需輸入敏感的資料時, 不要讓它記錄到history中:
#HISTCONTROL=ignorespace
# echo "redhat" | passwd --stdin lawrence (注意開頭必需為空白)
#history

如此一來echo "redhat" | passwd --stdin lawrence 就不會記錄到history中.

Wednesday, April 08, 2009

Modify Linux prompt

改變一下原本CentOS5.x黑底白字的prompt為黑底綠字如下, 有小學時用DOS的fu ~ XD



加入以下的設定於 /etc/profile讓每個使用者都有這種fu ~
PS1="\e[0;32m[\u@\h \W]$ \e[m"

Cocoa Packet Analyzer in OSX

以前帽客要在OSX下抓網路封包, 有兩種方法:
1. 開啟終端機, 執行tcpdump -> 只有文字模式
2. 安裝X11-> 透過某個在OSX下能安裝Linux apps的工具(Fink)安裝wireshark -> 有圖形可看了, 但是挺麻煩.

現在不用囉! 直接給它安裝Cocoa Packet Analyzer就可以在OSX下抓網路封包啦!
About Cocoa Packet Analyzer
A native Mac OS X implementation of a network protocol analyzer and packet sniffer. It is able to do basic network capturing (incl. packet filtering), analyze and display packet trace files. CPA supports the industry-standard PCAP packet capture format for reading, capturing and writing packet trace files. Further more the libPCAP/ tcpdump filter expressions may be used during capturing network traffic. It supports a variety of network protocols and can be enhanced using the Cocoa bundle plugin technology. Features a quicklook plugin so you can get an overview of you trace file even in finder.

Support libpcap format, 太棒了正是我需要的, 因為我 慣用的packet playback tools只支援libpcap format.

Download: http://www.apple.com/downloads/macosx/networking_security/cocoapacketanalyzer.html

Friday, April 03, 2009

透過ac command 顯示所有使用者登入的時間

今天看書,學習到利用ac指令來獲取系統上所有使用者上線的總時間,帽客覺得這是非常實用的指令,故於此分享給大家,以下是ac的簡單說明: (man page description)
ac prints out a report of connect time (in hours) based on the logins/logouts in the current wtmp file. A total is also printed out.

ok, 再來以上線跑不久的OpenSUSE11.1來做個例子:

Example1: 顯示每天所有使用者上線的時間總和:
linux-xgby:~ # ac -d
Mar 7 total 28.81
Mar 9 total 0.14
Mar 13 total 17.35
Mar 15 total 32.28
Mar 20 total 8.09
Mar 21 total 3.00
Mar 22 total 44.08
Mar 23 total 10.44
Mar 24 total 33.19
Mar 25 total 29.43
Mar 31 total 0.03
Apr 1 total 15.17
Apr 2 total 4.47
Apr 2 total 14.60
Apr 3 total 21.09
Today total 1.67

Example2: 顯示個別使用者上線的時間總和:
linux-xgby:~ # ac -p
lawrence 258.67
root 5.31
total 263.98

如何,夠簡單又實用吧!

Thursday, April 02, 2009

To compile polygraph network benchmark tools on CentOS5.2

What's polygraph?
"Web Polygraph is a freely available performance testing tool for caching proxies, origin server accelerators, L4/7 switches, content filters, and other Web intermediaries. Polygraph's features include:
high-performance HTTP clients and servers
realistic HTTP and SSL traffic generation
HTTP Basic, NTLM, and Negotiate proxy authentication
LDAP-friendly generation of user credentials
flexible content simulation
ready-to-use standard workloads for benchmarking
powerful domain-specific configuration language
portable open-source implementation
friendly commercial support "


http://www.web-polygraph.org/

在CentOS5.2下編譯polygraph v3.1.5時會發生SslWrap.cc的問題,解決的方法是:
http://www.linuxquestions.org/questions/linux-server-73/problem-compiling-web-polygraph-689766/

./configure;make;make install 好搞定了! Enjoy it!

Thursday, March 26, 2009

Novell SLES11 Server/Desktop is available to download

哇哈哈~ Novell SLES11 Server/Desktop總算是釋出了,目前家裡一台P4 2.4GHz的老PC跑OpenSUSE 11.0讓我非常滿意,之前有聽說過SLES11是基於OpenSUSE 11.1開發的。

打算先找台NB裝一下看看,BTW Novell SLES11與SLES10一樣提供60天的免費更新,哈!還算ok!
謎之音: 之前在某家公司內部所架設的SLES10 <- 提供挺多services 沒當過,不知還在運作否 XD

Monday, March 16, 2009

OSX: 螢幕抓圖利器 InstantShot!


InstantShot! 是帽客在OSX環境下慣用的螢幕抓圖軟體,個人覺得非常直覺好用,重點是它支援中文又是free的,這麼好用的軟體希望Mac fans不要錯過囉。

Friday, March 13, 2009

Linux管理小技巧: CDPATH

預設上, RHEL5.x與CentOS5.x的bind有chroot的機制, 所以當系統管理者要去更改named.conf或是相關的DNS zonefile時就必需要輸入/var/named/chroot/etc/ or /var/named/chroot/var/named/ 恩... 有點長, tab要按好幾次, 於是乎帽客想到了一個好用的偷懶方法, CDPATH.

透過CDPATH可以設定parent directory然後透過cd指令切入到subdirectories, 看起來有點抽象? 實際看看例子吧:


上面的例子是設定CDPATH為DNS Server chroot的路徑(/var/named/chroot), 並將它變成環境變數, 之後只要輸入cd etc就會切入到/var/named/chroot/etc, 而cd var/named就會切入到/var/named/chroot/var/named.

看起來方便多了吧!

update:
讓CDPATH重開機時就生效吧:
echo "CDPATH=/var/named/chroot" >> /root/.bash_profile

2009.3.16 update:
今天發現到bash內建的command,pushd與popd也有著類似的功能:
先將/var/named/chroot 透過pushd新增至stack中,並用dirs確定目前stack的內容(第一筆永遠是current directory),之後透過cd就可以切換到subdirectories。

Thursday, March 12, 2009

經濟愈差 病毒愈多

我的好朋友Mark給我以下的消息,網路實在是不安全。

Tuesday, March 10, 2009

Compile Linux kernel "2.6.28.7" on CentOS5.2

想玩看看EXT4,所以下載了最新版有支援EXT4的kernel於CentOS5.2上,以下是compile的雜記:

1. 於/usr/src/kernels/解開2.6.28.7的kernel source (download: www.kernel.org)
2. 將目前的kernel config 從/boot下copy到/usr/src/kernels/2.6.28.7/.config
3. 於/usr/src/kernels/2.6.28.7執行make menuconfig
-> Add EXT4
-> Remove Bluetooth
-> Remove wireless
4. 執行make bzImage
5. 執行make modules
6. 執行make modules_install
7. 執行make install
8. 檢查/boot/*, /boot/grub/grub.conf
-> 開機選用kernel 2.6.28.7開機。
2009.3.25 update:
Tested ext3 and ext4 performance on kernel 2.6.29 and result as below:
It looks like ext4 is better than ext3.
Note: To clean HD cache for each test processing by hdparm -f command.

Tuesday, February 24, 2009

列印出每個使用者登入至Linux主機的總次數

這麼下達就可以得到結果了 :

# last|awk -F" " '{print $1}'|grep -v "^$"|grep -v reboot|grep -v wtmp|sort|uniq -c

Monday, February 16, 2009

Check Linux NIC driver

工作需求所以用到了, 在此記錄:

#ethtool -i eth0
driver: e1000e
version: 0.3.3.3-k6
firmware-version: 5.7-6
bus-info: 0000:0c:00.0

Linux liveUSB creator

發現了一套可執行於Linux與Windows的Linux liveUSB creator: liveusb-creator 透過它, 可以很方便的透過iso檔製作出liveusb, usb開機比DVD/CD-ROM開機不僅來得快也來得方便多了, 畢竟現在很多notebook/netbook預設都不搭配DVD/CD-ROM.

安裝:
-如果你要運行於Windows在可於此下載, 解開並執行liveusb-creator.exe: liveusb-creator-3.2.zip
-然而如果要運行於Linux的話, 以Fedora9/10來說, 可直接透過yum安裝: # yum install liveusb-creator

測試:
Under Windows XP SP3
1. 插入USB device
2. Fdisk/Format USB device 為單一主要分割區, 格式為FAT32 (目前只能運作於FAT32/EXT)
3. 執行liveusb-creator.exe
4. 選擇來源ISO: systemrescuecd-x86-1.1.5.iso
5. 選擇Target Device為USB device partition
-> Completed

之後透過USB device開機, systemrescuecd Linux正常開機且運作順利.
更多的資訊可參考官方的FAQ: https://fedorahosted.org/liveusb-creator/wiki/FAQ

Thursday, January 22, 2009

Disable bug buddy in OpenSUSE11.1

這幾天OpenSUSE在X環境下(GNOME)不斷跳出bug buddy的popup message, 而我也已經將系統錯誤訊息回傳給OpenSUSE研發團隊了,但是它還是不斷地popup,有點惱人,決定先行關掉它了:

Disable bug buddy message method:
編輯家目錄下的 .profile:
vi ~/.profile
#Disable bug buddy message
export GNOME_DISABLE_CRASH_DIALOG=1

重新登入或重開機後就不再popup了.

Tuesday, January 20, 2009

iptstate tools

利用iptstate tools你可以觀察到netfilter中每一筆connection的狀況, 真是隻好工具! 使用時請先記得將ip_conntrack kernel module 掛載起來, 否則將無任何資料顯示出來.

# modprobe ip_conntrack

http://phildev.net/iptstate/

Tuesday, December 30, 2008

Linux4One for Acer Aspire One

有小萬朋友可以考慮安裝此發行版本Linux4One, 它針對小萬做了最佳化, 並包含了所有的硬體驅動程式, 且是基於Ubuntu加以修改.

http://www.linux4one.it/
http://downloads.agrilan.net/Linux4one_RC_1.iso

Thursday, December 25, 2008

一樣的blog name?

最近在google search自己的blog時(不是自戀,只是在別台電腦要找一下自己以前寫的文章參考),發現到竟然有人跟我用雷同的Blog name?! 只是他是熱愛Linux的電腦癡漢,而不是同時熱愛Linux與Mac OSX的電腦癡漢 XD。

在此想聲明一下那個人不是我唷!呵呵~那不是我的私生活呀~~~ 大家千萬別誤會。

Wednesday, December 24, 2008

OpenSUSE 11.1 特別的GRUB畫面

今天啟動OpenSUSE 11.1的機器時, 發現到讓我驚喜的畫面如下, 企鵝過聖誕?! 圖中的企鵝還會動哩.. 真是別具巧思的設計, 應該是利用gfxmenu美化的吧?

Monday, December 22, 2008

Add third-party repository for openSUSE 11.1

Step:
# zypper addrepo --repo http://packman.mirrors.skynet.be/pub/packman/suse/11.1/Packman.repo

Packman is the most popular third-party repository available for openSUSE. It contains many packages that aren't in the openSUSE version; either because they cannot be included for legal reasons, because the distribution contains an older version, or simply because it was never packaged for the distribution release.

This is the repository where you can acquire the relevant mp3 and other codecs, as well as many multimedia applications (such as mplayer), torrent clients, games, etc...

之後透過yast的Software/Software Management來安裝所需要的套件就方便了許多.

Thursday, December 18, 2008

Monitor Linux machine status (cpu, memory, traffic) via MRTG

有興趣的朋友, 請到以下的連結download小弟拙作:
http://www.nakido.com/B8DD850DCFA3C65697D5C5371559FBE6E6EA2E55

Note: 文章中的cpu.cfg與mem.cfg是參考阿駕零零壹 © 學習筆記 加以修改.

Tuesday, December 16, 2008

OSX: 在文字模式下執行修復檔案權限

透過GUI實在是太慢了,可開啟Terminal執行 sudo diskutil repairpermissions /
搞定收工~

UUID使用小技巧

在網路上看到了一篇關於UUID的使用好方法,整理如下:
1. 查看device的UUID:
1.1 blkid:

1.2 查看/dev/disk/by-uuid directory:


2.透過UUID反查device name:


補充:
亂數產生UUID: uuidgen
Clone UUID: tune2fs -U /dev/hdax

Friday, December 05, 2008

Fedora10: 在滑鼠右鍵中增加"終端機"

帽客習慣使用Console來操作Linux, 而Fedora 10 預設於GNOME中按下滑鼠右鍵並沒有開啟終端機的選項, 對於我來說實在是有點麻煩, 然而其實只要安裝上nautilus-open-terminal並重新登入GNOME就可以了.

Step: # yum -y install nautilus-open-terminal


PS. Ubuntu預設也應該是如此, 只是安裝完後上了Lazybuntu就包含了進去.

Thursday, December 04, 2008

Clonezilla

昨天在逛Linux today時, 無意中發現到有篇介紹Clonezilla的文章, 看完後感到非常有興趣, 所以就連到Clonezilla official website, 猛然發覺這套軟體是"MIT"的, 台灣人製造的哩! 當然要給它推一下.

Clonezilla經過帽客實際的測試過後, 的確是非常好用又簡單, 我採用的備份政策是backup full HD to remote samba server, 並用Virtualbox故意建立一個比原本HD還大容量的HD來測試從Samba server restore full HD, 結果完全沒有出錯.

測試的作業系統是Fedora10, file system是ext3與swap.

下一次我想試看看:

-Backup/restore specify partition via remote file server.
-Backup/restore OSX10.5.5 (HFS+)

Monday, November 17, 2008

expect example

In bash:
#!/bin/bash
expect -c "
spawn ssh root@1.1.1.1
expect password:
send \"1234\r\"
expect ]#
send \"ls -l\r\"
expect ]#
send \"uname -r\r\"
expect -timeout 1
"
Not in bash:
#!/usr/bin/expect
spawn ssh root@1.1.1.1
expect "password: "
send "1234\r"
expect "]# "
send "uname -r\r"
expect -timeout 1

Friday, October 31, 2008

dmidecode

Windows下相信大家常用cpuz去查看主機板的詳細資訊,而Linux下則可用dmidecode這個工具來查看,這邊是dmidecode官網的example: dmidecode example。

安裝的方法非常簡單,將tarball檔抓下來後,進入到解開的目錄中執行:make;make install即可安裝成功,而執行時直接打dmidecode就可以了,配合重新輸出導向,就可將此info記錄到某一檔案中。

Wednesday, October 22, 2008

Check USB status in Linux

簡單介紹一下如何在Linux OS下查看USB的控制器與其它資訊,一個非常簡單的方法是透過lspci,如下所示:
[root@s1 ~]# lspci | grep -i usb
00:07.2 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 16)
00:07.3 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 16)

可以看出這台老PC只支援USB 1.x 
PS. USB 控制器:
-UHCI: USB 1.x Inetl/VIA mb
-OHCI: USB 1.x 非Intel/VIA mb
-EHCI: USB 2.0

另外一個包含非常多USB資訊的檔案:
[root@s1 ~]# cat /proc/bus/usb/devices 
T:  Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
B:  Alloc=  0/900 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 1.10 Cls=09(hub  ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.18-53.el5 uhci_hcd
S:  Product=UHCI Host Controller
S:  SerialNumber=0000:00:07.3
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=255ms

T:  Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#=  1 Spd=12  MxCh= 2
B:  Alloc=  0/900 us ( 0%), #Int=  0, #Iso=  0
D:  Ver= 1.10 Cls=09(hub  ) Sub=00 Prot=00 MxPS=64 #Cfgs=  1
P:  Vendor=0000 ProdID=0000 Rev= 2.06
S:  Manufacturer=Linux 2.6.18-53.el5 uhci_hcd
S:  Product=UHCI Host Controller
S:  SerialNumber=0000:00:07.2
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=  0mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=09(hub  ) Sub=00 Prot=00 Driver=hub
E:  Ad=81(I) Atr=03(Int.) MxPS=   2 Ivl=255ms


Wednesday, October 15, 2008

利用PAM限制SSH login的user account

實作起來非常簡單,兩個設定即可,請參考如下:

需求:只允許root與u1可以ssh login至本機

1. 建立user list:
# vi /etc/ssh/ssh_users
root
u1

2. 修改/etc/pam.d/sshd:
#%PAM-1.0
#auth       include      system-auth
auth       required     pam_listfile.so item=user sense=allow file=/etc/ssh/ssh_users onerr=fail
account    required     pam_nologin.so
account    include      system-auth
password   include      system-auth
session    optional     pam_keyinit.so force revoke
session    include      system-auth
session    required     pam_loginuid.so

立即生效~
* sense=allow 代表名列於/etc/ssh/ssh_users的user才可ssh login, 反過來說當sense=deny時代表ssh_users中的account不可ssh login。
*onerr=fail 代表當/etc/ssh/ssh_users無法開啟或是檔案不存在時,當作失敗,反之onerr=succeed代表不管能不能讀取到檔案都成功。

Monday, September 22, 2008

翻得真好~

最近常看三國演義, 並看到這句話: A good bird chooses (for himself) the tree upon which to perch, the talented subject chooses (for himself) the lord that he shall.

有人知道怎麼將它翻回原文嗎? 先賣個關子

Friday, September 19, 2008

讓Windows XP也有Mac or Linux-like multiple desktop

帽客的小萬螢幕不夠大, 往往開了一堆App後Windows的工具列就雜亂很難看, 然而這個情況改變了, 今天碰巧的發現到原來老M也出了類似Mac與Linux的多工桌面環境, 你可以至以下的MS官方網址抓取使用:

http://technet.microsoft.com/en-us/sysinternals/cc817881.aspx


謎之音: 小萬:[快把我改裝成Linux啦~~~~]
我: [先用Virtualbox撐一下吧~]

Thursday, September 18, 2008

Acer ASPIRE one BIOS update

New BIOS of Acer ASPIRE one (AOA110/AOA150) is available to download:
http://www.acer.com.tw/driver.asp

V.3304

Thursday, September 11, 2008

LDIF generate tools: OpenDS內附的"makeldif"

提供一個大量產生LDIF user entries的產生器:
https://www.opends.org/wiki/page/MakeLdif
Download site

執行makeldif前,系統必須安裝JRE的環境,所以請到Sun官網抓吧:
Sun JRE

安裝好JRE後, 就可以順利透過makeldif產生大量的資料了,預設是10K.

最後提供一套在Windows下查詢LDAP Server user entries的好工具, 一樣Windows也必須有JRE:
LDAP Browser/Editor

Note:
Tested on CentOS5.2

Friday, September 05, 2008

更新Acer Aspire one BIOS

上星期帽客到黃色小屋敗了一台小筆電 Acer Aspire one XP120G(金色的那款), 目前使用上沒有遇到太大的問題, 唯一的就是當LCD亮度調到比較暗時, LCD會閃爍不停 :(

這個問題還挺多人遇到的, 不過Acer已經有釋放出BIOS來解決這個問題了, 新BIOS的版本為3301, 但是此時我需要USB開機碟, 上google爬了爬文, 發現到BootFlashDOS這個製作USB開機碟的好東東, 簡單又快速 XD

製作好USB開機碟後於XP中重新開機Acer Aspire one, 並按下F12選擇用USB開機, 開完後執行3301.bat, 待重開機後, BIOS更新成功, LCD閃爍的問題似乎也得到了改善, 且讓我再觀察一陣子看看.

另外還有人抱怨Aspire one 無線訊號不良與底座不平這兩個主要問題, 我使用上的感覺是:
-無線訊號不良: 還ok 連公司的AP都算順暢, 不過只有用MAC filter,如果有跑加密呢? 呵~應該跟我的3com AP來連看看, anyway我很少用wireless所以這點對我問題不大

-底座不平: 這點到還好, 如果拔掉電池, 一點也沒有不平的感覺, 裝上電池呢? 這點容我再留意一下

Tuesday, September 02, 2008

永久掛載smbfs/cifs filesystem時 於/etc/fstab不顯示user info

以前帽客在/etc/fstab mount smb/cifs的遠端FileServer時, 總是壞習慣的把username與password寫在/etc/fstab中, 不太好也不建議, 所以目前改用以下的方法將username與password存入到別的檔案, 而在/etc/fstab中則指定去讀這個檔案以取得user的相關info, 整個fstab的格式改變如下:

-before:
//172.17.1.254/homes /mnt/smb cifs defaults,username=lawrence%redhat

-after:
//172.17.1.254/homes /mnt/smb cifs defaults,credentials=/root/creds

/root/creds 內容:
username=lawrence
password=redhat

* /root/creds 權限建議設定為400

Friday, August 29, 2008

queryperf: 測試DNS Server的效能/壓力工具

今天找到了一個對於DNS Server做stress test的好工具: queryperf,這個工具事實上內建於bind套件中,不過我的Centos5.2與OpenSUSE10是透過rpm安裝bind的,利用rpm -ql | grep -i queryperf卻找不到相關的檔案?於是乎我去抓了bind tarball檔,將queryperf compile起來,產生queryperf binary file就可以使用了。

使用的語法也不難主要如下:

./queryperf -d -s

-d 是讀取測試RR文檔的意思
-s 是指定所要測試的DNS Server

RR_document的格式也是很簡單的,請參考以下範例:
server1.example.com A -> query server1.example.com A Record
example.com MX -> query example.com domain mx Record
mail.example.com CNAME -> query mail.example.com CNAME
server1.example.com TXT -> query server1.example.com TXT Record
example.com TXT -> query example.com domain TXT Record
example.com NS -> query example.com domain NS Record
100.10.10.10.in-addr.arpa PTR -> query 10.10.10.100 PTR Record
101.10.10.10.in-addr.arpa PTR -> query 10.10.10.101 PTR Record

Note: ->是說明,不需要加入到RR_document

執行結果:
Statistics:

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

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

RTT max: 0.033874 sec
RTT min: 0.013128 sec
RTT average: 0.023992 sec
RTT std deviation: 0.007508 sec
RTT out of range: 0 queries

Percentage completed: 100.00%
Percentage lost: 0.00%

Started at: Mon Aug 25 03:33:47 2008
Finished at: Mon Aug 25 03:33:47 2008
Ran for: 0.034861 seconds

Queries per second: 229.482803 qps

緊接著來寫個簡單的script讓他不斷的執行queryperf吧!
#!/bin/bash
while true
do
./queryperf -d dnstest -s $1 -v
done

把DNS所有的RR都寫入RR_document,這麼一來,就可以來試看看你的DNS Server耐不耐操了 XD!

Friday, August 22, 2008

控管非Linux風格的file system的權限

現今Linux已經可以支援許多非Linux的檔案系統了,比如vfat,ntfs,hpfs,hfs等等,而預設上只有root可以對這些非Linux風格的檔案系統做新增與刪除的動作,其他一般user是不被允許的,或許有人覺得,還好吧!那我用chown硬上看看,但得到的結果會是.... Operation not permitted,非常遺憾呢~ 然而小弟不才今天發現到了可行的方案,在此提供給各位參考:

解決的方法非常簡單,用mount參數就可以解決了!
uid=lawrence ->代表此檔案系統中所有的檔案的使用者都是lawrence
gid=qa -> 代表此檔案系統中所有的檔案的群組都是qa
umask=027 -> 類似原本umask的功能,只不過不分檔案與目錄所有預設的權限都是777 (Linux filesystem 新增檔案時權限為666,目錄為777),所以此檔案系統的權限為750

整個mount指令下達: mount -t vfat -o uid=lawrence,gid=qa,umask=027 /dev/hdaX /mnt/msdos
(-t vfat可不輸入)

Thursday, August 21, 2008

Colasoft Packet Builder

帽客很少介紹在Windows上的軟體,不過我覺得從事網通業的各位朋友們如果使用了這套軟體,對於網路行為的除錯應該是有些幫助,Colasoft Packet Builder是一套在Windows作業系統上的免費軟體,透過它我們可以製造出想要的TCP, UDP, IP, ARP的封包,好用的是我發現到它還load一些capture packets的紀錄檔(sniffer/wireshark),修改過後再產生packets,感謝D-Link大大Dennis的介紹~

Colasoft Packet Builder

Friday, August 15, 2008

忽視fsck 當mount filesystem達到指定的數量

有使用Ubuntu的朋友們應該有發現到,有時開機時會顯示正在fsck filesystem,這時只能去泡杯茶等它檢查完畢了,當然這樣對於filesystem的完整性並避免磁碟的錯誤是有幫助的,但是有時帽客實在是不太想等Ubuntu的這個好意,所以我用以下的方法將它取消:

1.先使用dumpe2fs得到mount幾次後就會fsck filesystem:
lawrence@lawrence-x24:~$ sudo dumpe2fs /dev/sda3 | grep -i mount
dumpe2fs 1.40.8 (13-Mar-2008)
Last mounted on:
Default mount options: (none)
Last mount time: Fri Aug 15 09:03:55 2008
Mount count: 27
Maximum mount count: 35
得到目前mount 27次,並於第35次時會fsck filesystem。

2.使用tune2fs修改Maximum mount count為-1(永不fck):
lawrence@lawrence-x24:~$ sudo tune2fs -c -1 /dev/sda3
tune2fs 1.40.8 (13-Mar-2008)
Setting maximal mount count to -1
lawrence@lawrence-x24:~$ sudo dumpe2fs /dev/sda3 | grep -i mount
dumpe2fs 1.40.8 (13-Mar-2008)
Last mounted on:
Default mount options: (none)
Last mount time: Fri Aug 15 09:03:55 2008
Mount count: 27
Maximum mount count: -1

實際上還有個參數,當經過多久後,也會fsck filesystem:
lawrence@lawrence-x24:~$ sudo dumpe2fs /dev/sda3 | grep -i inter
dumpe2fs 1.40.8 (13-Mar-2008)
Check interval: 15552000 (6 months)

看來預設是6個月,恩這樣倒不錯。

Thursday, August 14, 2008

Process執行中止時便停止追蹤(tail -f)

tail -f 可以持續顯示新增的檔案內容,對於協助追蹤某些檔案的內容變化非常有幫助,但事實上如果process已經沒有繼續執行的時候,那麼意義可能不大,所幸還是有解決的方法,利用--pid= 就可以做到,以下是實際演練:

1. ping hinet苦命的DNS 168.95.1.1,並將結果redirect到/tmp/test
# ping 168.95.1.1 > /tmp/test &

2.利用tail持續追蹤/tmp/test,並輸入ping process的pid
# tail -f --pid=xxxx /tmp/test

3. 中止ping
# killall ping

此時應該會看到類似這樣的行為:
[root@server2 tmp]# ping 168.95.1.1 > /tmp/test &
[1] 11024
[root@server2 tmp]# tail -f --pid=11024 /tmp/test
64 bytes from 168.95.1.1: icmp_seq=1 ttl=239 time=52.6 ms
64 bytes from 168.95.1.1: icmp_seq=2 ttl=246 time=21.4 ms
64 bytes from 168.95.1.1: icmp_seq=3 ttl=246 time=19.9 ms
64 bytes from 168.95.1.1: icmp_seq=4 ttl=246 time=19.6 ms
64 bytes from 168.95.1.1: icmp_seq=5 ttl=246 time=18.4 ms
64 bytes from 168.95.1.1: icmp_seq=6 ttl=239 time=50.9 ms
64 bytes from 168.95.1.1: icmp_seq=7 ttl=246 time=17.6 ms
64 bytes from 168.95.1.1: icmp_seq=8 ttl=246 time=19.1 ms
64 bytes from 168.95.1.1: icmp_seq=9 ttl=239 time=51.4 ms
64 bytes from 168.95.1.1: icmp_seq=10 ttl=246 time=18.1 ms
64 bytes from 168.95.1.1: icmp_seq=11 ttl=239 time=52.3 ms
64 bytes from 168.95.1.1: icmp_seq=12 ttl=246 time=20.6 ms
64 bytes from 168.95.1.1: icmp_seq=13 ttl=246 time=18.9 ms
64 bytes from 168.95.1.1: icmp_seq=14 ttl=239 time=53.4 ms
64 bytes from 168.95.1.1: icmp_seq=15 ttl=246 time=18.6 ms
64 bytes from 168.95.1.1: icmp_seq=16 ttl=246 time=18.5 ms
64 bytes from 168.95.1.1: icmp_seq=17 ttl=246 time=18.9 ms
[1]+ Terminated ping 168.95.1.1 >/tmp/test ping被kill了所以也就停止追蹤了。

Wednesday, August 13, 2008

刪除當前目錄備份檔(*~)的方法

我想到的方法分別有三種如下:

1. find ./ -iname "*~" -exec rm {} \;
2. find ./ -iname "*~" | xargs rm
3. rm `find ./ -iname "*~"`

如果您有更好的方法,煩請告知囉~

Thursday, August 07, 2008

Howto mount disk image

如果你今天面對的是disk image而不是一般的partition image,當使用mount -o loop時會無法mount成功。這很容易理解,因為你必須知道disk image中partition的位置後才能mount起來,怎麼做呢?以下將會說明:

需求: mount test.img 並更改第一個partition中的某個檔案

我們先看看如果直接用mount -o loop會如何:
lawrence@lawrence-x24:~/Desktop$ sudo mount -o loop test.img /mnt/test/
mount: you must specify the filesystem type
lawrence@lawrence-x24:~/Desktop$ sudo mount -o loop -t ext3 test.img /mnt/test/
mount: wrong fs type, bad option, bad superblock on /dev/loop0,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

恩,看起來是不work......

所以我必須先知道test.img的磁軌與磁區大小才能算出第一個partition的位置:
lawrence@lawrence-x24:~/Desktop$ fdisk -l test.img
You must set cylinders.
You can do this from the extra functions menu.

Disk test.img: 0 MB, 0 bytes
16 heads, 63 sectors/track, 0 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk identifier: 0x00000000

所用裝置 Boot Start End Blocks Id System
test.img1 1 32 16096+ 83 Linux

得知每個 track 共 63 sectors, 每個 sector 是 512bytes,故得知第一個partition是在63*512=32256

接下來利用losetup將第一個partition先掛到/dev/loop0,並驗證:
lawrence@lawrence-x24:~/Desktop$ sudo losetup --offset 32256 /dev/loop0 test.img
lawrence@lawrence-x24:~/Desktop$ sudo losetup /dev/loop0
/dev/loop0: [0803]:865823 (test.img), offset 32256

好了,將它mount起來吧!
lawrence@lawrence-x24:~/Desktop$ sudo mount /dev/loop0 /mnt/test/
lawrence@lawrence-x24:~/Desktop$ df -h | grep test
/dev/loop0 16M 7.9M 6.6M 55% /mnt/test

修改完畢後,一樣將他umount掉並detach /dev/loop0
lawrence@lawrence-x24:/mnt/test$ cd
lawrence@lawrence-x24:~$ sudo umount /mnt/test
lawrence@lawrence-x24:~$ df -h | grep test
lawrence@lawrence-x24:~$ sudo losetup -d /dev/loop0
lawrence@lawrence-x24:~$ sudo losetup /dev/loop0
loop: can't get info on device /dev/loop0: 沒有此一裝置或位址

以上希望對大家有幫助。

PS. Redhat中如果要位移,是下達losetup -o 32256而不是losetup --offset 32256

Friday, August 01, 2008

線上學習Linux

發現到一個線上學習Linux的好地方,文章非常豐富,英文用詞也不會太難,且也提供html與PDF的下載,真是滿不錯的,非常感謝這些無私奉獻的人。

http://learnlinux.tsf.org.za/index.html