Trusted answers to developer questions

What is the PING command?

Get the Learn to Code Starter Pack

Break into tech with the logic & computer science skills you’d learn in a bootcamp or university — at a fraction of the cost. Educative's hand-on curriculum is perfect for new learners hoping to launch a career.

Packet Inter-Network Grouper is a network utility, one of the ICMPInternet control message protocol commands, and a network performance measuring/testing tool used to check if a host or a node is up and running in an inter-network.

With the ping command, we can troubleshoot our local and small network, and ascertain where exactly the fault is on the network. This can be achieved by sending a ping to the different devices on the network, using their IP address or Host-name address.

What is ping and what exactly happens when we ping?

ping is a word of action. It is a command that uses the PING utility to instruct your hostThe ping generator to send a 32-bytes (on Windows) or a 64-bytes (on LINUX or MAC) echo request message to another hostthe receiver. This host will send back an echo reply message in an internetwork to confirm that both hosts are communicating efficiently.

So what really happens?

The ping process is just like screaming your name out to a friend, who is few blocks away, to confirm if they are at home. If they are, they will respond. The only difference here is that the message sent back by the receiver must contain the same content that was sent, i.e., the name echo message.

The structure of the two messagesthe echo request and reply will be the same, only that the identifier section may change. The structure will have:

  • An identifierWhat protocol is used and the IP type of the host
  • Code (set of encoded messages)
  • Header checksumthe IP address of sender and receiver, and other communication conditions like TTL
  • Sequence numberused by the transportation layer of the OSI model for flow and error control
  • PayloadThe transmitted message as a whole. A 32-byte message (windows especially), would be split into an 8-byte block of 4byte0, byte1, byte2, byte3

Now, let’s use an example to understand the ping command better.

Let’s say that you wish to know its statusconnected or not, operational or down. I have a simple local network setup, and would ping every host on said network (from one of the hosts in the network) and watch their response. The ping command, by default, sends several echo requests, typically four.

The results of the different echo requests sent are displayed, showing whether the request received a successful reply message (that is not lost), how many bytes were received in response (normally 32 bytes), the Time to LiveTTL, and how long it took for the reply message to be received. Statistical information about the packets, how much was lost, and the round trip times will also be included.

So, let’s take our little simple network, like the internet, and ping one of our remote hosts, the www.google.com server. We will go to our command prompt or terminal and enter:

ping www.google.com

The result we get will be as displayed below:

widget

The process followed above is the same when pinging in a local network. The only condition is that the host sending the ping should be in the same inter-network as the receiving host.

Explanation of the displayed information:

  • Time To Leave (TTL): This is the maximum time given for the sent packet to be echoed back to the sender, at the expiration of which the Timeout error message is returned.
  • Time: The duration of the packet en-route to the sender and back to the receiver. That is called the round-trip time.
  • Ping statistics: Summarizes the information gathered from the pinging process, like how many packets were received and how many were lost.
  • Approximate round trip times in milli-seconds provide the maximum and minimum round trip time among the packets sent and an average.
Below are some ping command options that allow us the flexibility of specifying some other actions that our command should execute.

These syntaxes are predominantly for Windows, with some variations for other OS.

  1. If you want to make several pings, use -to like ping -t www.google.com. Use control+C to quit.
  2. If you have an IP address, you can use ping -a to resolve to hostnames.
  3. You can use the -n to change the default 4 pings to any specified number like this: ping -n 8 www.google.com. This will ping the google server eight times, rather than the default four times.
  4. To specify a Time To Live value of your choice, which must be between 1-255 milli-seconds, you can do: ping -I 45 www.google.com. This can be helpful if you want to know whether a link can be faster.
  5. The -4 and -6 options will cause a change in the identifier section, which will cause the message to be an IPV4 or IPV6 type, respectively.

I encourage you to try out these commands and learn what each really does and how they could help you solve your problems. I promise they’re harmless!

I hope this shot was helpful. Thank you for reading.

RELATED TAGS

network protocols
networking
ping
Did you find this helpful?