最近遇到一个问题,同时上千台主机同时ping一台主机,导致该主机cpu使用率一直飙升的问题。觉得有必要查找下ping相关知识,记录如下:
ping命令介绍:man ping查看如下
PING(8) System Manager's Manual: iputils PING(8)
NAME
ping - send ICMP ECHO_REQUEST to network hosts
SYNOPSIS
ping [-aAbBdDfhLnOqrRUvV46] [-c count] [-F flowlabel] [-i interval] [-I interface] [-l preload] [-m mark] [-M pmtudisc_option] [-N
nodeinfo_option] [-w deadline] [-W timeout] [-p pattern] [-Q tos] [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp option] [hop
...] destination
DESCRIPTION
ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host or gateway. ECHO_REQUEST
datagrams (``pings'') have an IP and ICMP header, followed by a struct timeval and then an arbitrary number of ``pad'' bytes used to
fill out the packet.
ping works with both IPv4 and IPv6. Using only one of them explicitly can be enforced by specifying -4 or -6.
ping can also send IPv6 Node Information Queries (RFC4620). Intermediate hops may not be allowed, because IPv6 source routing was
deprecated (RFC5095).
大意如下:ping通过发送ICMP请求回显和回显特定主机报文。即
请求过程:
ping命令会首先构建一个固定格式的ICMP(Internet Control Message Protocol)请求数据包,然后通过该协议将这个数据包以及ping主机地址一起交到IP层协议,IP层协议就以这个ping主机地址作为目的地址,本机IP作为源地址,再加一些其他控制信息,构建为一个IP数据包,并在映射表中查找IP地址为ping主机所在的物理地址,一并发给数据链路层。后者构建一个数据帧,目的地址是IP层传过来的物理地址,源地址则是本机的物理地址,还要附加上一些控制信息,依据以太网的介质访问规则,将它们传送出去。
回显过程:
主机B收到这个数据帧后,先检查它的目的地址,并和本机的物理地址对比,如符合,则接收;否则丢弃。接收后检查该数据帧,将IP数据包从帧中提取出来,交给本机的IP层协议。同样,IP层检查后,将有用的信息提取后交给ICMP协议,后者处理后,马上构建一个ICMP应答包,发送给主机A,其过程和主机A发送ICMP请求包到主机B一模一样。