ping命令

? ? ? ? ? ?Linux系統的ping命令是常用的網絡命令,它通常用來測試與目標主機的連通性,我們經常會說“ping一下某機器,看是不是開著”、不能打開網頁時會說“你先ping網關地址192.168.1.1試試”。它通過發送ICMP?ECHO_REQUEST數據包到網絡主機 (send?ICMP?ECHO_REQUEST?to?network?hosts),并顯示響應情況,這樣我們就可以根據它輸出的信息來確定目標主機是否可訪問(但這不是絕對的)。有些服務器為了防止通過ping探測到,通過防火墻設置了禁止ping或者在內核參數中禁止ping,這樣就不能通過ping確定該主機是否還處于開啟狀態。

linux下的ping和windows下的ping稍有區別,linux下ping不會自動終止,需要按ctrl+c終止或者用參數-c指定要求完成的回應次數。


1.命令格式:

ping?[參數]?[主機名或IP地址]

2.命令功能:

ping命令用于:確定網絡和各外部主機的狀態;跟蹤和隔離硬件和軟件問題;測試、評估和管理網絡。如果主機正在運行并連在網上,它就對回送信號進行響應。每個回送信號請求包含一個網際協議(IP)和?ICMP?頭,后面緊跟一個?tim?結構,以及來填寫這個信息包的足夠的字節。缺省情況是連續發送回送信號請求直到接收到中斷信號(Ctrl-C)。

ping?命令每秒發送一個數據報并且為每個接收到的響應打印一行輸出。ping?命令計算信號往返時間和(信息)包丟失情況的統計信息,并且在完成之后顯示一個簡要總結。ping?命令在程序超時或當接收到?SIGINT?信號時結束。Host?參數或者是一個有效的主機名或者是因特網地址。

3.命令參數:

-d?使用Socket的SO_DEBUG功能。

-f??極限檢測。大量且快速地送網絡封包給一臺機器,看它的回應。

-n?只輸出數值。

-q?不顯示任何傳送封包的信息,只顯示最后的結果。

-r?忽略普通的Routing?Table,直接將數據包送到遠端主機上。通常是查看本機的網絡接口是否有問題。

-R?記錄路由過程。

-v?詳細顯示指令的執行過程。

<p>-c?數目:在發送指定數目的包后停止。

-i?秒數:設定間隔幾秒送一個網絡封包給一臺機器,預設值是一秒送一次。

-I?網絡界面:使用指定的網絡界面送出數據包。

-l?前置載入:設置在送出要求信息之前,先行發出的數據包。

-p?范本樣式:設置填滿數據包的范本樣式。

-s?字節數:指定發送的數據字節數,預設值是56,加上8字節的ICMP頭,一共是64ICMP數據字節。

-t?存活數值:設置存活數值TTL的大小。

4.使用實例:

實例1:ping的通的情況

命令:

ping?192.168.120.205

輸出:

[root@localhost ~]# ping 192.168.120.205

PING 192.168.120.205 (192.168.120.205) 56(84) bytes of data.

bytes from 192.168.120.205: icmp_seq=1 ttl=64 time=0.720 ms

bytes from 192.168.120.205: icmp_seq=2 ttl=64 time=0.181 ms

bytes from 192.168.120.205: icmp_seq=3 ttl=64 time=0.191 ms

bytes from 192.168.120.205: icmp_seq=4 ttl=64 time=0.188 ms

bytes from 192.168.120.205: icmp_seq=5 ttl=64 time=0.189 ms

--- 192.168.120.205 ping statistics ---

packets transmitted, 5 received, 0% packet loss, time 4000ms

rtt min/avg/max/mdev = 0.181/0.293/0.720/0.214 ms

[root@localhost ~]#


實例2:ping不通的情況

命令:

ping?192.168.120.202

輸出:

[root@localhost ~]# ping 192.168.120.202

PING 192.168.120.202 (192.168.120.202) 56(84) bytes of data.

From 192.168.120.204 icmp_seq=1 Destination Host Unreachable

From 192.168.120.204 icmp_seq=2 Destination Host Unreachable

From 192.168.120.204 icmp_seq=3 Destination Host Unreachable

From 192.168.120.204 icmp_seq=4 Destination Host Unreachable

From 192.168.120.204 icmp_seq=5 Destination Host Unreachable

From 192.168.120.204 icmp_seq=6 Destination Host Unreachable

--- 192.168.120.202 ping statistics ---

packets transmitted, 0 received, +6 errors, 100% packet loss, time 7005ms

, pipe 4

[root@localhost ~]#


實例3:ping網關

命令:

ping?-b?192.168.120.1

輸出:

[root@localhost ~]# route

Kernel IP routing table

Destination? ? Gateway? ? ? ? Genmask? ? ? ? Flags Metric Ref? ? Use Iface

192.168.120.0? *? ? ? ? ? ? ? 255.255.255.0? U? ? 0? ? ? 0? ? ? ? 0 eth0

192.168.0.0? ? 192.168.120.1? 255.255.0.0? ? UG? ? 0? ? ? 0? ? ? ? 0 eth0

10.0.0.0? ? ? ? 192.168.120.1? 255.0.0.0? ? ? UG? ? 0? ? ? 0? ? ? ? 0 eth0

default? ? ? ? 192.168.120.240 0.0.0.0? ? ? ? UG? ? 0? ? ? 0? ? ? ? 0 eth0

[root@localhost ~]# ping -b 192.168.120.1

PING 192.168.120.1 (192.168.120.1) 56(84) bytes of data.

bytes from 192.168.120.1: icmp_seq=1 ttl=255 time=2.02 ms

