How to use Ping Command in Unix | Ping Command Examples

Ping Command :

In UNIX, there are lot of communication utilities and user needs to use set of UNIX commands. I have already explained about the file creation in UNIX using multiple ways. When you work in distributed environment, you need to communicate with remote users and need to access remote machines. The Ping Command in UNIX is used to test ability of source computer to reach specified destination. The Ping command is used to check the connectivity with your source computer with the set of devices in the network. It usually sends the request to the computer in the network or device in the network .If user will get proper reply then the network is working properly.

The ping command is used to isolate the network hardware problems.

Tasks of Ping command :

If you are thinking that the ping is very simple command used to check the connectivity of the network, there are other uses of ping command.

1.Ping To diagnose connectivity :

First and most important use of ping command is to diagnose the network connectivity.

Check TCP-IP Connection :

Ping the loopback address to check TCP-IP connection is working fine.

Example :

Ping 127.1.0.1

Output :

Pinging 127.1.0.1 with 1450 bytes of data:

Reply from 127.1.0.1 bytes=1450 time<10ms TTL=32

Reply from 127.1.0.1: bytes=1450 time<10ms TTL=32

2.Ping IP address of local computer / Default gateway / remote host :

User can ping the ip address of local computer to check it is added to network correctly.User can check the connectivity of default gateway as well as remote host.

Example:

ping 10.14.129.23

Output:

Pinging 10.14.129.23 with 32 bytes of data:

Reply from 10.14.129.23: bytes=32 time<1ms TTL=128

Reply from 10.14.129.23: bytes=32 time<1ms TTL=128

Reply from 10.14.129.23: bytes=32 time<1ms TTL=128

Reply from 10.14.129.23: bytes=32 time<1ms TTL=128

Ping statistics for 10.14.129.23:

Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

Approximate round trip times in milli-seconds:

Minimum = 0ms, Maximum = 0ms, Average = 0ms

Ping Command

3.Increase or decrease the time interval between packets :

By default the Ping Command will wait till 1 second to send next packet.User can increase or decrease the packet interval by using –i option of ping. Only super user can specify interval less than 0.2 seconds.

Examples :

$Ping – I 5 10.14.129.23

The above ping command will wait 5 seconds before sending next packet.

$Ping – I 0.1 10.14.129.23

The above ping command will wait 1 milliseconds before sending next packet.

4.Show the version :

The –V option of ping is used to show the version and exit. The –V option is used to show the current version of ping program.

Example :

$Ping –V

Output :

ping utility, iputils-sss20181127

5. Send N packets in network :

-c option of ping command will send N packets over the network and then exit. Using this option the ping command will exit automatically rather than pressing CTRL + C to exit.

Example : 

$Ping –c  5 10.94.122.201

The above ping command will send 5 packets over the network and waits for response from destination .The ping will exit after response or error.

6.Audio ping :

The –a option of ping command is used for audible ping.This option is useful for system admin for troubleshooting. You can continue working with your changes, and when the remote machine become reachable you’ll hear the beep automatically. The disadvantage of this option is this option will not work with console.

Example :

$Ping –a   10.94.122.201

The user will get the beep sound after the remote computer is reachable.

7.Changing the Ping packet size :

Ping command is used to change the packet size using – s option of command.

Example :

$Ping –s 100 10.94.122.201

Output :

PING 10.94.122.201 (127.0.0.1) 100(128) bytes of data.

Formula :

Ping Bytes Sent = Ping Packet Size + Ping Header Packet Size (28 bytes)

The size is showing 128 which is nothing but the Packet header size + packet size. The packet size is 100 and its header size is 28.

8. Timeout option of Ping Command :

User can set the specific time to send the packets in the network. This actually specifies the total number of seconds the Ping command to send the packet to remote host. If you specify the less time then the timeout error will come.

Example :

ping -w 0.2 10.14.129.23

 Output : 

Pinging 10.14.129.23 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 10.14.129.23:

Packets: Sent = 4, Received = 0, Lost = 4 (100% loss).

9. Checking reachability of your server from different locations :

User can use the ping command to check the reachability of your server from different locations. There are different websites, which will give the status of your server from worlds different locations.

Check the screenshot:

 

These are some different uses of the Ping command. If you will get the error in ping command then user needs to check some points to resolve the error of server.

Resolution of Error ‘Request time out’ :

Ping Command

If the network is not working properly or terminal is not in the network then Request time out error will come.Following are basic checkpoints to resolve this error :

1.Check Firewall :

Most of the times the Ping Command is blocked at firewall level. User needs to check that and configure the firewall to allow ping command network access. For personal firewall user needs to allow the ICMP Echo and Echo Reply Packets.

2.Check Router Status :

Sometimes the router is down and due to that there is problem in network connectivity. Try to use tracert command to check the path between source and destination.

3.Destination Host Down :

Check the physical connectivity of destination host. When the destination host will down then Request time out error will come.

4.Check Response latency :

Sometimes latency of response is more than one seconds so the Request time out error will come. In that case, using – w increase the timeout of packet send and receive.

Destination net unreachable :

Sometimes user will get error ‘Destination net unreachable’. This error will come when there was no route to the destination.User need to check the routing table and reply from address is correct or not in  routing table.