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

ping [参数] [主机名或IP地址]

2.命令功能:

ping命令用于:确定网络和各外部主机的状态;跟踪和隔离硬件和软件问题;测试、评估和管理网络。如果主机正在运行并连在网上,它就对回送信号进行响应。每个回送信号请求包含一个网际协议(IP)和 ICMP 头,后面紧跟一个 tim 结构,以及来填写这个信息包的足够的字节。缺省情况是连续发送回送信号请求直到接收到中断信号(Ctrl-C)。

ping 命令每秒发送一个数据报并且为每个接收到的响应打印一行输出。ping 命令计算信号往返时间和(信息)包丢失情况的统计信息,并且在完成之后显示一个简要总结。ping 命令在程序超时或当接收到 SIGINT 信号时结束。Host 参数或者是一个有效的主机名或者是因特网地址。

3.命令参数:

-d 使用Socket的SO_DEBUG功能。

-f  极限检测。大量且快速地送网络封包给一台机器,看它的回应。

-n 只输出数值。

-q 不显示任何传送封包的信息,只显示最后的结果。

-r 忽略普通的Routing Table,直接将数据包送到远端主机上。通常是查看本机的网络接口是否有问题。

-R 记录路由过程。

-v 详细显示指令的执行过程。

<p>-c 数目:在发送指定数目的包后停止。

-i 秒数:设定间隔几秒送一个网络封包给一台机器,预设值是一秒送一次。

-I 网络界面:使用指定的网络界面送出数据包。

-l 前置载入:设置在送出要求信息之前,先行发出的数据包。

-p 范本样式:设置填满数据包的范本样式。

-s 字节数:指定发送的数据字节数,预设值是56,加上8字节的ICMP头,一共是64ICMP数据字节。

-t 存活数值:设置存活数值TTL的大小。

4.使用实例:

实例1:ping的通的情况

命令:

ping 192.168.120.205

输出:

  1.  
  2. [root@localhost ~]# ping 192.168.120.205
  3. PING 192.168.120.205 (192.168.120.205) 56(84) bytes of data.
  4. 64 bytes from 192.168.120.205: icmp_seq=1 ttl=64 time=0.720 ms
  5. 64 bytes from 192.168.120.205: icmp_seq=2 ttl=64 time=0.181 ms
  6. 64 bytes from 192.168.120.205: icmp_seq=3 ttl=64 time=0.191 ms
  7. 64 bytes from 192.168.120.205: icmp_seq=4 ttl=64 time=0.188 ms
  8. 64 bytes from 192.168.120.205: icmp_seq=5 ttl=64 time=0.189 ms
  9.  
  10. --- 192.168.120.205 ping statistics ---
  11. 5 packets transmitted, 5 received, 0% packet loss, time 4000ms
  12. rtt min/avg/max/mdev = 0.181/0.293/0.720/0.214 ms
  13. [root@localhost ~]# 

说明:

实例2:ping不通的情况

命令:

ping 192.168.120.202

输出:

  1.  
  2. [root@localhost ~]# ping 192.168.120.202
  3. PING 192.168.120.202 (192.168.120.202) 56(84) bytes of data.
  4. From 192.168.120.204 icmp_seq=1 Destination Host Unreachable
  5. From 192.168.120.204 icmp_seq=2 Destination Host Unreachable
  6. From 192.168.120.204 icmp_seq=3 Destination Host Unreachable
  7. From 192.168.120.204 icmp_seq=4 Destination Host Unreachable
  8. From 192.168.120.204 icmp_seq=5 Destination Host Unreachable
  9. From 192.168.120.204 icmp_seq=6 Destination Host Unreachable
  10.  
  11. --- 192.168.120.202 ping statistics ---
  12. 8 packets transmitted, 0 received, +6 errors, 100% packet loss, time 7005ms
  13. , pipe 4
  14. [root@localhost ~]#

说明:

实例3:ping网关

命令:

ping -b 192.168.120.1

输出:

  1.  
  2. [root@localhost ~]# route
  3. Kernel IP routing table
  4. Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
  5. 192.168.120.0   *               255.255.255.0   U     0      0        0 eth0
  6. 192.168.0.0     192.168.120.1   255.255.0.0     UG    0      0        0 eth0
  7. 10.0.0.0        192.168.120.1   255.0.0.0       UG    0      0        0 eth0
  8. default         192.168.120.240 0.0.0.0         UG    0      0        0 eth0
  9. [root@localhost ~]# ping -192.168.120.1
  10. PING 192.168.120.1 (192.168.120.1) 56(84) bytes of data.
  11. 64 bytes from 192.168.120.1: icmp_seq=1 ttl=255 time=2.02 ms
  12. 64 bytes from 192.168.120.1: icmp_seq=2 ttl=255 time=1.83 ms
  13. 64 bytes from 192.168.120.1: icmp_seq=3 ttl=255 time=1.68 ms
  14. 64 bytes from 192.168.120.1: icmp_seq=4 ttl=255 time=1.98 ms
  15. 64 bytes from 192.168.120.1: icmp_seq=5 ttl=255 time=1.88 ms
  16.  
  17. --- 192.168.120.1 ping statistics ---
  18. 5 packets transmitted, 5 received, 0% packet loss, time 4000ms
  19. rtt min/avg/max/mdev = 1.682/1.880/2.020/0.129 ms

