How to Ping a Server in Linux

When you cannot connect to a website, a database, or another computer on your network, you need a way to determine where the failure is occurring. Is your internet down? Is their server offline? Is a firewall blocking the connection? The ping command is the most fundamental diagnostic tool in a Linux administrator’s toolkit for answering these questions. It tests the reachability of a host on an Internet Protocol (IP) network and measures the round-trip time for messages sent from the originating host to a destination computer.

How Ping Works

The ping command operates using the Internet Control Message Protocol (ICMP). It sends a specific type of packet, called an “Echo Request,” to the target IP address or hostname. If the target receives the request and is configured to reply, it sends back an “Echo Reply.” By timing how long this round trip takes, ping provides vital data about network latency and packet loss.

Step-by-Step: Using the Ping Command

Using ping requires only the target’s IP address or domain name.

  1. Open your terminal application or connect via SSH.
  2. Type ping followed by a space and the target address. For example:
    ping google.com (to test external internet connectivity)
    ping 192.168.1.50 (to test a device on your local network)
  3. Press Enter.

Unlike Windows (which sends four packets and stops automatically), the Linux ping command will continue sending packets indefinitely until you force it to stop.

To stop the ping process, press Ctrl + C on your keyboard. The terminal will then print a statistical summary of the test.

Understanding the Ping Output

While the ping is running, each line represents one round trip. Pay attention to two key metrics:

  • time=XX ms: This is the latency (measured in milliseconds). A local network ping should be under 5ms. A ping to a regional internet server should be 20-50ms. Consistently high latency (over 150ms) indicates network congestion or a bad physical connection.
  • The Summary (Packet Loss): When you press Ctrl+C, look at the final statistics. If it says “0% packet loss”, your connection is stable. If it shows 10%, 50%, or 100% packet loss, packets are being dropped somewhere along the route, indicating a serious network failure.

Advanced Usage: Limiting the Count

If you are writing a script or simply do not want to press Ctrl+C every time, you can instruct ping to send a specific number of packets and then stop automatically using the -c (count) flag.

To send exactly four pings (mimicking the default Windows behavior), use:

ping -c 4 google.com

Troubleshooting Common Issues

If a ping fails, it does not necessarily mean the server is offline:

  • Firewalls blocking ICMP: Many secure servers and modern routers intentionally block incoming ICMP Echo Requests to prevent network mapping and Denial of Service (DoS) attacks. If you can browse a website perfectly fine in your browser but ping returns “Request timeout,” the server is simply ignoring your ping packets on purpose. In these cases, you must use tools like curl or telnet to test connectivity on specific ports (like port 80 or 443).

Mastering the ping command is the absolute first step in troubleshooting any Linux networking issue.

Get the best tech tips delivered straight to your inbox.

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