How to Ping a Server in Linux to Test Network Connectivity

If you are working on a Linux server and a website suddenly refuses to load, or you cannot connect to a remote database, your first troubleshooting step should always be to check your basic network connectivity. Before you start digging through complex firewall rules or rebooting routers, you need to answer a simple question: “Can my computer physically talk to the destination server over the internet?” You answer this question using the ping command.

How the Ping Command Works

The ping utility works exactly like a submarine’s sonar. It sends a tiny data packet (an ICMP Echo Request) across the internet to a specific destination. If the destination server receives it, it bounces a reply (an Echo Reply) back to you. By measuring how long the round trip takes, you can diagnose network lag or total connection failure.

To test your connection, open your terminal and type ping followed by a website address or a specific IP address.

ping google.com

Press Enter. Your terminal will immediately begin printing lines of text, one after another.

How to Read the Results

Each line represents one round-trip packet. You are looking for two crucial pieces of information:

  1. Time (Latency): At the end of each line, you will see something like time=14.2 ms. This is the milliseconds it took for the data to travel there and back. A low number (under 50ms) is excellent. A very high number (over 200ms) indicates a slow, laggy connection.
  2. Packet Loss: If a line says “Request timeout” or “Destination Host Unreachable,” the packet died on the journey. This means the internet connection is broken or the server is completely offline.

How to Stop the Ping

Unlike Windows, which automatically stops after sending four packets, the Linux ping command will continue running forever until you explicitly tell it to stop.

To force the command to quit, hold Ctrl and press C on your keyboard.

Linux will immediately stop pinging and print a summary report, showing you exactly how many packets were sent, how many were received, and the total percentage of packet loss.

If you want Linux to behave like Windows and automatically quit after sending a specific number of packets, you can use the -c (count) flag. For example, to send exactly four packets and then stop automatically, type:

ping -c 4 google.com

Get the best tech tips delivered straight to your inbox.

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