说明:

实例4:ping指定次数

命令:

ping -c 10 192.168.120.206

输出:

  1.  
  2. [root@localhost ~]# ping -10 192.168.120.206
  3. PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.
  4. 64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.25 ms
  5. 64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.260 ms
  6. 64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.242 ms
  7. 64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.271 ms
  8. 64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.274 ms
  9. 64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.295 ms
  10. 64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.269 ms
  11. 64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.270 ms
  12. 64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.253 ms
  13. 64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.289 ms
  14.  
  15. --- 192.168.120.206 ping statistics ---
  16. 10 packets transmitted, 10 received, 0% packet loss, time 9000ms
  17. rtt min/avg/max/mdev = 0.242/0.367/1.251/0.295 ms
  18. [root@localhost ~]# 

说明:

实例5:时间间隔和次数限制的ping

命令:

ping -c 10 -i 0.5 192.168.120.206

输出:

  1.  
  2. [root@localhost ~]# ping -10 -0.5 192.168.120.206
  3. PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.
  4. 64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.24 ms
  5. 64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.235 ms
  6. 64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.244 ms
  7. 64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.300 ms
  8. 64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.255 ms
  9. 64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.264 ms
  10. 64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.263 ms
  11. 64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.331 ms
  12. 64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.247 ms
  13. 64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.244 ms
  14.  
  15. --- 192.168.120.206 ping statistics ---
  16. 10 packets transmitted, 10 received, 0% packet loss, time 4499ms
  17. rtt min/avg/max/mdev = 0.235/0.362/1.241/0.294 ms
  18. [root@localhost ~]# ping -10 -0.01 192.168.120.206
  19. PING 192.168.120.206 (192.168.120.206) 56(84) bytes of data.
  20. 64 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=0.244 ms
  21. 64 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.195 ms
  22. 64 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.219 ms
  23. 64 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.204 ms
  24. 64 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=3.56 ms
  25. 64 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=1.93 ms
  26. 64 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.193 ms
  27. 64 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.193 ms
  28. 64 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.202 ms
  29. 64 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.211 ms
  30.  
  31. --- 192.168.120.206 ping statistics ---
  32. 10 packets transmitted, 10 received, 0% packet loss, time 90ms
  33. rtt min/avg/max/mdev = 0.193/0.716/3.564/1.080 ms
  34. [root@localhost ~]# 

说明:

实例6:通过域名ping公网上的站点

命令:

ping -c 5 www.58.com

输出:

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

说明:

实例7:多参数使用

命令:

ping -i 3 -s 1024 -t 255 192.168.120.206

输出:

  1.  
  2. [root@localhost ~]# ping -3 -1024 -255 192.168.120.206
  3. PING 192.168.120.206 (192.168.120.206) 1024(1052) bytes of data.
  4. 1032 bytes from 192.168.120.206: icmp_seq=1 ttl=64 time=1.99 ms
  5. 1032 bytes from 192.168.120.206: icmp_seq=2 ttl=64 time=0.694 ms
  6. 1032 bytes from 192.168.120.206: icmp_seq=3 ttl=64 time=0.300 ms
  7. 1032 bytes from 192.168.120.206: icmp_seq=4 ttl=64 time=0.481 ms
  8. 1032 bytes from 192.168.120.206: icmp_seq=5 ttl=64 time=0.415 ms
  9. 1032 bytes from 192.168.120.206: icmp_seq=6 ttl=64 time=0.600 ms
  10. 1032 bytes from 192.168.120.206: icmp_seq=7 ttl=64 time=0.411 ms
  11. 1032 bytes from 192.168.120.206: icmp_seq=8 ttl=64 time=0.281 ms
  12. 1032 bytes from 192.168.120.206: icmp_seq=9 ttl=64 time=0.318 ms
  13. 1032 bytes from 192.168.120.206: icmp_seq=10 ttl=64 time=0.362 ms
  14. 1032 bytes from 192.168.120.206: icmp_seq=11 ttl=64 time=0.408 ms
  15. 1032 bytes from 192.168.120.206: icmp_seq=12 ttl=64 time=0.445 ms
  16. 1032 bytes from 192.168.120.206: icmp_seq=13 ttl=64 time=0.397 ms
  17. 1032 bytes from 192.168.120.206: icmp_seq=14 ttl=64 time=0.406 ms
  18. 1032 bytes from 192.168.120.206: icmp_seq=15 ttl=64 time=0.458 ms
  19.  
  20. --- 192.168.120.206 ping statistics ---
  21. 15 packets transmitted, 15 received, 0% packet loss, time 41999ms
  22. rtt min/avg/max/mdev = 0.281/0.531/1.993/0.404 ms
  23. [root@localhost ~]# 

