东安网站建设,360关键词排名推广,福州网站建设自助建站,如何刷网站访问量目录 一、简介二、ping命令三、简单示例3.1 ping -c 3 www.baidu.com3.2 ping -c 3 -i 2 www.baidu.com 一、简介
PING #xff08;Packet Internet Groper#xff09;#xff0c; 因特网包探索器#xff0c;用于测试网络连接量的程序 。Ping是工作在 TCP/IP 网络体系结构… 目录 一、简介二、ping命令三、简单示例3.1 ping -c 3 www.baidu.com3.2 ping -c 3 -i 2 www.baidu.com 一、简介
PING Packet Internet Groper 因特网包探索器用于测试网络连接量的程序 。Ping是工作在 TCP/IP 网络体系结构中应用层的一个服务命令 主要是向特定的目的主机发送 ICMPInternet Control Message Protocol 因特网报文控制协议 Echo 请求报文测试目的站是否可达及了解其有关状态 。 在网络中ping是一个十分强大的TCP/IP工具。它的作用主要为
用来检测网络的连通情况和分析网络速度根据域名得到服务器IP根据ping返回的TTL值来判断对方所使用的操作系统及数据包经过路由器数量。 二、ping命令
ping命令在不同操作系统间的操作和可选字段略有不同以下是Linux系统ping命令 ping
Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface][-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos][-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option][-w deadline] [-W timeout] [hop1 ...] destination
Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface][-l preload] [-m mark] [-M pmtudisc_option][-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize][-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline][-W timeout] destination参数说明
参数说明-aAudible ping-A自适应ping根据ping包往返时间确定ping的速度-b允许ping一个广播地址-B不允许ping改变包头的源地址-c countping指定次数后停止ping-d使用Socket的SO_DEBUG功能-F flow_label为ping回显请求分配一个20位的“flow label”如果未设置内核会为ping随机分配-f极限检测快速连续ping一台主机ping的速度达到100次每秒-i interval设定间隔几秒发送一个ping包默认一秒ping一次-I interface指定网卡接口、或指定的本机地址送出数据包-l preload设置在送出要求信息之前先行发出的数据包-L抑制组播报文回送只适用于ping的目标为一个组播地址-n不要将ip地址转换成主机名-p pattern指定填充ping数据包的十六进制内容在诊断与数据有关的网络错误时这个选项就非常有用如“-p ff”-q不显示任何传送封包的信息只显示最后的结果-Q tos设置Qos(Quality of Service)它是ICMP数据报相关位可以是十进制或十六进制数详见rfc1349和rfc2474文档-R记录ping的路由过程(IPv4 only) 注意由于IP头的限制最多只能记录9个路由其他会被忽略-r忽略正常的路由表直接将数据包送到远端主机上通常是查看本机的网络接口是否有问题如果主机不直接连接的网络上则返回一个错误。-S sndbufSet socket sndbuf. If not specified, it is selected to buffer not more than one packet-s packetsize指定每次ping发送的数据字节数默认为“56字节”“28字节”的ICMP头一共是84字节 包头内容不能大于65535所以最大值为65507linux:65507, windows:65500-t ttl设置TTL(Time To Live)为指定的值。该字段指定IP包被路由器丢弃之前允许通过的最大网段数-T timestamp_option设置IP timestamp选项,可以是下面的任何一个 - ‘tsonly’ (only timestamps) - ‘tsandaddr’ (timestamps and addresses) - ‘tsprespec host1 [host2 [host3]]’ (timestamp prespecified hops)-M hint设置MTU最大传输单元分片策略。 可设置为 - ‘do’禁止分片即使包被丢弃- ‘want’当包过大时分片- ‘dont’不设置分片标志DF flag-m mark设置mark-v使ping处于verbose方式它要ping命令除了打印ECHO-RESPONSE数据包之外还打印其它所有返回的ICMP数据包-UPrint full user-to-user latency (the old behaviour) Normally ping prints network round trip time, which can be different f.e. due to DNS failures.-W timeout以毫秒为单位设置ping的超时时间-w deadlinedeadline
我们通常会用它来直接 ping ip 或 ping 域名来测试网络的连通情况。
命令如下 ping 10.0.7.229ping www.baidu.com输出结果
# ping 10.0.7.229
PING 10.0.7.229 (10.0.7.229) 56(84) bytes of data.
64 bytes from 10.0.7.229: icmp_seq1 ttl64 time3.75 ms
64 bytes from 10.0.7.229: icmp_seq2 ttl64 time16.2 ms
64 bytes from 10.0.7.229: icmp_seq3 ttl64 time1.53 ms
64 bytes from 10.0.7.229: icmp_seq4 ttl64 time0.898 ms--- 10.0.7.229 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3019ms
rtt min/avg/max/mdev 0.898/5.608/16.248/6.233 ms# ping www.baidu.com
PING www.a.shifen.com (39.156.66.14) 56(84) bytes of data.
64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq1 ttl50 time54.7 ms
64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq2 ttl50 time8.19 ms
64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq3 ttl50 time12.7 ms
64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq4 ttl50 time14.2 ms
64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq5 ttl50 time8.48 ms--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4644ms
rtt min/avg/max/mdev 8.197/19.680/54.708/17.672 ms输出格式说明
PING 10.0.7.229 (10.0.7.229) 56(84) bytes of data.
PING www.a.shifen.com (39.156.66.14) 56(84) bytes of data.10.0.7.229目标主机的域名和IPping会自动将域名转换为IP 56(84)不带包头的包大小和带包头的包大小参考 “-s” 参数
ping 域名第一行域名显示的不是ping的域名其实 www.a.shifen.com 是 CDN 域名39.156.66.14 是CDN域名的ip。 64 bytes from 10.0.7.229: icmp_seq1 ttl64 time3.75 ms64 bytes数据包大小也就是字节 icmp_seq1ping序列从1开始如果数字不是按顺序递增也就意味着丢包了 ttl64ttl表示生存时间Time to Live表示DNS记录在DNS服务器上存在的时间它是IP协议包的一个值告诉路由器该数据包何时需要被丢弃。可以通过Ping返回的TTL值大小粗略地判断目标系统类型是Windows系列还是UNIX/Linux系列默认情况下Linux系统的TTL值为64或255Windows NT/2000/XP系统的TTL值为128Windows 98系统的TTL值为32UNIX主机的TTL值为255。 time3.75ms响应时间数值越小连通速度越快 --- 10.0.7.229 ping statistics ---表示ping统计信息的开始。 5 packets transmitted, 5 received, 0% packet loss, time 4644ms5 packets transmitted发出去的包数 5 received返回的包数 0% packet loss丢包率 time 4644ms耗费时间 rtt min/avg/max/mdev 8.197/19.680/54.708/17.672 msrtt min/avg/max/mdev表示耗时统计信息最小/平均/最大/标准差后面的数值与之一一对应。 三、简单示例
3.1 ping -c 3 www.baidu.com
说明ping 3次www.baidu.com之后退出。
输出结果
PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data.
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq1 ttl50 time11.9 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq2 ttl50 time8.41 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq3 ttl50 time8.45 ms--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev 8.411/9.594/11.913/1.641 ms3.2 ping -c 3 -i 2 www.baidu.com
说明每隔2秒ping一次ping 3次之后退出。
输出结果
PING www.a.shifen.com (39.156.66.14) 56(84) bytes of data.
64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq1 ttl50 time10.3 ms
64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq2 ttl50 time7.94 ms
64 bytes from 39.156.66.14 (39.156.66.14): icmp_seq3 ttl50 time12.5 ms--- www.a.shifen.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 4004ms
rtt min/avg/max/mdev 7.949/10.285/12.525/1.871 ms