13.網絡系統(快樂的Linux命令行)

1.學習的指令

ping Send an ICMP ECHO_REQUEST to network hosts
traceroute Print the route packets trace to a network host
netstat Print network state
ftp Internet file transfer program
wget Non-interactive network downloader
ssh remote login program

2.小知識

知識點1:ping命令的具體過程

ping 命令發送網絡數據包,叫做 ICMP ECHO_REQUEST,到指定的主機。多數接收這個的網絡設備會回覆它,來進行網絡連接驗證。

知識點2:traceroute命令的作用

traceroute 程序會顯示從本地到指定主機,要經過的所有“跳數”的網絡流量列表。

知識點3:ftp操作各選項的意義

ftp fileserver 喚醒 ftp 程序,讓它連接到 FTP 服務器,fileserver。
anonymous 登錄名。輸入登錄名後,將出現一個密碼提示。可能是空密碼,也可能是 “[email protected]”。
cd pub/cd_images/Ubuntu-8.04 跳轉到遠端系統中,要下載文件所在的目錄下, 大多數文件都能在pub下找到
ls 列出遠端系統中的目錄。
lcd Desktop 跳轉到本地系統中的 ~/Desktop 目錄下。 這個命令把工作目錄改爲 ~/Desktop,多了個l
get ubuntu-8.04-desktop-i386.iso 告訴遠端系統傳送文件到本地。因爲工作目錄 已經更改到 ~/Desktop,所以會被下載到此目錄。
bye 退出遠端服務器,結束 ftp 程序會話。也可以使用命令 quit 和 exit。

 

知識點4:lftp與ftp的區別?

沒什麼區別就是lftp更高級,比如直接可以用Tab鍵進行補全代碼。

知識點5:wget與ftp的區別?

答:wget可以在網絡下進行下載,也可以在ftp下進行下載。所以很有用。

知識點6:若連接主機密碼也就修改,如何通過SSH進行重新連接?

答:進入~/.ssh/known_hosts 刪除 offend key 即廢棄的鑰匙,再進行連接

3.代碼實操

 

[me@linuxbox ~]$ ping linuxcommand.org
[me@linuxbox ~]$ ping linuxcommand.org
PING linuxcommand.org (66.35.250.210) 56(84) bytes of data.
64 bytes from vhost.sourceforge.net (66.35.250.210): icmp\_seq=1
ttl=43 time=107 ms
64 bytes from vhost.sourceforge.net (66.35.250.210): icmp\_seq=2
ttl=43 time=108 ms
64 bytes from vhost.sourceforge.net (66.35.250.210): icmp\_seq=3
ttl=43 time=106 ms
64 bytes from vhost.sourceforge.net (66.35.250.210): icmp\_seq=4
ttl=43 time=106 ms
64 bytes from vhost.sourceforge.net (66.35.250.210): icmp\_seq=5
ttl=43 time=105 ms
...

[me@linuxbox ~]$ traceroute slashdot.org
traceroute to slashdot.org (216.34.181.45), 30 hops max, 40 byte
packets
1 ipcop.localdomain (192.168.1.1) 1.066 ms 1.366 ms 1.720 ms
2 * * *
3 ge-4-13-ur01.rockville.md.bad.comcast.net (68.87.130.9) 14.622
ms 14.885 ms 15.169 ms
4 po-30-ur02.rockville.md.bad.comcast.net (68.87.129.154) 17.634
ms 17.626 ms 17.899 ms
5 po-60-ur03.rockville.md.bad.comcast.net (68.87.129.158) 15.992
ms 15.983 ms 16.256 ms
6 po-30-ar01.howardcounty.md.bad.comcast.net (68.87.136.5) 22.835
...
注:從輸出結果中,我們可以看到連接測試系統到 slashdot.org 網站需要經由16個路由器。對於那些提供標
識信息的路由器,我們能看到它們的主機名,IP 地址和性能數據,這些數據包括三次從本地到此路由器的往返
時間樣本。對於那些沒有提供標識信息的路由器(由於路由器配置,網絡擁塞,防火牆等 方面的原因),我們
會看到幾個星號

[me@linuxbox ~]$ netstat -ie
eth0    Link encap:Ethernet HWaddr 00:1d:09:9b:99:67
        inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
        inet6 addr: fe80::21d:9ff:fe9b:9967/64 Scope:Link
        UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
        RX packets:238488 errors:0 dropped:0 overruns:0 frame:0
        TX packets:403217 errors:0 dropped:0 overruns:0 carrier:0
        collisions:0 txqueuelen:100 RX bytes:153098921 (146.0 MB) TX
        bytes:261035246 (248.9 MB) Memory:fdfc0000-fdfe0000

