Example Uses of the Command Ping

Use Ping to test your network connection

According to the manual page, the Linux "ping" command uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from a host of the gateway.

The manual page uses a lot of technical terms but all you need to know is that the Linux "ping" command can be used to test whether a network is available and the amount of time it takes to send and get a response from the network.

Why Would You Use the "ping" Command

Most of us visit the same useful sites regularly. For instance, we visit the BBC website to read the news and we visit the Sky Sports website to get the football news and results. You will undoubtedly have your own set of key sites such as Lifewire.

Imagine you entered the web address for Lifewire.com into your browser and the page did not load at all. The cause of this can be one of many things.

For instance, you might not have an internet connection at all even though you are connected to your router. Sometimes the internet service provider has localized issues that prevents you from using the internet.

Another reason might be that the site is genuinely down and unavailable.

Whatever the reason you can easily check the connectivity between your computer and another network using the "ping" command.

How Does the Ping Command Work

When you use your phone you dial a number (or more commonly nowadays pick their name from an address book on your phone) and the phone rings at the receiver's end. When that person answers the phone and says "hello" you know you have a connection.

The "ping" command works in a similar way. You specify the IP address which is the equivalent to a phone number or a web address (the name associated with the IP address) and "ping" sends off a request to that address. When the receiving network receives the request it will send back a response which is basically saying "hello".

The time taken for the network to respond is called the latency.

Example Use of the "ping" Command

To test whether a website is available, type "ping" followed by the name of the site you wish to connect to. For example, to ping Lifewire.com you would run the following command:

Linux ping command

The ping command continuously sends requests to the network and when a response is received you will receive a line of output with the following information:

  • number of bytes received
  • the IP address
  • a sequence number
  • the time taken to respond

If the network you are trying to ping doesn't respond because it is unavailable then you will be notified of this.

Linux ping with IP address

If you know the IP address of the network you can use this in place of the website name:

Get an Audible "ping"

You can get the ping command to make a noise whenever a response is returned by using the "-a" switch as part of the command as shown in the following command:

Return the IPv4 or IPv6 Address

IPv6 is the next-generation protocol for assigning network addresses as it provides more unique possible combinations and it is due to replace the IPv4 protocol in the future.

The IPv4 protocol assigns IP addresses in the way we are currently used to. (For example

The IPv6 protocol assigns IP addresses in the format [fe80::51c1::a14b::8dec%12].

If you want to return the IPv4 format of the network address you can use the following command:

To use the IPv6 only format you can use the following command:

Limit the Number of Pings

By default when you ping a network it continues to do so until you press CTRL and C at the same time to end the process.

Unless you are testing the network speed you will probably only want to ping until you receive a response.

Linux ping with limited number

You can limit the number of attempts by using the "-c" switch as follows:

What happens here is that the request in the above command is sent 4 times. The result is you might get 4 packets sent and only 1 reply.

Linux ping with limited time

Another thing you can do is set a deadline of how long to run the ping command by using the "-w" switch.

This sets a deadline for the ping to last for 10 seconds. 

What is interesting about running the commands in this way is the output as it shows how many packets were sent and how many received.

If 10 packets were sent and only 9 were received back then that amounts to a 10% packet loss. The higher the loss the worse the connection.

You can use another switch which floods the number of requests to the receiving network. For every packet sent a dot is displayed on the screen and every time the network responds the dot is taken away. Using this method you can see visually how many packets are getting lost.

Linux ping flood with interval and limit

You need to be a superuser to run this command and it really is for network monitoring purposes only.

The opposite of flooding is to specify a longer interval between each request. To do this you can use the "-i" switch as follows:

The above command will ping lifewire.com every 4 seconds.

How to Suppress Output

You might not care about all the stuff that happens between each request sent and received but just the output at the beginning and end.

Linux ping suppressed output

For instance, if you sent the following command using the "-q" switch you will receive a message stating the IP address being pinged and at the end, the number of packets sent, received and the packet loss without every intervening line repeated.


The ping command has a few other options which can be found by reading the manual page.

To read the manual page run the following command:

Was this page helpful?