Ping(全稱 Packet InterNet Groper) 是一種用來測試封包是否能通過 IP 協議到達特定主機的管理員工具。
Ping 程式通過向目標主機發送一個ICMP 請求,並等待其回應封包。它根據時間和成功次數來計算數據丟包率以及數據往返時間(Rouad-trip time, RTT)。
$ ping -help Usage: ping [-LRUbdfnqrvVaAD] [-c count] [-i interval] [-w deadline] [-p pattern] [-s packetsize] [-t ttl] [-I interface] [-M pmtudisc-hint] [-m mark] [-S sndbuf] [-T tstamp-options] [-Q tos] [hop1 ...] destination
目前許多系統也提供了用來測試 IPv6 網絡的ping6 工具。
$ ping6 -help Usage: ping6 [-LUdfnqrvVaAD] [-c count] [-i interval] [-w deadline] [-p pattern] [-s packetsize] [-t ttl] [-I interface] [-M pmtudisc-hint] [-S sndbuf] [-F flowlabel] [-Q tclass] [[-N nodeinfo-option] ...] [hop1 ...] destination
C:\>ping /? Usage: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS] [-r count] [-s count] [[-j host-list] | [-k host-list]] [-w timeout] [-R] [-S srcaddr] [-4] [-6] target_name Options: -t Ping the specified host until stopped. To see statistics and continue - type Control-Break; To stop - type Control-C. -a Resolve addresses to hostnames. -n count Number of echo requests to send. -l size Send buffer size. -f Set Don't Fragment flag in packet (IPv4-only). -i TTL Time To Live. -v TOS Type Of Service (IPv4-only. This setting has been deprecated and has no effect on the type of service field in the IP Header). -r count Record route for count hops (IPv4-only). -s count Timestamp for count hops (IPv4-only). -j host-list Loose source route along host-list (IPv4-only). -k host-list Strict source route along host-list (IPv4-only). -w timeout Timeout in milliseconds to wait for each reply. -R Use routing header to test reverse route also (IPv6-only). -S srcaddr Source address to use. -4 Force using IPv4. -6 Force using IPv6.
在 Linux 系統下,運行ping 程式,向 www.yahoo.com 發送 5 個測試封包的輸出結果:
$ ping -c 5 www.yahoo.com PING www.yahoo.com (116.214.12.74) 56(84) bytes of data. 64 bytes from 116.214.12.74: icmp_req=1 ttl=47 time=22.8 ms 64 bytes from 116.214.12.74: icmp_req=2 ttl=47 time=22.3 ms 64 bytes from 116.214.12.74: icmp_req=3 ttl=47 time=22.8 ms 64 bytes from 116.214.12.74: icmp_req=4 ttl=47 time=22.2 ms 64 bytes from 116.214.12.74: icmp_req=5 ttl=47 time=22.2 ms --- www.yahoo.com ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4005ms rtt min/avg/max/mdev = 22.228/22.503/22.853/0.316 ms
程式在完成 ping 檢測之後,輸出了詳細的結果信息。數據往返時間(RTT)為 22.228 ms, 平均時間為 22.503 ms, 最長時間為 22.853 ms,其中測量的誤差為0.316 ms。