The ping command in Linux

ping sends ICMP echo requests to a host and reports each reply with its round-trip time. It is the first question of all network debugging — "can I reach it at all?" — and its output encodes reachability, latency, jitter and packet loss in a form every engineer learns to read at a glance.

How ping works

ping speaks ICMP, the control protocol that lives beside TCP and UDP: it sends an echo-request packet carrying a sequence number and a timestamp, and the target's kernel — not any application — answers with an echo-reply. The round-trip time is computed from the embedded timestamp, and gaps in the sequence numbers are how ping detects loss. Because ICMP requires raw sockets, ping is granted special capabilities at install time; it is one of the few unprivileged commands allowed to craft packets.

Two fields turn ping into a measuring instrument. TTL (time-to-live) is decremented by every router; the value in replies hints at hop count, and a TTL that changes between replies betrays route flapping. Payload size (-s) probes MTU problems: if 1400-byte pings pass and 1500-byte pings vanish, something on the path fragments badly — the classic diagnosis for "SSH works but transfers stall".

Syntax

ping [OPTIONS] HOST

Common options

OptionWhat it does
-c NSend N packets and stop (otherwise ping runs until Ctrl+C).
-i SECInterval between packets (default 1 second).
-W SECTimeout waiting for each reply.
-s SIZEPayload size in bytes — for testing MTU issues.
-4 / -6Force IPv4 or IPv6.
-qQuiet: only the summary line.

How to use ping: examples

$ ping -c 4 google.com

Four probes and a summary: reachability, min/avg/max latency and loss.

$ ping -c 1 -W 2 10.0.0.5 && echo up || echo down

A one-shot liveness test with a 2-second timeout — the building block of countless monitoring scripts.

$ ping -c 100 -i 0.2 server | tail -2

A quick loss/jitter measurement: 100 fast probes, read only the statistics.

$ ping -6 example.com

Verify IPv6 connectivity specifically.

Real-world use cases for ping

Bisecting an outage

The site is down: ping the server's IP, then the gateway, then 8.8.8.8, then a domain name. The first failure locates the layer — machine, LAN, internet or DNS — in under a minute, and determines who you call.

Watching a reboot come back

ping server in one terminal while the machine restarts: replies stop, then resume the moment the network stack is up. The cheapest possible "is it back yet?" indicator during maintenance windows.

Pro tips and common mistakes

Frequently asked questions about ping

ping works by IP but not by name — what does that mean?

Routing is fine; DNS resolution is broken. Check /etc/resolv.conf and test the resolver directly with dig.

What is a good ping time?

Same LAN: under 1 ms. Same country: 5–30 ms. Cross-continent: 80–200 ms. Consistency matters as much as the average — variance (jitter) is what breaks calls and games.

Why does a host not answer ping but serve web pages?

Many firewalls drop ICMP while allowing TCP. No ping reply proves little; a TCP check (curl, nc) is the more honest liveness test for services.

Related commands

curl

Download files, test APIs, send POST requests with JSON, and inspect headers.

ip

The modern tool for addresses, links and routes — replacing ifconfig and route.

dig

Ask DNS questions directly: A, MX, TXT records, and which server answered.

Want to build real fluency? The interactive course takes you through ping and every other essential command with guided, checked exercises.