说明:

-i 3 发送周期为 3秒 -s 设置发送包的大小为1024 -t 设置TTL值为 255

linux ping命令的更多相关文章

  1. Linux ping 命令

    ping命令用来测试与目标主机的连通性,常见用法如下: [root@localhost ~]$ ping www.baidu.com # 对目标主机域名进行连通性测试 [root@localhost ...

  2. linux ping 命令解析

    不管在windows平台,还是在linux平台,ping都是非常常用的网络命令:ping命令通过ICMP(Internet控制消息协议)工作:ping可以用来测试本机与目标主机是否联通.联通速度如何. ...

  3. Linux ping命令详解

    Linux系统的ping命令是常用的网络命令,它通常用来测试与目标主机的连通性 基于IMCP协议 常见命令参数 -q 不显示任何传送封包的信息,只显示最后的结果 -n 只输出数值 -R 记录路由过程 ...

  4. linux ping命令实践

          ping 解析       Linux系统的ping命令是常用的网络命令,它通常用来检测与目标主机的连通性,经常说"ping以下机器,看是否开着,不能打开网页时候,可以ping ...

  5. windows 环境和linux环境下 ping命令的区别:

    Ping 是Windows自带的一个DOS命令.利用它可以检查网络是否能够连通,用好它可以很好地帮助我们分析判定网络故障.该命令可以加许多参数使用,键入Ping按回车即可看到详细说明.Ping 命令可 ...

  6. 每天一个linux命令(54):ping命令

    Linux系统的ping命令是常用的网络命令,它通常用来测试与目标主机的连通性,我们经常会说“ping一下某机器,看是不是开着”.不能打开网页时会说“你先ping网关地址192.168.1.1试试”. ...

  7. Linux和Windows下ping命令详解(转:http://linux.chinaitlab.com/command/829332.html)

    一.Linux下的ping参数 用途 发送一个回送信号请求给网络主机. 语法 ping [ -d] [ -D ] [ -n ] [ -q ] [ -r] [ -v] [ \ -R ] [ -a add ...

  8. 每天一个linux命令(46):ping命令

    Linux系统的ping 命令是常用的网络命令,它通常用来测试与目标主机的连通性,我们经常会说“ping一下某机器,看是不是开着”.不能打开网页时会说“你先ping网关地 址192.168.1.1试试 ...

  9. Linux中ping命令

    Linux系统的ping命令是常用的网络命令,它通常用来测试与目标主机的连通性,我们经常会说“ping一下某机器,看是不是开着”.不能打开网页时会说“你先ping网关地址192.168.1.1试试”. ...

随机推荐

  1. 富文本编辑器--FCKEditor 上传图片

    FCKEditor的最新版本已经更改名称为CKEditor: 1.在页面引入fckeditor目录下的fckeditor.js <script type="text/javascrip ...

  2. 在iOS中将string转成UTF-8编码

    在iOS开发中,特别是在对Web服务调用的时候,经常会遇到请求参数为中文的情况,那么这时候就需要将Url转成UTF-8编码才能进行请求.使用stringByAddingPercentEscapesUs ...

  3. export export defalut

    require/exports 和 import/export 形式不一样 require/exports 的用法只有以下三种简单的写法: const fs = require('fs') expor ...

  4. redis的五种存储类型的具体用法

    String 类型操作 string是redis最基本的类型,而且string类型是二进制安全的.意思是redis的string可以包含任何数据.比如jpg图片或者序列化的对象 $redis-> ...

  5. HDU 3407.Zjnu Stadium 加权并查集

    Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  6. wmi uuid

    [转]https://www.cnblogs.com/-sylar/p/8376621.html 1. 开始-运行-输入:wbemtest 回车2. 单击"连接", 输入:root ...

  7. Java界面编程—API

    Java 的 GUI 提供的对象都存在 java.awt 和 java.swing 两个包中. awt :Abstract Window ToolKit(抽象窗口工具包),需要调用本地系统方法实现功能 ...

  8. 知名APP(支付宝、微信、花瓣等)首页设计技巧及原型实例讲解

    APP首页设计对APP自身来说是至关重要的,一款优秀的APP产品,其首页设计不仅需要清晰的展示产品核心功能,给用户创造良好的用户体验,而且还需要展示公司的品牌形象,提升在用户心中的品牌认知度.今天,就 ...

  9. Django web project

    在virtualenv下 (myvenv) ~/djangogirls$ django-admin startproject mysite . 生成web 工程目录 djangogirls ├───m ...

  10. springboot配置il8n

    springMvc下,配置il8n: 1.配置ResourceBundleMessageSource管理国际化资源文件 2.在页面使用fmt标签取出国际化内容 springBoot下,自动配置了il8 ...