How to use Ping command.

How To Use Ping Command.

In this article, wee will explain how to use ping command.

ping is part of the iputils (or iputils-ping) package, which is pre-installed on nearly all Linux distributions. It is also available on Windows, macOS, and FreeBSD.

 

How to Use the Ping Command

The syntax for the ping command is as follows:

ping [OPTIONS] DESTINATION

To better illustrate, how the ping command works let’s ping nexonhost.com:

ping nexonhost.com

The output will look something like this:

PING nexonhost.com (89.45.12.91) 56(84) bytes of data.
64 bytes from 89.45.12.91 (89.45.12.91): icmp_seq=1 ttl=63 time=0.527 ms
64 bytes from 89.45.12.91 (89.45.12.91): icmp_seq=2 ttl=63 time=0.637 ms
64 bytes from 89.45.12.91 (89.45.12.91): icmp_seq=3 ttl=63 time=0.577 ms
64 bytes from 89.45.12.91 (89.45.12.91): icmp_seq=4 ttl=63 time=0.573 ms
64 bytes from 89.45.12.91 (89.45.12.91): icmp_seq=5 ttl=63 time=0.610 ms
^C
--- nexonhost.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4001ms
rtt min/avg/max/mdev = 0.527/0.584/0.637/0.048 ms

 

Specify the Number of Packets

As already mentioned, by default, ping will continue to send ICMP packages until it receives an interrupt signal. To specify the number of Echo Request packages to be sent after which ping will exit, use the -c option followed by the number of the packages:

ping -c 1 DESTINATION

For example, to ping linuxize.com only one time you would use:

ping -c 1 nexonhost.com

 

Specify the Source Interface

The default behavior of the ping command is to send ICMP packages via the default route. If you have multiple interfaces on your machine you can specify the source interface with the -I option:

ping -I INTERFACE_NAME DESTINATION

The following command will ping linuxize.com using em2 as a source interface:

ping -I em2 nexonhost.com

 

Specify the Internet Protocol

When you run the ping command, it will use either IPv4 or IPv6, depending on your machine DNS settings.

To force ping to use IPv4, pass the -4 option, or use its alias ping4:

ping -4 DESTINATION

 

For IPv6, pass the -6 option or use ping6:

ping -6 DESTINATION

 

Conclusion

ping is a command-line network utility that allows you to test the IP-level connectivity of a given host on the network.

To view all available options of the ping command, type man ping in your terminal.