bytes from 192.168.120.1: icmp_seq=2 ttl=255 time=1.83 ms

bytes from 192.168.120.1: icmp_seq=3 ttl=255 time=1.68 ms

bytes from 192.168.120.1: icmp_seq=4 ttl=255 time=1.98 ms

bytes from 192.168.120.1: icmp_seq=5 ttl=255 time=1.88 ms

--- 192.168.120.1 ping statistics ---

packets transmitted, 5 received, 0% packet loss, time 4000ms

rtt min/avg/max/mdev = 1.682/1.880/2.020/0.129 ms


實例4:ping指定次數

命令:

ping?-c?10?192.168.120.206

輸出:

[root@localhost ~]# ping -c 10 192.168.120.206

PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.

bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.25 ms

bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.260 ms

bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.242 ms

bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.271 ms

bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.274 ms

bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.295 ms

bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.269 ms

bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.270 ms

bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.253 ms

bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.289 ms

--- 192.168.120.206 ping statistics ---

packets transmitted, 10 received, 0% packet loss, time 9000ms

rtt min/avg/max/mdev = 0.242/0.367/1.251/0.295 ms

[root@localhost ~]#


實例5:時間間隔和次數限制的ping

命令:

ping?-c?10?-i?0.5?192.168.120.206

輸出:

[root@localhost ~]# ping -c 10 -i 0.5 192.168.120.206

PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.

bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.24 ms

bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.235 ms

bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.244 ms

bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.300 ms

bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.255 ms

bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.264 ms

bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.263 ms

bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.331 ms

bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.247 ms

bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.244 ms

--- 192.168.120.206 ping statistics ---

packets transmitted, 10 received, 0% packet loss, time 4499ms

rtt min/avg/max/mdev = 0.235/0.362/1.241/0.294 ms

[root@localhost ~]# ping -c 10 -i 0.01 192.168.120.206

PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.

bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=0.244 ms

bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.195 ms

bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.219 ms

bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.204 ms

bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=3.56 ms

bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=1.93 ms

bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.193 ms

bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.193 ms

bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.202 ms

bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.211 ms

--- 192.168.120.206 ping statistics ---

packets transmitted, 10 received, 0% packet loss, time 90ms

rtt min/avg/max/mdev = 0.193/0.716/3.564/1.080 ms

[root@localhost ~]#


實例6:通過域名ping公網上的站點

命令:

ping?-c?5?www.58.com

輸出:

peida-VirtualBox ~ # ping -c 5 www.58.com

PING www.58.com (211.151.111.30) 56(84) bytes of data.

bytes from 211.151.111.30: icmp_req=1 ttl=49 time=14.7 ms

bytes from 211.151.111.30: icmp_req=2 ttl=49 time=16.4 ms

bytes from 211.151.111.30: icmp_req=3 ttl=49 time=15.2 ms

bytes from 211.151.111.30: icmp_req=4 ttl=49 time=14.6 ms

bytes from 211.151.111.30: icmp_req=5 ttl=49 time=19.9 ms

--- www.58.com ping statistics ---

packets transmitted, 5 received, 0% packet loss, time 20101ms

rtt min/avg/max/mdev = 14.618/16.192/19.917/1.965 ms

peida-VirtualBox ~ #


實例7:多參數使用

命令:

ping?-i?3?-s?1024?-t?255?192.168.120.206

輸出:

[root@localhost ~]# ping -i 3 -s 1024 -t 255 192.168.120.206

PING 192.168.120.206 (192.168.120.206) 1024(1052) bytes of data.

bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.99 ms

bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.694 ms

bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.300 ms

bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.481 ms

bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.415 ms

bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.600 ms

bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.411 ms

bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.281 ms

bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.318 ms

bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.362 ms

bytes from 192.168.120.206: icmp_seq=11 ttl=64 time=0.408 ms

bytes from 192.168.120.206: icmp_seq=12 ttl=64 time=0.445 ms

bytes from 192.168.120.206: icmp_seq=13 ttl=64 time=0.397 ms

bytes from 192.168.120.206: icmp_seq=14 ttl=64 time=0.406 ms

bytes from 192.168.120.206: icmp_seq=15 ttl=64 time=0.458 ms

--- 192.168.120.206 ping statistics ---

packets transmitted, 15 received, 0% packet loss, time 41999ms

rtt min/avg/max/mdev = 0.281/0.531/1.993/0.404 ms

[root@localhost ~]#

說明:

-i?3?發送周期為?3秒?-s?設置發送包的大小為1024?-t?設置TTL值為?255


轉載至:https://www.cnblogs.com/peida/archive/2013/03/06/2945407.html

?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 230,825評論 6 546
  • 序言:濱河連續發生了三起死亡事件,死亡現場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發現死者居然都...
    沈念sama閱讀 99,814評論 3 429
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 178,980評論 0 384
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 64,064評論 1 319
  • 正文 為了忘掉前任,我火速辦了婚禮,結果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,779評論 6 414
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
    開封第一講書人閱讀 56,109評論 1 330
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 44,099評論 3 450
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 43,287評論 0 291
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當地人在樹林里發現了一具尸體,經...
    沈念sama閱讀 49,799評論 1 338
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 41,515評論 3 361
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發現自己被綠了。 大學時的朋友給我發了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,750評論 1 375
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 39,221評論 5 365
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質發生泄漏。R本人自食惡果不足惜,卻給世界環境...
    茶點故事閱讀 44,933評論 3 351
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,327評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,667評論 1 296
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,492評論 3 400
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,703評論 2 380

推薦閱讀更多精彩內容