Advanced usage of Ping command

Advanced usage of Ping command

The ping command is used to test the reachability and latency of the network connection, but the specific implementation of the ping command may be different in different operating systems, so some options may be different.

ping command

The ping command is used to test the reachability and latency of the network connection. It determines the network connection status by sending an ICMP echo request (ping request) to the target host and waiting for the target host to return an ICMP echo response (ping response).


The basic syntax for using the ping command is as follows:

ping [选项] 目标主机
  • 1.

Options include:

usage: ping [-AaDdfnoQqRrv] [-c count] [-G sweepmaxsize]
            [-g sweepminsize] [-h sweepincrsize] [-i wait]
            [-l preload] [-M mask | time] [-m ttl] [-p pattern]
            [-S src_addr] [-s packetsize] [-t timeout][-W waittime]
            [-z tos] host
       ping [-AaDdfLnoQqRrv] [-c count] [-I iface] [-i wait]
            [-l preload] [-M mask | time] [-m ttl] [-p pattern] [-S src_addr]
            [-s packetsize] [-T ttl] [-t timeout] [-W waittime]
            [-z tos] mcast-group
Apple specific options (to be specified before mcast-group or host like all options)
            -b boundif           # bind the socket to the interface
            -k traffic_class     # set traffic class socket option
            -K net_service_type  # set traffic class socket options
            --apple-connect       # call connect(2) in the socket
            --apple-time          # display current time
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.

For example, to ping a target host (such as www.example.com) and send 5 ping requests, you can use the following command:

ping -c 5 www.example.com
  • 1.

The ping command will display the results of each ping request, including the IP address of the target host, the packet size of the ping request, the time of the ping request, and the ping response information returned from the target host.

Please note that the specific implementation of the ping command may vary in different operating systems, so some options may differ.

Use of ping -t

Ping -t is a command under Windows system that is used to continuously send ICMP Echo requests to the specified target IP address to test the stability and latency of the network connection. Among them, the -t parameter means to continue sending requests until manually stopped.

Use of ping -a

The ping -a command is used to obtain the corresponding host name through the IP address. It will send network detection packets to the specified IP address and wait for a response from the target host. When the target host responds, the ping -a command returns the hostname of the host.

Usage example:

ping -a 192.168.0.1
  • 1.

This command will send a network detection packet to the host with the IP address 192.168.0.1 and return the host name of the host.

Use of ping -n

ping -n is a command used for network diagnostics. It is used to test the network connection to the target host. In Windows systems, the ping -n command is used to specify the number of ping requests to be sent.

Usage example:

ping -n 5 www.example.com
  • 1.

The above command will send 5 ping requests to www.example.com and display the results of each request.

Use of ping -l size

ping -l size is a parameter used to specify the size of ICMP packets. Among them, size represents the size of the data packet to be sent, in bytes.

By using the ping -l size command, you can test network connectivity and latency. It sends ICMP packets to the target host and waits for a response from the target host. By observing response times and packet loss, you can evaluate the quality and performance of your network.

For example, to send a packet with a size of 64 bytes, you can use the following command:

ping -l 64
  • 1.

Note that the actual packet size sent may be slightly larger than the specified size because some additional header information needs to be included.

Use of ping -r count

ping -r count is a command used for network diagnostics, where count specifies the number of ICMP Echo requests to be sent.

Use the ping -r count command to send ICMP Echo requests to the specified target host and display the round-trip time (RTT) of each request and the IP address of each intermediate router on the routing path.

The following is an example of using the ping -r count command:

ping -r 5 www.example.com
  • 1.

This command will send 5 ICMP Echo requests to www.example.com and display the RTT of each request and the IP addresses of intermediate routers on the routing path.

Please note that the ping -r count command may have some differences on different operating systems, and the specific usage and parameters may be different. When using this command, it is recommended to consult the documentation of the relevant operating system or use the ping -r --help command for more details.

Batch ping network segments

To ping a network segment in batches, you can use the following command:

for /L %i in (1,1,255) do ping -n 1 192.168.0.%i
  • 1.

This command will ping each IP address in the specified network segment in sequence, from 1 to 255. You can replace 192.168.0 in the command with the network segment you want to ping.

Note that this command is used under Windows system. If you are using other operating systems, please use the corresponding command.