How to use the ping Command on Ubuntu

In this guide, we will be showing you how to use the ping command on the Ubuntu operating system.

ping command on Ubuntu

Using the ping tool on Ubuntu helps diagnose the network connectivity between your device and a network destination.

It achieves this by sending a packet to the destination and awaiting a response. The time it takes for this request to be sent and a response received is calculated giving you your latency.

When the ping command doesn’t get a request back, it can indicate your Ubuntu device either has no connection to the destination. Please note that some services actively block the ICMP packet the ping tool utilizes.

This tool is different from the traceroute command on Ubuntu. That tool shows you your connection’s path when going from your device to the destination.

If you simply want to see whether you have a connection, you will want to use the ping tool on Ubuntu instead.

Using the ping Command on Ubuntu

In this section, we will be exploring how you can use the ping utility on Ubuntu. Using this tool, you will be able to check whether your device can connect to a specific syntax.

The ping tool should come packaged alongside your Ubuntu distribution, but it can be installed if it is missing. Skip down to our “Installing ping on Ubuntu” section if you find it missing from your system.

You will see how straightforward this tool is to use, especially when you only need to perform a basic connectivity test.

The following steps will all be performed within the terminal. You can open the terminal on the desktop version of Ubuntu by pressing CTRL + ALT + T.

Basic Usage of ping on Ubuntu

The ping tool is very straightforward to use as you don’t really need to worry about any options. When used without any options, the command will continue to ping the destination until you kill the process.

Below you can see the basic syntax for this command. We won’t be exploring the options parameter much within this guide.

ping [OPTIONS] DESTINATION

The “DESTINATION” can be an IP address or a domain name. If you specify a domain name, the ping tool will use your Ubuntu systems configured nameserver to resolve the IP address.

Example of Using ping on google.com

To showcase how the ping tool works on Ubuntu, we can perform a ping request to a known server.

In this example, we will use “google.com” as the destination for our device to ping. It’s an excellent website to test internet connectivity with due to its distributed servers, and it rarely goes offline.

To perform this request, we need to use “ping” followed by the destination.

ping google.com

As the tool runs, you will see each ping request your device makes to the destination. There will be a slight delay between each request as the tool waits to see if the previous request has been received.

Using this, you can see the destination IP address and how long the ping request took to come back from the destination, alongside some additional information.

Once stopped, the tool will give you an overview of all the ping requests sent . Using this, you can see various information, including the number of packets transmitted and received and the percentage of packets lost.

PING google.com (172.217.167.110) 56(84) bytes of data.
64 bytes from syd09s17-in-f14.1e100.net (172.217.167.110): icmp_seq=1 ttl=116 time=61.3 ms
64 bytes from syd09s17-in-f14.1e100.net (172.217.167.110): icmp_seq=2 ttl=116 time=52.0 ms
64 bytes from syd09s17-in-f14.1e100.net (172.217.167.110): icmp_seq=3 ttl=116 time=58.5 ms
64 bytes from syd09s17-in-f14.1e100.net (172.217.167.110): icmp_seq=4 ttl=116 time=40.9 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 40.875/53.170/61.292/7.863 ms

You can stop the ping tool from running on your Ubuntu device by pressing CTRL + C within the terminal session.

Limiting the Number of Pings

If you want to test the network connectivity of your Ubuntu device using a limited number of pings, then there is an option you can utilize.

This option is called the “count” and can be set by using the “-c” option followed by the number of pings.

Below you can see the basic syntax of using ping on Ubuntu while limiting the number of pings.

ping -c COUNT DESTINATION

Example of Limiting the Number of pings on Ubuntu

For this example, we will use our Ubuntu device to ping “google.com” but limit the number of pings it makes to only two.

To achieve this, we use “ping” followed by the “-c” option, then the number 2, and finally the destination for our pings.

ping -c 2 google.com

After running this command, your device will make two ping requests to the specified destination. You won’t have to stop the process manually.

PING google.com (172.217.24.46) 56(84) bytes of data.
64 bytes from syd15s20-in-f14.1e100.net (172.217.24.46): icmp_seq=1 ttl=115 time=49.2 ms
64 bytes from syd15s20-in-f14.1e100.net (172.217.24.46): icmp_seq=2 ttl=115 time=36.0 ms

--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 36.040/42.606/49.172/6.566 ms

Installing ping on Ubuntu

If your Ubuntu distribution didn’t come with the ping utilities for some reason, it can be easily installed. Often this might be the case when dealing with slim distributions such as the ones provided for Docker images.

You can tell that your system doesn’t have the package available by the error message “ping: command not found“.

With the following two steps, you will easily get the ping command installed on your Ubuntu system.

1. Start by updating the package list of your Ubuntu system by running the command below.

sudo apt update

2. Once the update completes, you can install the “iputils-ping” package by using the following command.

This package contains everything your system needs to perform a ping to a networked device.

sudo apt install iputils-ping

3. You should now be able to use the ping command on your Ubuntu system.

You should check out the previous two sections for some of the simple ways to use this utility.

Conclusion

This guide has shown you how to use the ping command on your Ubuntu device to check your network connectivity.

We have a tutorial that takes a deeper dive into how this ping command works that is well worth a look.

If you have any questions about using ping on Ubuntu, please comment below.

Be sure to check out our other Ubuntu guides or our general Linux command tutorials.

Leave a Reply

Your email address will not be published. Required fields are marked *