ping命令用來測試主機之間網絡的連通性。執行ping指令會使用ICMP傳輸協議,發出要求迴應的信息,若遠端主機的網絡功能沒有問題,就會迴應該信息,於是得知該主機運做正常。html
ping(選項)(參數)
-d:使用Socket的SO_DEBUG功能; -c<完成次數>:設置完成要求迴應的次數; -f:極限檢測; -i<間隔秒數>:指定收發信息的間隔時間; -I<網絡界面>:使用指定的網絡界面送出數據包; -l<前置載入>:設置在送出要求信息以前,先行發出的數據包; -n:只輸出數值; -p<範本樣式>:設置填滿數據包的範本樣式; -q:不顯示指令執行過程,開頭和結尾的相關信息除外; -r:忽略普通的Routing Table,直接將數據包送到遠端主機上; -R:記錄路由過程; -s<數據包大小>:設置數據包的大小; -t<存活數值>:設置存活數值TTL的大小; -v:詳細顯示指令的執行過程。
ping命令經過ICMP(Internet控制消息協議)工做;ping能夠用來測試本機與目標主機是否聯通、聯通速度如何、穩定性如何。
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
|
參數 | 詳解 |
---|---|
-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; |
1
2
3
4
5
6
7
8
9
10
11
|
[root@aiezu.com ~]
# 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
|
1
2
3
4
5
6
|
[root@aiezu ~]
# 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
|
1
2
3
4
5
6
7
8
9
|
[root@aiezu.com ~]
# 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
rtt min
/avg/max/mdev
= 32.038
/32
.208
/32
.362
/0
.246 ms
|
1
2
3
4
5
|
[root@aiezu.com ~]
# ping -c 3 9.9.9.9
PING 9.9.9.9 (9.9.9.9) 56(84) bytes of data.
--- 9.9.9.9
ping
statistics ---
3 packets transmitted, 0 received, 100% packet loss,
time
1999ms
|
1
|
ping: packet size too large: 70000
|
1
2
3
4
|
WARNING: packet size 65508 is too large. Maximum is 65507
PING 10.0.0.52 (10.0.0.52) 65508(65536) bytes of data.
ping: local error: Message too long, mtu=1500
ping: local error: Message too long, mtu=1500
|