What is a Ping Command?

Ping or Packet Internet Groper is a network administration software utility used to check whether a network is available and if a host is reachable over an IP network. It is a command-line utility that is available in any Operating Systems that have network capability. Windows, Linux, and MacOS, the top three Operating Systems also have this command-line utility, although, with slightly different command syntaxes, all come with the same function. 

Ping commands act to see if a network device is reachable through sending a request over the network to a specific device. There are many ways to use the ping commands. Later, we will walk you through all the useful Linux ping commands and explain them deeper.

How does a Ping Command work?

In a nutshell, a Ping command is a network tool used to determine whether a certain IP address or host is accessible. The ping utility uses the echo request and echoes reply messages within the Internet Control Message Protocol (ICMP) – an Integral part of an IP network. 

When a Ping Command is issued, an ICMP request message is sent to the specific device or certain IP Address. If the destination IP address is available, it sends an ICMP message response to the sender. 

Linux Ping Commands

In using the ping command utility, all you need is a terminal with user permissions to run the command. The basic ping syntax includes the word ‘ping’ followed by a specific hostname or IP address.

ping [option] hostname or IP address

As an example:

——————————————————————————————————————-

$ ping google.com

——————————————————————————————————————-

The ping command resolves the domain name into an IP address and starts sending ICMP packages to the destination IP. If the destination IP address is reachable it sends an ICMP message response to the sender. 

The output or the message response will be like this:

——————————————————————————————————————-

Output

PING google.com (172.217.22.206) 56(84) bytes of data.

64 bytes from muc11s01-in-f14.1e100.net (172.217.22.206): icmp_seq=1 ttl=53 time=40.2 ms

64 bytes from muc11s01-in-f14.1e100.net (172.217.22.206): icmp_seq=2 ttl=53 time=41.8 ms

64 bytes from muc11s01-in-f14.1e100.net (172.217.22.206): icmp_seq=3 ttl=53 time=47.4 ms

64 bytes from muc11s01-in-f14.1e100.net (172.217.22.206): icmp_seq=4 ttl=53 time=41.4 ms

^C

— google.com ping statistics —

4 packets transmitted, 4 received, 0% packet loss, time 7ms

rtt min/avg/max/mdev = 40.163/42.700/47.408/2.790 ms

——————————————————————————————————————-

This tells us about the connectivity status of the network with a packet of information the ping command prints a line that includes the following fields:

               from: This is the destination or the sender with its given IP address. The IP address varies for websites depending on your geographical location.

  icmp_seq=1: This is the number of echo request and the sequence number of each ICMP packet; it increases by one for every subsequent echo request.

               ttl=53: ttl or Time to Live value from 1 to 255, It represents the number of network hops before it discards.

time=40.2 ms: The time it took a packet to reach the destination and come back to the source. Expressed in milliseconds.

When the remote host receives the echo request, it responds with an echo reply packet. . It shows how many bytes where received in response, the time to live (ttl), and how long the response took to receive.

Note: The process will continue to send ICMP packages to the destination until it receives interruption. To stop this process, press ‘Ctrl + C’ combination keys to interrupt.

Ping “localhost” to Check Local Network

The best practice in troubleshooting when encountering issues reaching a certain device or specific IP address is to check your local network by pinging your localhost. There are three ways to check the local network interface:

  • ping 0 – this is the fastest and quickest way to ping localhost. The terminal resolves the IP address and provides a response automatically.
  • ping localhost – Simply by typing the word 'localhost' you can get a response from it.
  • ping 127.0.0.1 – "There's no place like 127.0.0.1" which means 'home'. The home here indicates your localhost.

You can choose whichever you are comfortable, the output is all the same.

——————————————————————————————————–

$ ping localhost

PING localhost (127.0.0.1) 56(84) bytes of data.

64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=53 time=0.012 ms

64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=53 time=0.016 ms

64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=53 time=0.017 ms

64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=53 time=0.020 ms

^C

— localhost ping statistics —

4 packets transmitted, 4 received, 0% packet loss, time 2080ms

rtt min/avg/max/mdev = 0.12/0.016/0.020/0.006 ms

——————————————————————————————————–

A successful ping results in a response from the computer that was ping backed to the computer. If ping does not return a reply, it means that there is no network communication established. Chances are the destination IP is down or not active. In some cases, it may have a firewall that disallows the connection and blocks the ICMP traffic or other third-party applications that blocks the response to ping requests.

Increase/Decrease interval between ping packets

By default, the interval time between sending each packet is 1 second in Linux. To specify an interval between successive packet transmissions, see this example below:

               $ ping -i 5 127.0.0.1         // Increase the time interval between packet transmissions.

               $ ping -i 0.5 127.0.0.1     // Decrease the time interval between packet transmissions.

There are some cases that you need to be a super user – ‘$sudo ‘ (Administrator Privileges) in order for their other ping option commands to be used.

Initiate the desired number of packets

You can also set ping to send a desired number of packets

               $ ping -c NumberOfPackets IP/hostname

               $ ping -c 5 127.0.0.1        //Sets the number of packets transmitted to 5.

$ ping -c 5 127.0.0.1  

PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.

64 bytes from 127.0.0.1: icmp_seq=1 ttl=53 time=0.012 ms

64 bytes from 127.0.0.1: icmp_seq=2 ttl=53 time=0.016 ms

64 bytes from 127.0.0.1: icmp_seq=3 ttl=53 time=0.017 ms

64 bytes from 127.0.0.1: icmp_seq=4 ttl=53 time=0.020 ms

— 127.0.0.1 ping statistics —

4 packets transmitted, 4 received, 0% packet loss, time 2080ms

rtt min/avg/max/mdev = 0.12/0.016/0.020/0.006 ms

 

Here are the other ping option commands that you can try:

     Ping Option

  What The Command Does

  a

  Generates a sound when the peer can be reached.

  b

  Allows to ping a broadcast IP address.

  B

  Prevents the ping to change the source address of the probe.

  c (count)

  Limits the number of sent ping requests.

  d

  Sets the SO-DEBUG option on the used socket.

  f

  Floods the network by sending hundreds of packets per second.

  i (interval)

  Specifies an interval between successive packet transmissions. 

The default value is one second.

  I (interface address)

  Sets the source IP address to the specified interface IP address. 

The option is required when pinging IPv6 link local address. 

You can use an IP address or name of the device.

  l (preload)

  Defines the number of packets to send without waiting for a reply. 

To specify a value higher than 3, you need superuser permissions.

  n

  Displays IP addresses in the ping output rather than hostnames.

  q

  Shows a quiet output. One ping line is displayed and the summary of 

the ping command at the end.

  T (ttl)

  Sets the Time To Live.

  v

  It provides verbose output.

  V

  Displays the ping version and exits to a new command prompt line.

  w (deadline)

  Specifies a time limit before the ping command exits, regardless of

how many packets have been sent or received.

  W (timeout)

  Determines the time, in seconds, to wait for a response.

A successful ping results in a response from the computer that was ping backed to the computer. 

The most common use of ping is network troubleshooting. When trying to use applications or systems over a network, the most important thing to know is if there is a working connection. Ping can also be used to monitor the network availability of devices, the stability of established network connection.

We will be happy to hear your thoughts

Leave a reply

Coders Eye - Web Dev Tutorials and How-To Guides for Beginners
Logo
Enable registration in settings - general