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.命令格式:

Shell

1

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

2.命令功能:

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

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

3.命令參數:

Shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

d 使用SocketSO_DEBUG功能。
 
f  極限檢測。大量且快速地送網絡封包給一臺機器,看它的回應。
 
n 只輸出數值。
 
q 不顯示任何傳送封包的信息,只顯示最后的結果。
 
r 忽略普通的Routing Table,直接將數據包送到遠端主機上。通常是查看本機的網絡接口是否有問題。
 
R 記錄路由過程。
 
v 詳細顯示指令的執行過程。
 
<p>c 數目:在發送指定數目的包后停止。
 
i 秒數:設定間隔幾秒送一個網絡封包給一臺機器,預設值是一秒送一次。
 
I 網絡界面:使用指定的網絡界面送出數據包。
 
l 前置載入:設置在送出要求信息之前,先行發出的數據包。
 
p 范本樣式:設置填滿數據包的范本樣式。
 
s 字節數:指定發送的數據字節數,預設值是56,加上8字節的ICMP頭,一共是64ICMP數據字節。

4.使用實例:

實例1:ping的通的情況

命令:

Shell

1

ping 192.168.120.205

輸出:

Shell

1
2
3
4
5
6
7
8
9
10
11
12

[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不通的情況

命令:

Shell

1

ping 192.168.120.202

輸出:

Shell

1
2
3
4
5
6
7
8
9
10
11
12
13

[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網關

命令:

Shell

1

ping b 192.168.120.1

輸出:

Shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

[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指定次數

命令:

Shell

1

ping c 10 192.168.120.206

輸出:

Shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

[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:時間間隔和次數限制的ping

命令:

Shell

1

ping c 10 i 0.5 192.168.120.206

輸出:

Shell

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

[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 ~]#

說明:

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

命令:

Shell

1

ping c 5 www.58.com

輸出:

Shell

1
2
3
4
5
6
7
8
9
10
11
12

peidaVirtualBox ~ # ping -c 5 www.58.com
PING www.58.com (211.151.111.30) 56(84) bytes of data.
64 bytes from 211.151.111.30: icmp_req=1 ttl=49 time=14.7 ms
64 bytes from 211.151.111.30: icmp_req=2 ttl=49 time=16.4 ms
64 bytes from 211.151.111.30: icmp_req=3 ttl=49 time=15.2 ms
64 bytes from 211.151.111.30: icmp_req=4 ttl=49 time=14.6 ms
64 bytes from 211.151.111.30: icmp_req=5 ttl=49 time=19.9 ms
 
 www.58.com ping statistics 
5 packets transmitted, 5 received, 0% packet loss, time 20101ms
rtt min/avg/max/mdev = 14.618/16.192/19.917/1.965 ms
peidaVirtualBox ~ #

原創文章,作者:371987341,如若轉載,請注明出處:http://www.www58058.com/83436

(0)
371987341371987341
上一篇 2017-07-30 21:06
下一篇 2017-07-30 21:38

相關推薦

  • 網絡管理的相關命令

    今天要說的是有關網絡的一些相關內容,主要介紹的有以下幾點:網絡的服務:Centos6/7中的常用命令,如何手動配置網絡,路由表的相關內容,關于Bond(僅主機模式)網絡接口的配置以及Bridge(橋接)的網絡接口配置。 首先要說的是網絡的服務: 1,Centos6/7的常用網絡的命令: Centos6:禁用網卡:ifconfig 網卡名 down啟用網卡:i…

    2017-09-07
  • Linux命令總結

      1、登陸和開關機 ? ? ? 關機    halt    poweroff    init 0    重啟    reboot    init 6    shutdown    shutdown -r 重啟    shutodwn -h 關機    shutdown -c 取消計劃關機    shutdown +0 馬上關機    +1 一分鐘后關機  …

    2017-09-11
  • 馬哥教育網絡班22期第一周課程練習1-3天

    1.描述計算機組成及其功能 CPU:  運算器  控制器  寄存器  緩存 存儲器:  RAM(隨機訪問存儲器)  I/O設備:               i:下指令,提供數據 如:鍵鼠     &…

    Linux干貨 2016-08-15
  • HAproxy reload config file with uninterrupt session

    HAProxy is a high performance load balancer. It is very light-weight, and free, making it a great option if you are in the market for a load balancer and need to keep your cos…

    Linux干貨 2015-04-03
  • Linux命令之:setfacl和getfacl

    命令總結之:setfacl和getfacl acl:access control list,實現靈活的權限管理 除了文件的所有者,所屬組合其他人,可以對更多的用戶設置權限 acl生效順序:所有者、自定義用戶、自定義組、其他人 1、首先我們查看man幫助文檔說明 [root@centos7 sixijie]# man setfac…

    Linux干貨 2016-08-04
  • 實現NFS為lamp環境web站點提供共享存儲

    1.實驗需求 (1)nfs server導出/data/application/web,在目錄中提供wordpress; (2)nfs client掛載nfs server導出的文件系統,至/var/www/html; (3)客戶端1(lamp)部署wordpress,并讓其正常訪問,要確保正常發文章,上傳圖片。 (4)客戶端2(lamp),掛載nfs se…

    Linux干貨 2017-05-02
欧美性久久久久