What is Ping command?

The ping command is used to verify that communication with a particular PC or server is possible. It is a very commonly used verification command to find out the cause of network problems.

The Ping command works in a very simple way: When you execute the ping command, it asks the specified peer to return some data (in Windows, a sequence of alphabetic characters) verbatim. When the peer receives the ICMP echo request, it responds with the data exactly as it was received, which is called an ICMP echo reply. When an ICMP echo reply is returned, it means that data has been exchanged back and forth between the communication partner.

The ping command also shows the approximate time required for round-trip data exchange.

Figure: How ping works
Figure: How ping works

Ping command on Windows OS

The ping command is executed at the command prompt; the syntax of the ping command is as follows.

Windows OS ping command

C:\>ping <IP address or hostname>

When a hostname is specified, the system automatically queries the DNS server to obtain the IP address for the hostname and sends an ICMP echo request to that IP address.

As shown below, if a response (ICMP echo reply) is returned from the specified IP address, it indicates that normal communication is possible. In addition to verifying communication, the ping command can also be used as a simple network performance measurement as it provides an estimate of the response time.

Figure: Example of ping command execution result
Figure: Example of ping command execution result
C:\Users\gene>ping 8.8.8.8

Pinging 8.8.8.8 with 32 bytes of data:
Reply from 8.8.8.8: bytes=32 time=4ms TTL=59
Reply from 8.8.8.8: bytes=32 time=3ms TTL=59
Reply from 8.8.8.8: bytes=32 time=4ms TTL=59
Reply from 8.8.8.8: bytes=32 time=3ms TTL=59

Ping statistics for 8.8.8.8:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 3ms, Maximum = 4ms, Average = 3ms

You can specify various options when executing the ping command.

ping command optionsMeaning
-tContinuously execute the ping command. To stop, type CTRL+C
-l <size>Specify the data size to be sent when the ping command is executed
-w <msec>Specify the time to wait for a response in milliseconds
-n <number>Specifies the number of times data is sent when a ping command is executed
Table Ping command options

If the ping command does not return a successful response from the communication partner, there is a problem somewhere between you and the communication peer. Note that if the ping command fails, it may simply time out, or it may return a response from someone other than the communicating peer.

A response from a non-communicating peer reports an error that the data could not be delivered. For example, in the following figure, the command ping 10.10.10.10 returns a response. However, this is not a response from the specified 10.10.10.10. The 219.103.128.145 along the way is reporting to the source that executed the ping command that it “could not transfer data to 10.10.10.10.10.

Figure: Example of ping command failure
Figure: Example of ping command failure
C:\Users\gene>ping 1.1.1.1

Pinging 1.1.1.1 with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.

Ping statistics for 1.1.1.1:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

C:\Users\gene>ping 10.10.10.10

Pinging 10.10.10.10 with 32 bytes of data:
Reply from 209.103.128.145: Destination network unreachable.
Reply from 209.103.128.145: Destination network unreachable.
Reply from 209.103.128.145: Destination network unreachable.
Reply from 209.103.128.145: Destination network unreachable.

Ping statistics for 10.10.10.10:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Note that a failed ping command does not necessarily mean that there is a problem with the network. A malicious user may exploit ICMP used in the ping command to attack the network or a specific server. To prevent such attacks, security software or firewalls may prevent responses to ping commands.

Also, when a ping command fails, it is often simply a matter of specifying the wrong IP address; be careful not to specify the wrong IP address when executing the ping command.