How to Use the Ping Command in Linux

The ping command is handy utility command to quickly test network connections. It sends a packet of data to a specific IP address or hostname and shows how long it took to transmit that data with severeal additional response information.

General syntax for ping command:

Specify the number of packets
ping -c [number] [IP-Address]

Use the -c option to have the ping command automatically stop after a certain number of packets have been sent.

Example: Let’s stop sending packets after 5 replies. And specifying as the IP address

specify number of packets
Check Localhost network
ping localhost

If you’re having trouble connecting to a remote computer or website, ping the localhost to ensure you’re connected.

Example: Let’s type this command to test the network connection.

check localhost
Send pings only for a limited period of time
ping -i [number] [IP-Address]

The -i option sets the timeout interval in seconds before each packet is sent.

Example: Sending ICMP packets with an interval of 5 seconds to the IP address

send time-limited pings
Flood ping to target host
ping -f [IP-address]

The -f option is used to run the flood ping. This will help you test the performance of your network under heavy load.

Example: Flood pinging IP address

flood ping
Change ping packet size
ping -s [number] [IP-Address]

Use the -s option to increase the default packet size, you can send light and heavy packets.

Example: Let’s increase the packet size to 1000 bytes and send them to the IP address

change ping packet size
Display only the summary lines
ping -q [IP-Address]

The -q option outputs a single line with the regular ping information, followed by the statistics.

Example: Getting only summary information about the IP address

display summary lines
Set Time Limit for receiving packages
ping -w [seconds] [IP-Address]

This option stops receiving ping output after a certain length of time.

Example: Entering the ping -w 10 command to stop printing ping output after 10 seconds.

set time limit