lo      Link encap:Local Loopback
        inet addr:127.0.0.1 Mask:255.0.0.0
...
[me@linuxbox ~]$ netstat -r
Kernel IP routing table
Destination     Gateway     Genmask         Flags    MSS  Window  irtt Iface

192.168.1.0     *           255.255.255.0   U        0    0          0 eth0
default         192.168.1.1 0.0.0.0         UG       0    0          0 eth0
注:-ie等同於ifconfig  -r 顯示內核網絡路由表


[me@linuxbox ~]$ ftp fileserver
Connected to fileserver.localdomain.
220 (vsFTPd 2.0.1)
Name (fileserver:me): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> cd pub/cd\_images/Ubuntu-8.04
250 Directory successfully changed.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-rw-r-- 1 500 500 733079552 Apr 25 03:53 ubuntu-8.04- desktop-i386.iso
226 Directory send OK.
ftp> lcd Desktop
Local directory now /home/me/Desktop
ftp> get ubuntu-8.04-desktop-i386.iso
local: ubuntu-8.04-desktop-i386.iso remote: ubuntu-8.04-desktop-
i386.iso
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for ubuntu-8.04-desktop-
i386.iso (733079552 bytes).
226 File send OK.
733079552 bytes received in 68.56 secs (10441.5 kB/s)
ftp> bye
注:從匿名 FTP 服務器,其名字是 fileserver, 的/pub/_images/Ubuntu-8.04的目錄下,使用 ftp 程
序下載一個 Ubuntu 系統映像文件。

[me@linuxbox ~]$ wget http://linuxcommand.org/index.php
--11:02:51-- http://linuxcommand.org/index.php
        => `index.php'
Resolving linuxcommand.org... 66.35.250.210
Connecting to linuxcommand.org|66.35.250.210|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]

  [ <                        => ]        3,120       --.--K/s

11:02:51 (161.75 MB/s) - 'index.php' saved [3120]

[me@linuxbox ~]$ ssh remote-sys
The authenticity of host 'remote-sys (192.168.1.4)' can't be
established.
RSA key fingerprint is
41:ed:7a:df:23:19:bf:3c:a5:17:bc:61:b3:7f:d9:bb.
Are you sure you want to continue connecting (yes/no)?
Warning: Permanently added 'remote-sys,192.168.1.4' (RSA) to the list
of known hosts.
me@remote-sys's password:
Last login: Sat Aug 30 13:00:48 2008
注:連接到remote-sys的遠程主機

[me@linuxbox ~]$ ssh bob@remote-sys
bob@remote-sys's password:
Last login: Sat Aug 30 13:03:21 2008
注:使用不同的賬號進行來連接remote-sys

[me@linuxbox ~]$ ssh remote-sys free
me@twin4's password:
            total   used       free     shared buffers cached

Mem:        775536  507184   268352          0  110068 154596

-/+ buffers/cache: 242520  533016
Swap: 0 1572856 0 110068 154596
注:通過遠程操作free命令

[me@linuxbox ~]$ ssh remote-sys 'ls \*' > dirlist.txt
me@twin4's password:
注:將遠程的結果導入到本地。若加單引號則傳入到遠程端,看下段代碼。
[me@linuxbox ~]$ ssh remote-sys 'ls * > dirlist.txt'

[me@linuxbox ~]$ scp remote-sys:document.txt .
me@remote-sys's password:
document.txt
100%        5581        5.5KB/s         00:00
注:從 remote-sys 遠端系統的家目錄下複製文檔 document.txt,到我們本地系統的當前工作目錄下

[me@linuxbox ~]$ sftp remote-sys
Connecting to remote-sys...
me@remote-sys's password:
sftp> ls
ubuntu-8.04-desktop-i386.iso
sftp> lcd Desktop
sftp> get ubuntu-8.04-desktop-i386.iso
Fetching /home/me/ubuntu-8.04-desktop-i386.iso to ubuntu-8.04-
desktop-i386.iso
/home/me/ubuntu-8.04-desktop-i386.iso 100% 699MB 7.4MB/s 01:35
sftp> bye
注:SSH 文件複製程序是 sftp,顧名思義,它是 ftp 程序的安全替代品。
發佈了59 篇原創文章 · 獲贊 11 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章