2013年12月30日 星期一

Howto apply patch

====generate a patch file======

diff -Naurp old_file new_file > production.patch
產生patch file是用diff指令,至於要下哪些參數可以
參考diff --help來使用


====apply patch file======
patch
-p之後接數字代表要patch(更新)的file目
錄檔案從哪邊開始可以參考patch file的
第一行所寫的路經

patch -p數字 < patch_file_path

還原:
 patch -R <  patch_file_path

2013年12月29日 星期日

mount NTFS fs

linux cmd:

1. check partition information and make sure what partition you wan to mount:
               fdisk -l
    ex:
[root@adamlee adam]# fdisk -l

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xe84788aa

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1        3919    31479336    7  HPFS/NTFS
/dev/sda2            3920       19457   124808985    f  W95 Ext'd (LBA)
/dev/sda5            3920       11752    62918541    7  HPFS/NTFS
/dev/sda6   *       11753       11778      204799+  83  Linux
/dev/sda7           11778       18305    52428799+  83  Linux
/dev/sda8           18305       18827     4194303+  82  Linux swap / Solaris

Disk /dev/sdb: 4027 MB, 4027580416 bytes
117 heads, 29 sectors/track, 2318 cylinders
Units = cylinders of 3393 * 512 = 1737216 bytes
Disk identifier: 0x00000000

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1        2318     3932113    c  W95 FAT32 (LBA)

2. mount:
              mount -t ntfs /dev/sda1  /media/NTFSpartition

3. umount
              umount -t ntfs /dev/sda1

2013年9月30日 星期一

check network interface traffic

 要check interface 網路流量,提供以下幾個方法

法1: 使用ifconfig + interface name

 ex:
[root@localhost ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:A6:F8:0D
          inet addr:192.168.10.128  Bcast:192.168.10.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fea6:f80d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:150 errors:0 dropped:0 overruns:0 frame:0  ==>看Rx 
          TX packets:146 errors:0 dropped:0 overruns:0 carrier:0 ==>看Tx
          collisions:0 txqueuelen:1000
          RX bytes:17994 (17.5 KiB)  TX bytes:21413 (20.9 KiB)
          Interrupt:18 Base address:0x2000

     

法2: 使用sys 的 statistics

ex: 
cat /sys/class/net/eth0/statistics/rx_packets   
(看Rx ,以packet為單位)
cat /sys/class/net/eth0/statistics/tx_packets
(看Tx ,以packet為單位)

cat /sys/class/net/eth0/statistics/rx_bytes
(看Rx ,以byte為單位)
cat /sys/class/net/eth0/statistics/tx_bytes
(看Rx ,以byte為單位)

法3: 利用/proc/net/dev

cat /proc/net/dev 可以check所有interface的traffic

ex:
 [root@localhost ~]# cat /proc/net/dev
Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:     560       8    0    0    0     0          0         0      560       8    0    0    0     0       0          0
  eth0:   35898     360    0    0    0     0          0         0    36441     284    0    0    0     0       0          0
[root@localhost ~]#


2013年8月21日 星期三

變更VMware httpd port number


1.修改 /etc/httpd/conf/httpd.conf裡面
    的Listen選項為要變更的port(預設是80)
     ex: Listen 8081

2./etc/init.d/httpd restart

3.VMware NAT setting:
     virtual machine port要改成變更的port




4.在browser網址列打完IP要接欲使用的port number
    ex:192.168.1.100:8081

2013年7月22日 星期一

daemon 啟動方式

Stand alone daemon啟動方式:

/etc/init.d/app_script command
command = start/stop/restart
ex: /etc/init.d/vsfptd restart

Super daemon啟動方式 :

 super daemon統一管理許多服務
/etc/init.d/xinetd command
如果需要增加新的服務請到
xinetd config設定 = /etc/xinetd.conf

ex: /etc/init.d/xinetd start

2013年7月9日 星期二

FTP mode (Active/Passive)

FTP使用command channel與data channel進行連線傳輸
command channel 一般是走port 21,而data channel則是
port 20(server 預設)

FTP的傳輸模式可分為Active mode 與 Passive mode

(主動模式)Active mode:

在client先用command channel連上Server之後,
如果需要傳輸資料,client端會再發出一個PORT
cmd給Server提出資料連線的需求
ex: PORT 172,17,21,100,210,102
Server收到後會利用port20向 client端的某一個port進行
連線(使用3-way handshake),其中這個某一port要從
PORT cmd算出,計算方式如下:
ex:
PORT 172,17,21,100,210,102
210x256+102=53862(client port)

整個流程大概是這樣
(command channel 3-way handshake)
(port >1024)Clinet------SYN------------>Server(port 21)
(port >1024)Client<------SYN,ACK------------Server(port 21)   
(port >1024)Client------ACK------------>Server(port 21)
                                                .
                                                .
(port >1024)Client------PORT 172,17,21,100,210,102----->Server(port 21)
(port >1024)Client<---PORT command successful-----Server(port 21)
cleint與server協調好要用的port後,主動式(active)模式下
是由Server發起連線通知給Client
(data channel 3-way handshake)
(port 20)Server------SYN------------>Client(port 53862)
(port 20)Server<------SYN,ACK------------Client(port 53862)   
(port 20)Server------ACK------------>Client(port 53862)

(被動模式)Passive mode:

client用command channel連上Server之後
再發出PASV cmd,Server端收到這個PASV cmd
之後會回傳 Entering Passive Mode後面代一串數字
(172,17,21,74,181,15)代表Server所要使用的data channel port
計算方式相同
ex:
172,17,21,74,181,15
181x256+15=46351(Server欲使用的data chaenel port)

(port >1024)Clinet------SYN------------>Server(port 21)
(port >1024)Client<------SYN,ACK------------Server(port 21)   
(port >1024)Client------ACK------------>Server(port 21)
                                                .
                                                .
(port >1024)Client---------PASV---------------->Server(port 21)
(port >1024)Client<---Entering Passive Mode-----Server(port 21)
           (172,17,21,74,181,15)
server與Client協調好要用的port後,被動式(Passive)模式下
是由Client發起連線通知給Server
(data channel 3-way handshake)
(port >1024)Client------SYN------------>Server(port 46351)
(port >1024)Client<------SYN,ACK------------Server(port 46351)   
(port >1024)Client------ACK------------>Server(port 46351)

主動模式的缺點是如果client端在firewall或是NAT之後,就會造成server用port 20要連到client端時可能被firewall擋住就進不到client端,這時可能會發現明明就連接上 FTP 伺服器了 (命令通道已建立),但是就是無法取得檔案名稱的列表,而是在超過一段時間後顯示『  Can't build data connection: Connection refused,無法進行資料傳輸』之類的訊息, 那肯定就是這個原因所造成的困擾了。

被動模式則可以解決這個問題,因為主動式是由Server向Client端發起連線,而被動式就是由Client向Server端發起連線, 既然是由Client發起連線,那麼自然就不需要考慮來自 port 20 的連線,所以就不會有firewall/NAT的問題了。


詳細可以參考鳥哥:
http://linux.vbird.org/linux_server/0410vsftpd.php

2013年6月24日 星期一

scp

scp用法


1.複製遠端檔案到本地端
   scp -r  username@host:/remotePath/remoteFile /localPath/localfile
  ex:
    scp -r root@11.22.33.44:/root/install.log /home/install.log

2.複製本地端檔案到遠端

   scp localfile username@host:/remotePath/remoteFile
ex:
   scp /home/test.txt root@11.22.33.44:/root/tmp/test.txt