Site icon yCrash

ping – Unix/Linux command, beginners introduction with examples 

‘ping’ command is used to troubleshoot and diagnose network connectivity issues. It is used to check whether the host is reachable. It’s available on all the Operating Systems. ‘ping’ reports the round-trip time for the messages sent from the source to the destination.

How does ‘ping’ work?

Fig: Ping Packets 

Ping command sends a 32 bytes ICMP (Internet Control Message Protocol) packet from “Host A” (Source) to “Host B” (Destination) and waits for the “Host B” to be responded with a 32 bytes packet to “Host A”. If connectivity is successful then overall round trip time is printed, if not reason for failure such as packet loss, timeout, connectivity errors,… are printed.

How to execute the ‘ping’ command ?

Here is how you can invoke this command:

ping [IP/domain]

Example: 

 ping gceasy.com

When the above command is issued, the following message will be printed in the console:

Pinging gceasy.com [195.201.17.137] with 32 bytes of data:
Reply from 195.201.17.137: bytes=32 time=217ms TTL=45
Reply from 195.201.17.137: bytes=32 time=185ms TTL=45
Reply from 195.201.17.137: bytes=32 time=188ms TTL=45
Reply from 195.201.17.137: bytes=32 time=196ms TTL=45

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

Where,

What is the ping’s default TTL?

Ping command’s TTL (Time To Live) Values differ from Operating system to Operating system. Following table summarizes the ping command’s default TTL value for the popular Operating systems:

Linux/Unix64
Windows128
Solaris/AIX254

Ping Errors:

Example:  

ping gceasy.io

Pinging gceasy.io [52.52.12.54] with 32 bytes of data:
Request timed out.
Request timed out.
Request timed out.
Request timed out.

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

SOLUTION: Increase the wait time using the ping -w switch.

Example: 

ping test123blah.com

Ping request could not find host test123blah.com. Please check the name and try again.

SOLUTION: Verify the hostname that is passed to the ping command. Verify whether DNS servers are available/reachable from your host.

Example: 

ping 192.168.0.0

Pinging 192.168.0.0 with 32 bytes of data:
Reply from 192.168.0.102: Destination host unreachable.
Reply from 192.168.0.102: Destination host unreachable.
Reply from 192.168.0.102: Destination host unreachable.
Reply from 192.168.0.102: Destination host unreachable.

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

SOLUTION: Validate whether the destination host is up and running. Modify the local route table or notify the router administrator.

SOLUTION: Identify the IP addresses that are repeating and causing the loop. On Linux, issue “route -n” command as a root user to see the current routing table. On the windows, issue the command “route print”.

Example: 

ping 2DAB:FFFF:0000:3EAE:01AA:00FF:DD72:2C4A

Pinging 2dab:ffff:0:3eae:1aa:ff:dd72:2c4a with 32 bytes of data:
PING: transmit failed. General failure.
PING: transmit failed. General failure.
PING: transmit failed. General failure.
PING: transmit failed. General failure.

Ping statistics for 2dab:ffff:0:3eae:1aa:ff:dd72:2c4a:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss)

SOLUTION: Make sure there are no issues with the network card. Make sure the latest version of the network driver is installed on the device. Check whether the proper IP address is assigned to the device.

Commonly used Ping Commands

You can use other options along with the ‘ping’ command to get to the information that you are looking for.

To send more Request:

Say if you want to send ‘5’ echo request, then you can issue the following command:

ping -n 5 gceasy.com

When the above command is issued, the following message will be printed in the console:

Pinging gceasy.com [195.201.17.137] with 32 bytes of data:
Reply from 195.201.17.137: bytes=32 time=168ms TTL=45
Reply from 195.201.17.137: bytes=32 time=165ms TTL=45
Reply from 195.201.17.137: bytes=32 time=170ms TTL=45
Reply from 195.201.17.137: bytes=32 time=170ms TTL=45
Reply from 195.201.17.137: bytes=32 time=183ms TTL=45

Ping statistics for 195.201.17.137:
    Packets: Sent = 5, Received = 5, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 165ms, Maximum = 183ms, Average = 171ms

To Ping the specified host until stopped:

Say if you want to send request to the specified host until it is manually stopped, then you can issue the following command:

ping -t gceasy.com

Also Read – How to kill processes in Unix/Linux effectively! Master commands like kill and pkill to terminate tasks and manage your system efficiently.

Tools for Ping

Performance root cause analysis tools like yCrash, captures application level artifacts (like thread dump, heap dump, Garbage Collection log) and system level artifacts (like netstat, vmstat, iostat, top, top -H, dmesg,…). Along with it, the tool also captures the ping command output. Tool analyzes all these artifacts and generates an unified root cause analysis report instantly. If the tool spots any errors in the ping command output, it will raise an alert in the report. 

Fig: ping output captured and reported in yCrash tool

‘ping’ command options

 If you want to know all the options passed to the ‘ping’ command, please refer here.

Exit mobile version