This is the 12th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

Introduction of the command

The ping command is a common network command in Linux. The ping command is used to test network connectivity, network performance, and host response capability.

In daily work, we often encounter the situation that web pages cannot be opened and web addresses cannot be requested. At this time, our general operation is to ping the website, such as ping Baidu.com

When using ping to test network connectivity, you need to test the local system first to check whether the network interface of the local system is enabled, then test the hosts on the local network, and then test the connectivity of other target hosts. During the test, the ping command calculates the minimum, maximum, and average round-trip time and collects statistics on lost packet data.

The ping command in Linux is slightly different from the ping command in Windows. In Linux, the ping command does not terminate automatically. You need to press CTRL + C to terminate the ping command or use the -c parameter to specify the number of response times.

The ping command uses the ECHO_REQUEST packet based on the ICMP protocol to detect the specified host and gateway and expects to obtain an ICMP ECHO_RESPONSE response packet. The ECHO_REQUEST datagram has an IP and ICMP header, followed by a timeVal structure, and finally any number of padding bytes to assemble into the complete packet data. Where, hops is the gateway to be crossed, dest is the host name or IP address of the target system.

In most cases, the output of the ping command can be used to determine whether the target host is accessible (but this is not absolute). To prevent ping detection, some servers disable ping through firewalls or disable ping in kernel parameters. In this way, the host cannot be pinged to determine whether it is still enabled.

The command format

Ping [parameter] [Host name or IP address]Copy the code

The command parameter

parameter explain
-a Added an audio prompt when testing network connectivity.
-A Adaptive connectivity testing. Automatically adjusts the time interval between packet data to accommodate the round-trip response time of network communication to avoid one or more (if specified) in the network-lOption) for unresponded probe grouping data above. For the average user, the minimum interval is 200 milliseconds. On networks with low round-trip times, this test is equivalent to a flood test.
-b Allows testing broadcast addresses. banpingModify the source address of the probe packet data (bound topingThe address selected to start the run).
-c count In sending specified quantitycount 的 ECHO_REQUESTStop after grouping data. with-wOptions used together,pingThe command will wait for the specified numbercount 的 ECHO_REPLYGroup data until timeout.
-d Sets the value of the socket currently usedSO_DEBUGOptions. In fact, the Linux kernel does not use this socket option.
-f Limit detection. Send network packets to a machine in large numbers and quickly to see how it responds.
-i intvl Seconds: Sets the number of seconds at which a network packet is sent to a machine. The default value is once a second.
-I Network interface: sends packets using the specified network interface.
-l Preloading: Sets the packet that is sent before the requested message is sent.
-n Output only numeric values. Display the IP address instead of interpreting the IP address as a symbolic name.
-p Template style: Sets the template style for filling packets.
-q Quiet output mode. Do not display any information about sending packets, only the final result.
-r Bypassing the regular routing table, packet data is sent directly to the host connected to the network interface.
-R Record the routing process.
-s Specifies the number of bytes of data to send. The default is56, and8Bytes of ICMP header information are combined to form 64 bytes of ICMP packet data.
-t Survival value: Sets the survival valueTTLThe size of the.
-v Detailed display of command execution process.
-w End value: specifiespingTimeout value (in seconds) for the command to terminate execution.

Examples of application

  1. Tests network connectivity between the local system and the remote host, and whether the remote host is running.
Ping baidu.com (220.181.baidu.com): 56 data bytes 64 bytes from 220.181.38.251: Icmp_seq =0 TTL =49 time=10.255 ms 64 bytes from 220.181.38.251: ICmp_seq =1 TTL =49 time=9.296 msCopy the code
  1. Ping fails
Ping-na www.google.com.hk ping www-wide.l.google.com (74.125.23.199): 56 data bytes Request timeout for icmp_seq 0 Request timeout for icmp_seq 1 Request timeout for icmp_seq 2Copy the code

Reference documentation

  • The ping command