linux中的ping命令的詳細解釋
linux中的ping命令的詳細解釋
linxu下的ping命令的主要功能就是確定網(wǎng)絡狀態(tài),下面由學習啦小編為大家整理了linux的ping命令的詳細解釋的相關知識,希望對大家有幫助!
一、linux中的ping命令的詳細解釋
1.命令格式:
ping [參數(shù)] [主機名或IP地址]
2.命令功能:
ping命令用于:確定網(wǎng)絡和各外部主機的狀態(tài);跟蹤和隔離硬件和軟件問題;測 試、評估和管理網(wǎng)絡。如果主機正在運行并連在網(wǎng)上,它就對回送信號進行響應。每個回送信號請求包含一個網(wǎng)際協(xié)議(IP)和 ICMP 頭,后面緊跟一 個 tim 結構,以及來填寫這個信息包的足夠的字節(jié)。缺省情況是連續(xù)發(fā)送回送信號請求直到接收到中斷信號(Ctrl-C)。
ping 命 令每秒發(fā)送一個數(shù)據(jù)報并且為每個接收到的響應打印一行輸出。ping 命令計算信號往返時間和(信息)包丟失情況的統(tǒng)計信息,并且在完成之后顯示一個簡要 總結。ping 命令在程序超時或當接收到 SIGINT 信號時結束。Host 參數(shù)或者是一個有效的主機名或者是因特網(wǎng)地址。
3.命令參數(shù):
-d 使用Socket的SO_DEBUG功能。
-f 極限檢測。大量且快速地送網(wǎng)絡封包給一臺機器,看它的回應。
-n 只輸出數(shù)值。
-q 不顯示任何傳送封包的信息,只顯示最后的結果。
-r 忽略普通的Routing Table,直接將數(shù)據(jù)包送到遠端主機上。通常是查看本機的網(wǎng)絡接口是否有問題。
-R 記錄路由過程。
-v 詳細顯示指令的執(zhí)行過程。
<p>-c 數(shù)目:在發(fā)送指定數(shù)目的包后停止。
-i 秒數(shù):設定間隔幾秒送一個網(wǎng)絡封包給一臺機器,預設值是一秒送一次。
-I 網(wǎng)絡界面:使用指定的網(wǎng)絡界面送出數(shù)據(jù)包。
-l 前置載入:設置在送出要求信息之前,先行發(fā)出的數(shù)據(jù)包。
-p 范本樣式:設置填滿數(shù)據(jù)包的范本樣式。
-s 字節(jié)數(shù):指定發(fā)送的數(shù)據(jù)字節(jié)數(shù),預設值是56,加上8字節(jié)的ICMP頭,一共是64ICMP數(shù)據(jù)字節(jié)。
-t 存活數(shù)值:設置存活數(shù)值TTL的大小。
二、Linux中的ping命令的詳解實例
實例1:ping的通的情況
命令:
ping 192.168.120.205
輸出:
Java代碼
[root@localhost ~]# ping 192.168.120.205
PING 192.168.120.205 (192.168.120.205) 56(84) bytes of data.
64 bytes from 192.168.120.205: icmp_seq=1 ttl=64 time=0.720 ms
64 bytes from 192.168.120.205: icmp_seq=2 ttl=64 time=0.181 ms
64 bytes from 192.168.120.205: icmp_seq=3 ttl=64 time=0.191 ms
64 bytes from 192.168.120.205: icmp_seq=4 ttl=64 time=0.188 ms
64 bytes from 192.168.120.205: icmp_seq=5 ttl=64 time=0.189 ms
--- 192.168.120.205 ping statistics ---
5 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
輸出:
Java代碼
[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 ---
8 packets transmitted, 0 received, +6 errors, 100% packet loss, time 7005ms
, pipe 4
[root@localhost ~]#
說明:
實例3:ping網(wǎng)關
命令:
ping -b 192.168.120.1
輸出:
Java代碼
[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.
64 bytes from 192.168.120.1: icmp_seq=1 ttl=255 time=2.02 ms
64 bytes from 192.168.120.1: icmp_seq=2 ttl=255 time=1.83 ms
64 bytes from 192.168.120.1: icmp_seq=3 ttl=255 time=1.68 ms
64 bytes from 192.168.120.1: icmp_seq=4 ttl=255 time=1.98 ms
64 bytes from 192.168.120.1: icmp_seq=5 ttl=255 time=1.88 ms
--- 192.168.120.1 ping statistics ---
5 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指定次數(shù)
命令:
ping -c 10 192.168.120.206
輸出:
Java代碼
[root@localhost ~]# ping -c 10 192.168.120.206
PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.
64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.25 ms
64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.260 ms
64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.242 ms
64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.271 ms
64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.274 ms
64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.295 ms
64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.269 ms
64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.270 ms
64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.253 ms
64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.289 ms
--- 192.168.120.206 ping statistics ---
10 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:時間間隔和次數(shù)限制的ping
命令:
ping -c 10 -i 0.5 192.168.120.206
輸出:
Java代碼
[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.
64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.24 ms
64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.235 ms
64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.244 ms
64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.300 ms
64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.255 ms
64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.264 ms
64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.263 ms
64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.331 ms
64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.247 ms
64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.244 ms
--- 192.168.120.206 ping statistics ---
10 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.
64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=0.244 ms
64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.195 ms
64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.219 ms
64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.204 ms
64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=3.56 ms
64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=1.93 ms
64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.193 ms
64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.193 ms
64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.202 ms
64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.211 ms
--- 192.168.120.206 ping statistics ---
10 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 ~]#
三、Linux中的ping命令知識擴展
怎樣使用Ping這命令來測試網(wǎng)絡連通呢?
•連通問題是由許多原因引起的,如本地配置錯誤、遠程主機協(xié)議失效等,當然還包括設備等造成的故障。首先我們講一下使用Ping命令的步驟。
•使用Ping檢查連通性有六個步驟:
•1.使用ifconfig觀察本地網(wǎng)絡設置是否正確;
•2.Ping127.0.0.1,127.0.0.1回送地址Ping回送地址是為了檢查本地的TCP/IP協(xié)議有沒有設置好;
•3.Ping本機IP地址,這樣是為了檢查本機的IP地址是否設置有誤;
•4.Ping本網(wǎng)網(wǎng)關或本網(wǎng)IP地址,這樣的是為了檢查硬件設備是否有問題,也可以檢查本機與本地網(wǎng)絡連接是否正常;(在非局域網(wǎng)中這一步驟可以忽略)
•5.Ping本地DNS地址,這樣做是為了檢查DNS是否能夠將IP正確解析。
•6.Ping遠程IP地址,這主要是檢查本網(wǎng)或本機與外部的連接是否正常。