The ping command in Linux: how to check network connectivity

Introduction

In the world of system administration, verifying network connectivity is one of the first tasks performed when diagnosing communication problems between devices. The ping command, available in practically all Linux distributions, allows sending ICMP Echo Request packets to a destination host and measuring the response time. This simple yet powerful tool provides valuable information about availability, latency, and possible packet loss on a network path.

What is ping?

Ping is a utility based on the ICMP (Internet Control Message Protocol). Its name comes from the sound submarines make when emitting a pulse and waiting for its echo. In networking terms, the source device sends an Echo Request message and waits to receive an Echo Reply from the destination. If the packet arrives and returns, connectivity is considered to exist; otherwise, an interruption in the path can be inferred.

How ICMP works

ICMP does not transport application data, but control and diagnostic messages. When ping is executed, the kernel builds an IP packet whose protocol field indicates ICMP, and inside it carries a type 8 (Echo Request) and a code 0. The remote host, upon receiving it, generates a packet of type 0 (Echo Reply) with the same identifier and sequence number, sending it back to the sender. The elapsed time between sending and receiving is measured and displayed to the user.

Basic syntax

The simplest form of the command is:

ping [options] destination

Where destination can be an IP address (e.g., 8.8.8.8) or a hostname resolvable via DNS (such as www.google.com). If no options are specified, ping sends packets of 56 bytes of data (plus 28 bytes of ICMP/IP header) at a one-second interval and continues indefinitely until the user stops it with Ctrl+C.

Useful options

  • -c count: limits the number of packets sent to count.
  • -i interval: sets the interval in seconds between each transmission (default 1 second).
  • -s size: adjusts the payload size in bytes (the total packet size will be size + 28).
  • -t ttl: sets the Time To Live value for outgoing packets.
  • -W timeout: defines the wait time in seconds for each response before considering it lost.

Practical examples

To check connectivity with Google’s public DNS server and send only four packets, you can use:

ping -c 4 8.8.8.8

If you wish to perform a continuous test with a half-second interval and a payload size of 100 bytes, the command would be:

ping -i 0.5 -s 100 www.example.com

In scenarios where you need to limit the wait time to 500 milliseconds per response, you add the option -W 0.5:

ping -c 3 -W 0.5 192.168.1.1

Interpretation of results

Each output line shows several fields: sequence number, received packet size, round-trip time (ms), and TTL. For example:

64 bytes from 8.8.8.8: icmp_seq=1 ttl=115 time=23.4 ms

A low time indicates low latency; a high time may reflect congestion or long routes. The appearance of messages such as Destination Host Unreachable or Request timeout for icmp_seq 2 indicates that no response was obtained, suggesting a routing problem, a firewall blocking ICMP, or the destination host being down.

Best practices and limitations

Although ping is excellent for an initial check, it does not guarantee that upper-layer services (HTTP, SSH, etc.) are operational. Some administrators disable ICMP in their firewalls for security reasons, causing ping to fail even though the host is reachable via other protocols. In those cases, tools such as telnet, nc, or curl are used to test specific ports. Additionally, it is recommended not to abuse ping with very large packets or very short intervals on production networks, as it can generate unnecessary traffic and be interpreted as a denial-of-service attack.

Conclusion

The ping command remains an indispensable tool in any Linux administrator’s toolkit. Its simplicity allows quickly obtaining information about a host’s reachability and latency, facilitating early detection of network problems. Knowing its options and knowing how to interpret its output makes ping an effective first step toward a deeper diagnosis when needed.

This post is also available in ESPAÑOL.

Leave a Reply

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

Esta obra está bajo una Licencia Creative Commons Atribución 4.0 Internacional para Francesc Roig francesc@vivaldi.net .