Linux 常用ping命令詳解(adb shell)
一、ping用法:
ping命令執行在命令提示符終端,用法為:“ping 引數 目標主機”。其中引數為零到多個,目標主機可以是IP或者域名。
1 2 3 4 |
Usage: ping [-aAbBdDfhLnOqrRUvV]
[-c count] [-i interval] [-I interface]
[-m
mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
[-s
packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
[-w
deadline] [-W timeout] [hop1 ...] destination |
二、ping引數詳解:
下面是愛E族(aiezu.com)收集整理的ping詳細引數,可能部分不全或翻譯錯誤,歡迎指正:
引數 | 詳解 |
---|---|
-a | Audible ping. |
-A | 自適應ping,根據ping包往返時間確定ping的速度; |
-b | 允許ping一個廣播地址; |
-B | 不允許ping改變包頭的源地址; |
-c count | ping指定次數後停止ping; |
-d | 使用Socket的SO_DEBUG功能; |
-F flow_label | 為ping回顯請求分配一個20位的“flow label”,如果未設定,核心會為ping隨機分配; |
-f | 極限檢測,快速連續ping一臺主機,ping的速度達到100次每秒; |
-i interval | 設定間隔幾秒傳送一個ping包,預設一秒ping一次; |
-I interface | 指定網絡卡介面、或指定的本機地址送出資料包; |
-l preload | 設定在送出要求資訊之前,先行發出的資料包; |
-L | 抑制組播報文回送,只適用於ping的目標為一個組播地址 |
-n | 不要將ip地址轉換成主機名; |
-p pattern | 指定填充ping資料包的十六進位制內容,在診斷與資料有關的網路錯誤時這個選項就非常有用,如:“-p ff”; |
-q | 不顯示任何傳送封包的資訊,只顯示最後的結果 |
-Q tos | 設定Qos(Quality of Service),它是ICMP資料報相關位;可以是十進位制或十六進位制數,詳見rfc1349和rfc2474文件; |
-R |
記錄ping的路由過程(IPv4 only); 注意:由於IP頭的限制,最多隻能記錄9個路由,其他會被忽略; |
-r | 忽略正常的路由表,直接將資料包送到遠端主機上,通常是檢視本機的網路介面是否有問題;如果主機不直接連線的網路上,則返回一個錯誤。 |
-S sndbuf | Set socket sndbuf. If not specified, it is selected to buffer not more than one packet. |
-s packetsize |
指定每次ping傳送的資料位元組數,預設為“56位元組”+“28位元組”的ICMP頭,一共是84位元組; 包頭+內容不能大於65535,所以最大值為65507(linux:65507, windows:65500); |
-t ttl | 設定TTL(Time To Live)為指定的值。該欄位指定IP包被路由器丟棄之前允許通過的最大網段數; |
-T timestamp_option |
設定IP timestamp選項,可以是下面的任何一個: 'tsonly' (only timestamps) 'tsandaddr' (timestamps and addresses) 'tsprespec host1 [host2 [host3]]' (timestamp prespecified hops). |
-M hint |
設定MTU(最大傳輸單元)分片策略。 可設定為: 'do':禁止分片,即使包被丟棄; 'want':當包過大時分片; 'dont':不設定分片標誌(DF flag); |
-m mark | 設定mark; |
-v | 使ping處於verbose方式,它要ping命令除了列印ECHO-RESPONSE資料包之外,還列印其它所有返回的ICMP資料包; |
-U |
Print full user-to-user latency (the old behaviour). Normally ping prints network round trip time, which can be different f.e. due to DNS failures. |
-W timeout | 以毫秒為單位設定ping的超時時間; |
-w deadline | deadline; |
三、輸出格式:
下圖為簡單的ping產生的響應內容,圖中返回內容具體的含義如下:
- ① ping目標主機的域名和IP(ping會自動將域名轉換為IP)
- ② 不帶包頭的包大小和帶包頭的包大小(參考“-s”引數)
- ③ icmp_seq:ping序列,從1開始;
- ttl:剩餘的ttl;
- time: 響應時間,數值越小,聯通速度越快;
- ④ 發出去的包數,返回的包數,丟包率,耗費時間;
- ⑤ 最小/最大/平均響應時間和本機硬體耗費時間;
四、簡單例子:
1、每隔0.6秒ping一次,一共ping 5次:
1 2 3 4 5 6 7 8 9 10 11 |
[[email protected]
~] #
ping -c 5 -i 0.6 qq.com
PING
qq.com (14.17.32.211) 56(84) bytes of data.
64
bytes from 14.17.32.211: icmp_seq=1 ttl=54 time =16.5
ms
64
bytes from 14.17.32.211: icmp_seq=2 ttl=54 time =17.0
ms
64
bytes from 14.17.32.211: icmp_seq=3 ttl=54 time =16.6
ms
64
bytes from 14.17.32.211: icmp_seq=4 ttl=54 time =18.3
ms
64
bytes from 14.17.32.211: icmp_seq=5 ttl=54 time =19.9
ms
---
qq.com ping statistics
---
5
packets transmitted, 5 received, 0% packet loss, time 2405ms
rtt
min /avg/max/mdev =
16.520 /17 .692 /19 .919 /1 .293
ms
|
2、極限快速的使用大包ping:
以最快的速度,使用最大的包進行ping,可用於測試目標主機的承壓能力:
1 2 3 4 5 6 |
[[email protected]
~] #
ping -f -s 65507 10.0.0.52
PING
10.0.0.52 (10.0.0.52) 65507(65535) bytes of data.
.^
---
10.0.0.52 ping statistics
---
646
packets transmitted, 646 received, 0% packet loss, time 1675ms
rtt
min /avg/max/mdev =
1.202 /2 .406 /8 .253 /0 .507
ms, ipg /ewma 2.598 /2 .318
ms
|
3、聯通不穩定,丟包嚴重的情形:
下面的ping發出17個ping icmp包,而只有序號為8、9、12的包收到響應資訊,丟包率達82%,聯通非常不穩定:
1 2 3 4 5 6 7 8 9 |
[[email protected]
~] #
ping 8.8.8.8
PING
8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64
bytes from 8.8.8.8: icmp_seq=8 ttl=43 time =32.3
ms
64
bytes from 8.8.8.8: icmp_seq=9 ttl=43 time =32.2
ms
64
bytes from 8.8.8.8: icmp_seq=12 ttl=43 time =32.0
ms
^C
---
8.8.8.8 ping statistics
---
17
packets transmitted, 3 received, 82% packet loss, time 16003ms
|