How to Use the ping Command to Test Network Connectivity in Ubuntu

When your Ubuntu computer suddenly loses internet access, or when you are trying to connect to a new local server but keep getting connection timeouts, you need a way to figure out where the connection is breaking down. Is your router offline? Is the remote website down? Or is your computer’s network card misconfigured?

The fastest way to diagnose network problems in the Linux terminal is using the ping command. It acts like digital sonar, sending tiny packets of data to a specific destination and listening for a response, known as an “echo reply”.

How to Use the ping Command

The basic syntax requires the command followed by the domain name or IP address you want to test.

  1. Open your terminal application (press Ctrl + Alt + T).
  2. Type the command and the address. For example, to test your internet connection by reaching out to Google’s public servers, type:
    ping google.com
  3. Press Enter.

Unlike Windows, where the ping command sends exactly four packets and then automatically stops, Ubuntu will continue sending pings infinitely until you manually tell it to stop.

To stop the ping command, you must press Ctrl + C on your keyboard. The terminal will immediately halt the process and display a statistical summary.

Understanding the Output

While the command is running, you will see a continuous stream of text that looks like this:

64 bytes from 142.250.190.46: icmp_seq=1 ttl=117 time=14.2 ms

Here is what that data actually means:

  • 64 bytes: The size of the data packet sent.
  • 142.250.190.46: The IP address of the server that replied. (Notice how the ping command automatically translated “google.com” into its underlying IP address using DNS).
  • icmp_seq=1: The sequence number of the packet. This helps you track if any packets were dropped or arrived out of order.
  • ttl=117: “Time to Live”. This number decreases every time the packet passes through a router. It prevents lost packets from bouncing around the internet forever.
  • time=14.2 ms: The latency. This is how long it took (in milliseconds) for the packet to travel to the server and back. Lower numbers mean a faster, more responsive connection.

How to Limit the Number of Pings

If you prefer the Windows-style behaviour where the command stops automatically, you can use the -c (count) flag.

To send exactly five packets and then automatically stop, run:

ping -c 5 google.com

Diagnosing Problems with ping

By pinging specific targets, you can map out exactly where a network failure is occurring.

  1. Ping localhost or 127.0.0.1: This pings your own computer’s internal network stack. If this fails, your operating system’s networking software is broken or misconfigured.
  2. Ping your Router’s IP (e.g., 192.168.1.1): If the first test passes but this fails, the physical connection (Wi-Fi or Ethernet cable) between your computer and your router is broken.
  3. Ping 8.8.8.8: This is Google’s public DNS server. If the router test passes but this fails, your router is working, but your ISP is down (you have no actual internet connection).
  4. Ping google.com: If you can ping 8.8.8.8 successfully, but pinging “google.com” results in a “Name or service not known” error, your internet is working but your DNS server is broken.

Leave a Reply

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

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.