• 关于ping的一些知识


    Ping的介绍

    Ping(Packet Internet Groper)是Windows、Unix和Linux系统下的一个命令。

    ping也属于一个通信协议,是TCP/IP协议的一部分。

    ping的运作原理是向目标主机传出一个ICMP(Internet Control Messages Protocol)即因特网信报控制协议的请求回显数据包,并等待接收回显回应数据包。程序会按时间和成功响应的次数估算丢失数据包率(丢包率)和数据包往返时间(网络时延,Round-trip delay time)。
    

    Ping的格式

    应用格式:ping IP地址 
    如:ping 192.168.100.1
    
    Ping命令亦可以根据网页解析其IP地址
    如:ping www.baidu.com
    

    该命令还可以加许多参数使用,具体是键入ping按回车即可看到详细说明。

    Ping的回显含义:

    ping 192.168.100.43
    PING 192.168.100.43 (192.168.100.43): 56 data bytes
    64 bytes from 192.168.100.43: icmp_seq=0 ttl=255 time=3.744 ms
    --- 192.168.100.20 ping statistics ---
    2 packets transmitted, 2 packets received, 0.0% packet loss
    round-trip min/avg/max/stddev = 0.064/0.091/0.118/0.027 ms
    
    ping www.baidu.com
    PING www.a.shifen.com (61.135.169.121): 56 data bytes
    64 bytes from 61.135.169.121: icmp_seq=0 ttl=55 time=12.199 ms
    64 bytes from 61.135.169.121: icmp_seq=1 ttl=55 time=10.127 ms
    --- www.a.shifen.com ping statistics ---
    2 packets transmitted, 2 packets received, 0.0% packet loss
    round-trip min/avg/max/stddev = 12.199/15.465/18.731/3.266 ms
    
    # ping www.baidu.com
    # ping www.a.shifen.com是www.baidu.com的DNS别名 IP地址是61.135.169.121 以56 bytes大小测试
    # 以64 bytes大小返回来自61.135.169.121的数据  icmp_seq为icmp序列(第几个数据包)  ttl(Time to Live) Time(返回数据包最短时间)
    # 某地址的ping的统计数
    # 2 数据包传输,2 收到的信息包,0%数据包丢失
    # PING的来回的最小/平均/最大/偏离平均值的时间
    
    stddev:表示这些ICMP包的RTT偏离平均值的程度,用来衡量网速的稳定性,这个值越大说明你的网速越不稳定。
    注:不同的操作系统,可能名称不同,比如mac下叫做stddev,Linux中为mdev,windows下没这行统计数据。
    

    其他知识

    1. linux中ping命令不会像windows一样自动结束,不手动结束会一直进行下去 ping -c 3 www.baidu.com 表示ping 进行三次后结束;

      ping -c 3 www.baidu.com
      PING www.a.shifen.com (61.135.169.125): 56 data bytes
      64 bytes from 61.135.169.125: icmp_seq=0 ttl=55 time=15.238 ms
      64 bytes from 61.135.169.125: icmp_seq=1 ttl=55 time=13.449 ms
      64 bytes from 61.135.169.125: icmp_seq=2 ttl=55 time=18.579 ms
      
      --- www.a.shifen.com ping statistics ---
      3 packets transmitted, 3 packets received, 0.0% packet loss
      round-trip min/avg/max/stddev = 13.449/15.755/18.579/2.126 ms
      
    2. 只看结果不看过程:ping -q -c 2 www.baidu.com ;

      ping -q -c 2 www.baidu.com
      PING www.a.shifen.com (61.135.169.125): 56 data bytes
      
      --- www.a.shifen.com ping statistics ---
      2 packets transmitted, 2 packets received, 0.0% packet loss
      round-trip min/avg/max/stddev = 11.954/15.258/18.562/3.304 ms
      
    3. 指定ping数据包的大小 :默认情况下,ping命令是以64字节大小的数据包来测试网络联通性的,如需要改变默认数据包的大小,则可以使用参数-s选项。例如使用65500字节的数据包来测试网络:

      ping -s 65500 -c 3 www.baidu.com
      PING www.a.shifen.com (61.135.169.125) 65500(65528) bytes of data.
      
      --- www.a.shifen.com ping statistics ---
      3 packets transmitted, 0 received, 100% packet loss, time 2029ms
      

      -s 选项通常用来发现网络中的MTU相关问题,MTU: Maxitum Transmission Unit 最大传输单元。

    4. 指定ping 的TTL :

      TTL(生存时间)是网络发送的数据包中包含的计时器值,它告诉接收者在丢弃和过期数据(数据包)之前要保留或使用该数据包多长时间。对于不同的操作系统,TTL值是不同的。因此,您可以根据TTL值确定操作系统。

      指定的选项是 -t

      不指定ping命令会采用默认值,不同操作系统的默认值是不同的:
      windows 通常为 128                    
      Linux 通常是 64或255                       
      Unix  通常是 255
      
      TTL值介乎于110-128之间的,基本我们可以判断为是Windows系列的操作系统
      TTL值介乎于50-64之间的,基本我们可以判断为是Linux/CentOS/FreeBSD等操作系统。
      Linux系统的TTL值计算方法是 (64-所过路由数量)=最终TTL
      Windows系统的TTL值计算方法是 (128-所过路由数量)=最终TTL
      
    5. 指定ping的时间间隔 :

      ping命令的核心功能就是查看网络的联通性和网络的延迟。默认发送两个包的间隔为1s。使用-i选项可以更改两个包之间的时间间隔。注意只有root可以设置低于0.2s。

    根据不同的回显判断连通性

    1. 如果本地连接是通的,目的主机在线上并且可达,你将会输出每个ICMP(Internet Control Message Protocol)回显请求来显示每个ICMP回显应答。

      ping 192.168.100.223
      PING 192.168.100.223 (192.168.100.223): 56 data bytes
      64 bytes from 192.168.100.223: icmp_seq=0 ttl=128 time=0.473 ms
      64 bytes from 192.168.100.223: icmp_seq=1 ttl=128 time=0.572 ms
      ^C
      --- 192.168.100.223 ping statistics ---
      2 packets transmitted, 2 packets received, 0.0% packet loss
      round-trip min/avg/max/stddev = 0.473/0.522/0.572/0.049 ms
      
    2. 如果本地连接是通的,但是对方的防火墙拒绝了你的ICMP回显请求,那么你讲收到ICMP请求超时的消息。如果目的主机确实响应你的ARP请求,那就意味着你的本地连接是好的同时网络状态是好的。那么就应该尝试关闭目的主机的防火墙,并再次发送PING请求,或者尝试PING一个其他的主机。

      ping 192.168.100.223
      PING 192.168.100.223 (192.168.100.223): 56 data bytes
      Request timeout for icmp_seq 0
      Request timeout for icmp_seq 1
      Request timeout for icmp_seq 2
      ^C
      --- 192.168.100.223 ping statistics ---
      4 packets transmitted, 0 packets received, 100.0% packet loss
      
    3. 如果目的主机没有响应ARP请求,或者目的主机不在线,你将会接收到“Host is down”这样的消息。这样你就需要尝试ping其他主机,如果还是收到Host is down”这样的消息,那么就说明你的IP地址是配置错误的或者你的上行链路是好的,但是局域网中的其他部分是有问题的。造成这个问题的可能的原因是 上行链路的管理不当VLAN不匹配电缆上游存在损坏。

      ping 192.168.100.223
      PING 192.168.100.223 (192.168.100.223): 56 data bytes
      ping: sendto: No route to host
      ping: sendto: Host is down
      ping: sendto: Host is down
      
    4. 如果你的本地连接是有问题的,那么你将会收到”No route to host“这样的消息,这种状态下你就需要确认你的适配器已启用,或者重新把茶以太电缆(网线),或者重启你的无线连接。

      ping 192.168.100.223
      PING 192.168.100.223 (192.168.100.223): 56 data bytes
      ping: sendto: No route to host
      ping: sendto: No route to host
      

    不同操作系统的默认TTL(生存时间)值

    PING subinsb.com (108.162.199.61) 56(84) bytes of data.
    64 bytes from 108.162.199.61: icmp_seq=1 ttl=57 time=503 ms
    64 bytes from 108.162.199.61: icmp_seq=2 ttl=57 time=416 ms
    

    从输出中可以看到,您获得了 TTL值。由于此网站托管在Red Hat系统上,因此返回57,接近64(Linux系统的TTL默认值)。因此,由此我们可以了解远程系统的操作系统。以下是 不同设备/操作系统的默认TTL值:

    Device / OS Version Protocol TTL
    AIX TCP 60
    AIX UDP 30
    AIX 3.2, 4.1 ICMP 255
    BSDI BSD/OS 3.1 and 4.0 ICMP 255
    Compa Tru64 v5.0 ICMP 64
    Cisco ICMP 254
    DEC Pathworks V5 TCP and UDP 30
    Foundry ICMP 64
    FreeBSD 2.1R TCP and UDP 64
    FreeBSD 3.4, 4.0 ICMP 255
    FreeBSD 5 ICMP 64
    HP-UX 9.0x TCP and UDP 30
    HP-UX 10.01 TCP and UDP 64
    HP-UX 10.2 ICMP 255
    HP-UX 11 ICMP 255
    HP-UX 11 TCP 64
    Irix 5.3 TCP and UDP 60
    Irix 6.x TCP and UDP 60
    Irix 6.5.3, 6.5.8 ICMP 255
    juniper ICMP 64
    MPE/IX (HP) ICMP 200
    Linux 2.0.x kernel ICMP 64
    Linux 2.2.14 kernel ICMP 255
    Linux 2.4 kernel ICMP 255
    Linux Red Hat 9 ICMP and TCP 64
    MacOS/MacTCP 2.0.x TCP and UDP 60
    MacOS/MacTCP X (10.5.6) ICMP/TCP/UDP 64
    NetBSD ICMP 255
    Netgear FVG318 ICMP and UDP 64
    OpenBSD 2.6 & 2.7 ICMP 255
    OpenVMS 07.01.2002 ICMP 255
    OS/2 TCP/IP 3.0 64
    OSF/1 V3.2A TCP 60
    OSF/1 V3.2A UDP 30
    Solaris 2.5.1, 2.6, 2.7, 2.8 ICMP 255
    Solaris 2.8 TCP 64
    Stratus TCP_OS ICMP 255
    Stratus TCP_OS (14.2-) TCP and UDP 30
    Stratus TCP_OS (14.3+) TCP and UDP 64
    Stratus STCP ICMP/TCP/UDP 60
    SunOS 4.1.3/4.1.4 TCP and UDP 60
    SunOS 5.7 ICMP and TCP 255
    Ultrix V4.1/V4.2A TCP 60
    Ultrix V4.1/V4.2A UDP 30
    Ultrix V4.2 – 4.5 ICMP 255
    VMS/Multinet TCP and UDP 64
    VMS/TCPware TCP 60
    VMS/TCPware UDP 64
    VMS/Wollongong 1.1.1.1 TCP 128
    VMS/Wollongong 1.1.1.1 UDP 30
    VMS/UCX TCP and UDP 128
    Windows for Workgroups TCP and UDP 32
    Windows 95 TCP and UDP 32
    Windows 98 ICMP 32
    Windows 98, 98 SE ICMP 128
    Windows 98 TCP 128
    Windows NT 3.51 TCP and UDP 32
    Windows NT 4.0 TCP and UDP 128
    Windows NT 4.0 SP5- 32
    Windows NT 4.0 SP6+ 128
    Windows NT 4 WRKS SP 3, SP 6a ICMP 128
    Windows NT 4 Server SP4 ICMP 128
    Windows ME ICMP 128
    Windows 2000 pro ICMP/TCP/UDP 128
    Windows 2000 family ICMP 128
    Windows Server 2003 128
    Windows XP ICMP/TCP/UDP 128
    Windows Vista ICMP/TCP/UDP 128
    Windows 7 ICMP/TCP/UDP 128
    Windows Server 2008 ICMP/TCP/UDP 128
    Windows 10 ICMP/TCP/UDP 128

    I will update this table in the future when there’s a release of new important OS whenever I get the time. You can get the short version of default TTL values by this table :

    Device / OS TTL
    *nix (Linux/Unix) 64
    Windows 128
    Solaris/AIX 254

    这个文章原因,就是发现对ping不是很了解,想理解透彻方便并且自己日后查看,因此查阅资料,整合成的文章。

    Referer:

    ping 的零碎知识

    使用常见的网络命令查看当前网络状态——Mac OS X篇

    [不同操作系统的默认TTL(生存时间)值](

  • 相关阅读:
    FireFox/Chrome不支持在前台js读后台Attributes.Add("DefaultValue")的属性
    IIS Web怪问题: Access is denied due to invalid credentials.
    转:OWC学习笔记电子表格(Spreadsheet)风格属性设置
    最全的CSS浏览器兼容问题整理(IE6.0、IE7.0 与 FireFox)
    转:[网站安全]避免在站点中通过URL参数做重定向
    [SQL Server 2005 BI]在.NET中创建SQL 2005 KPI
    即使asp:TreeView有几万个节点,也让IE不死的解决方法
    Visual Totals in MDX and Role Security
    css hack
    让Updatepanel中的控件触发整个页面Postback
  • 原文地址:https://www.cnblogs.com/rab3it/p/12657074.html
Copyright © 2020-2023  润新知