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

输出:

[root@localhost ~]# ping 192.168.120.205
PING 192.168.120.205 (192.168.120.205) () bytes of data.
bytes from 192.168.120.205: icmp_seq= ttl= time=0.720 ms
bytes from 192.168.120.205: icmp_seq= ttl= time=0.181 ms
bytes from 192.168.120.205: icmp_seq= ttl= time=0.191 ms
bytes from 192.168.120.205: icmp_seq= ttl= time=0.188 ms
bytes from 192.168.120.205: icmp_seq= ttl= time=0.189 ms --- 192.168.120.205 ping statistics ---
packets transmitted, received, % 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

输出:

[root@localhost ~]# ping 192.168.120.202
PING 192.168.120.202 (192.168.120.202) () bytes of data.
From 192.168.120.204 icmp_seq= Destination Host Unreachable
From 192.168.120.204 icmp_seq= Destination Host Unreachable
From 192.168.120.204 icmp_seq= Destination Host Unreachable
From 192.168.120.204 icmp_seq= Destination Host Unreachable
From 192.168.120.204 icmp_seq= Destination Host Unreachable
From 192.168.120.204 icmp_seq= Destination Host Unreachable --- 192.168.120.202 ping statistics ---
packets transmitted, received, + errors, % packet loss, time 7005ms
, pipe
[root@localhost ~]#

实例3:ping网关

命令:

  ping -b 192.168.120.1

输出:

[root@localhost ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.120.0 * 255.255.255.0 U eth0
192.168.0.0 192.168.120.1 255.255.0.0 UG eth0
10.0.0.0 192.168.120.1 255.0.0.0 UG eth0
default 192.168.120.240 0.0.0.0 UG eth0
[root@localhost ~]# ping -b 192.168.120.1
PING 192.168.120.1 (192.168.120.1) () bytes of data.
bytes from 192.168.120.1: icmp_seq= ttl= time=2.02 ms
bytes from 192.168.120.1: icmp_seq= ttl= time=1.83 ms
bytes from 192.168.120.1: icmp_seq= ttl= time=1.68 ms
bytes from 192.168.120.1: icmp_seq= ttl= time=1.98 ms
bytes from 192.168.120.1: icmp_seq= ttl= time=1.88 ms --- 192.168.120.1 ping statistics ---
packets transmitted, received, % packet loss, time 4000ms
rtt min/avg/max/mdev = 1.682/1.880/2.020/0.129 ms

实例4:ping指定次数

命令:

ping -c 10 192.168.120.206

输出:

[root@localhost ~]# ping -c  192.168.120.206
PING 192.168.120.206 (192.168.120.206) () bytes of data.
bytes from 192.168.120.206: icmp_seq= ttl= time=1.25 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.260 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.242 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.271 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.274 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.295 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.269 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.270 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.253 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.289 ms --- 192.168.120.206 ping statistics ---
packets transmitted, received, % packet loss, time 9000ms
rtt min/avg/max/mdev = 0.242/0.367/1.251/0.295 ms
[root@localhost ~]#

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

命令:

ping -c 10 -i 0.5 192.168.120.206

输出:

[root@localhost ~]# ping -c  -i 0.5 192.168.120.206
PING 192.168.120.206 (192.168.120.206) () bytes of data.
bytes from 192.168.120.206: icmp_seq= ttl= time=1.24 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.235 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.244 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.300 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.255 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.264 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.263 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.331 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.247 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.244 ms --- 192.168.120.206 ping statistics ---
packets transmitted, received, % packet loss, time 4499ms
rtt min/avg/max/mdev = 0.235/0.362/1.241/0.294 ms
[root@localhost ~]# ping -c -i 0.01 192.168.120.206
PING 192.168.120.206 (192.168.120.206) () bytes of data.
bytes from 192.168.120.206: icmp_seq= ttl= time=0.244 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.195 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.219 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.204 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=3.56 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=1.93 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.193 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.193 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.202 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.211 ms --- 192.168.120.206 ping statistics ---
packets transmitted, received, % packet loss, time 90ms
rtt min/avg/max/mdev = 0.193/0.716/3.564/1.080 ms
[root@localhost ~]#

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

命令:

  ping -c 5 www.58.com

输出:

peida-VirtualBox ~ # ping -c  www..com
PING www..com (211.151.111.30) () bytes of data.
bytes from 211.151.111.30: icmp_req= ttl= time=14.7 ms
bytes from 211.151.111.30: icmp_req= ttl= time=16.4 ms
bytes from 211.151.111.30: icmp_req= ttl= time=15.2 ms
bytes from 211.151.111.30: icmp_req= ttl= time=14.6 ms
bytes from 211.151.111.30: icmp_req= ttl= time=19.9 ms --- www..com ping statistics ---
packets transmitted, received, % packet loss, time 20101ms
rtt min/avg/max/mdev = 14.618/16.192/19.917/1.965 ms
peida-VirtualBox ~ #

实例7:多参数使用

命令:

  ping -i 3 -s 1024 -t 255 192.168.120.206

输出:

[root@localhost ~]# ping -i  -s  -t  192.168.120.206
PING 192.168.120.206 (192.168.120.206) () bytes of data.
bytes from 192.168.120.206: icmp_seq= ttl= time=1.99 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.694 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.300 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.481 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.415 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.600 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.411 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.281 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.318 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.362 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.408 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.445 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.397 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.406 ms
bytes from 192.168.120.206: icmp_seq= ttl= time=0.458 ms --- 192.168.120.206 ping statistics ---
packets transmitted, received, % packet loss, time 41999ms
rtt min/avg/max/mdev = 0.281/0.531/1.993/0.404 ms
[root@localhost ~]#

说明:

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

每天一个linux命令(网络):【转载】ping命令的更多相关文章

  1. linux查看网络链接状况命令netstat

    linux查看网络链接状况命令 netstat 参数如下: -a 显示所有socket,包括正在监听的. -c 每隔1秒就重新显示一遍,直到用户中断它. -i 显示所有网络接口的信息,格式同“ifco ...

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

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

  3. Linux和Windows下ping命令详解

    转:http://linux.chinaitlab.com/command/829332.html 一.Linux下的ping参数 用途 发送一个回送信号请求给网络主机. 语法 ping [ -d] ...

  4. Linux服务架设篇--ping命令

    工作原理: 向远程机发送包含一定字节数的ICMP数据包,如果能收到对方的回复的数据包,就表明网络是相通的,而且根据两个数据包的时间差,还可以知道相互之间网络链接的速度. 注意: 有些远程主机由于某种原 ...

  5. Linux系统下如何禁止ping命令或允许ping命令的方法

    1.禁止pingecho 1 >/proc/sys/net/ipv4/icmp_echo_ignore_all 2.允许ping echo 0 >/proc/sys/net/ipv4/ic ...

  6. Linux系统关闭对ping命令做响应。

    1.测试 ping 192.168.10.5 可以正常ping通, 2,修改 /proc/sys/net/ipv4/icmp_echo_ignore_all  文件的值=1 3.在测试 已经ping不 ...

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

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

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

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

  9. LINUX网络之ifconfig命令与ping

    ifconfig命令 网络配置 ifconfig命令被用于配置和显示Linux内核中网络接口的网络参数.用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在.要想将上述的配置信息 ...

  10. 【转】每天一个linux命令(54):ping命令

    原文网址:http://www.cnblogs.com/peida/archive/2013/03/06/2945407.html Linux系统的ping命令是常用的网络命令,它通常用来测试与目标主 ...

随机推荐

  1. CSV文件读取类

    最近项目中,经常需要读取Csv文件.基本步骤是: (1)按行读取 (2)然后将一行数据按逗号,分割为字符串数组 (3)将各列字符串转换成相应类型的数据 ,如int double类型 写了一个简单的Cs ...

  2. testng多线程并行执行测试

    testng多线程并行执行测试 testng多线程并行执行测试 并行(多线程)技术在软件术语里被定义为软件.操作系统或者程序可以并行地执行另外一段程序中多个部分或者子组件的能力.TestNG允许我们以 ...

  3. EF code first:列名 'Discriminator' 无效

    使用EF code first编写类继承的时候,出现列名 'Discriminator' 无效 . 字段中没有列名 'Discriminator' 原来在代码中,定义了一个类A,类B,B继承A,但是数 ...

  4. #C++初学记录(高精度运算)(加法)

    高精度运算 不管是int还是double亦或者long long ,这些定义变量都有数据范围的一定限制,在计算位数超过十几位的数,也就是超过他们自身的数据范围时,不能采用现有类型进行计算,只能自己通过 ...

  5. iframe 跨域问题解决方案 利用window.name+iframe跨域获取数据详解

    详解 前文提到用jsonp的方式来跨域获取数据,本文为大家介绍下如何利用window.name+iframe跨域获取数据. 首先我们要简单了解下window.name和iframe的相关知识.ifra ...

  6. 能否通过六面照片构建3D模型?比如人脸,全身的多角度照片,生成3D模型。?

    https://www.zhihu.com/question/36412840 9023 ​添加评论 ​分享 ​邀请回答​举报 ​ 收起 已关注写回答   9 个回答 默认排序​ 叛逆者 计算机图形学 ...

  7. STM32之独立版USB(Host)驱动+MSC+Fatfs移植

    源:STM32之独立版USB(Host)驱动+MSC+Fatfs移植 STM32之USB驱动库详解(架构+文件+函数+使用说明+示例程序)

  8. Python笔记 #04# Methods

    源:DataCamp datacamp 的 DAILY PRACTICE  + 日常收集. Methods String Methods List Methods 缺一 Methods You can ...

  9. Spring JPA中OneToOne和OneToMany用法

    Spring工程中,创建实体对象时,可以通过JPA的@Entity标识实体与数据库表的对应关系,@Column标识数据库字段.其中还有标识两个实体间关系的注解:@OneToOne.@OneToMany ...

  10. ubuntu 18.04 64bit build tensorflow report error:C++ compilation of rule '//tensorflow/core/kernels:broadcast_to_op' failed (Exit 4)

    注意:笔者未能在Ubuntu18.04 64bit下成功从源码编译cpu版本的tensorflow Ans: 1.You are likely running out of memory. Try r ...