Linux ping Command

Linux ping Command

When a website won’t load or a server stops answering, the first thing to check is whether your computer can reach that machine at all. The ping command checks that by sending small test messages and timing the replies.

I’ll show you how to run ping, read what it prints, and what a reply does and doesn’t tell you.

What ping measures

Linux ping sends Internet Control Message Protocol (ICMP) echo requests to a destination and waits for echo replies. The replies include round-trip time (RTT), the time between sending a request and receiving its response.

An echo reply confirms that an ICMP exchange completed for that probe. It does not confirm that a website, SSH server, or another application is accepting connections, because those use different protocols and can have separate filtering rules.

Ping resultWhat it tells you
Echo replyAn ICMP response returned for that request.
Packet lossSome requests did not receive replies during this sample.
RTTElapsed time for each request and reply, not a general score for the connection.

What you need before running ping

  • A Linux terminal with the ping command installed.
  • A destination written as a hostname or an IP address.

The required permissions depend on how your distribution configures ping.

Step 1: Send a bounded ping

Use the count option to send a fixed number of requests, so the command returns without waiting for Ctrl+C.

ping -c 4 127.0.0.1
Linux ping command replies to four bounded probes
A finite ping run receives four replies and reports zero packet loss.

I ran the finite check against loopback, and every request returned a reply. This local baseline does not rely on DNS or a remote host.

A hostname works in place of the address when name resolution succeeds. The hostname capture below shows ping resolving a name and continuing until Ctrl+C because no count was set.

Ping Hostname Example
Ping Hostname Example

Press Ctrl+C to stop an ongoing run. For a name-resolution problem, compare the result with the steps in the Linux DNS guide.

Step 2: Read replies and packet statistics

Each reply line reports the responding address, an ICMP sequence number, a time-to-live value, and an RTT measurement. The summary then compares transmitted requests with received replies.

FieldHow to read it
icmp_seqSequence number for a request and its matching reply.
ttlRemaining IP time-to-live value shown on the reply. It is not an exact hop count.
packet lossPercentage of sent requests with no reply in this probe set.
min/avg/max/mdevMinimum, average, maximum, and variation in measured RTT values.

A four-request check against a public hostname can return a different address and RTT from this local example. The count screenshot below shows the finite-run summary for a hostname, while its DNS answer and timings are specific to that capture.

Ping Count Example
Ping Count Example

Use the Linux IP address guide when you need to compare the responding address with an address assigned to a local interface.

Step 3: Set the interval and deadline

Choose an option based on what you need to bound. The iputils manual distinguishes an overall deadline from the wait for an individual reply.

OptionEffect
-c countStop after the specified number of requests.
-i intervalSet the time between requests.
-w deadlineStop the whole run when its deadline expires.
-W timeoutSet how long to wait for a reply.
-s sizeSet the ICMP data payload size in bytes.
Address familyChoose -4 for IPv4 or -6 for IPv6.
ping -i 5 -c 3 127.0.0.1
ping -w 2 -c 5 127.0.0.1
ping -c 1 -s 100 127.0.0.1
ping -4 -c 1 127.0.0.1
ping -6 -c 1 ::1

When count and deadline are combined, iputils returns status 1 if the deadline arrives before enough replies arrive. Read the summary too, because that status can accompany replies that did arrive.

The interval capture shows the five-second interval applied to each request. The deadline capture uses the whole-run limit, while the payload example changes ICMP data size rather than the destination.

I set a five-second interval and count of three against loopback. The measured 10178ms run returned three replies.

Ping Interval Example
Ping Interval Example

The interval screenshot uses an unbounded command and ends when Ctrl+C is pressed. The deadline screenshot shows a separate way to end a run after a time limit.

Ping Timeout Example
Ping Timeout Example

For IPv6 link-local destinations, the iputils manual notes that an interface may also be needed. Its ping manual documents the available options and their implementation details.

When ping gets no reply

A missing reply means no ICMP echo reply reached ping during that sample. It does not identify whether the destination is offline, the route is broken, or a firewall or host policy is filtering ICMP.

Linux ping reports no ICMP echo replies
The test address 192.0.2.1 is reserved for documentation, so this capture shows a no-reply state rather than a check of your network.

I used the TEST-NET-1 documentation address 192.0.2.1 for a no-reply example, and ping reported 100% packet loss. RFC 5737 reserves that address block for documentation.

  • If a hostname fails, check name resolution separately from ICMP replies.
  • If an address fails, inspect the local route and interface configuration before changing network settings. The Linux network configuration guide explains those settings.
  • If you need to inspect intermediate network hops, use a route-tracing tool such as the Linux traceroute command.

Ping does not test whether a TCP or UDP port is open. A browser or service-client check answers that separate application question, so do not infer service health from a single lost echo.

After correcting an Ubuntu network configuration, use the Ubuntu guide to restart networking only when the change requires it.

A ping reply answers one narrow question

Use ping to ask whether ICMP echo replies return under the conditions of that probe. When they do not, check the route with the network configuration guide before treating the result as proof that an application is down.

ip route get 192.0.2.1

The route lookup asks Linux which path it would use for that destination. For a hostname problem, compare the route check with the DNS steps above. For a service problem, test that service with its own protocol.

Linux ping command FAQ

What does the ping command do in Linux?

Linux ping sends ICMP echo requests to a destination and reports received replies, packet loss, and round-trip time.

How do I stop a continuous ping in Linux?

Use Ctrl+C to stop an ongoing run, or pass -c followed by a count to make ping stop after a fixed number of requests.

Does ping check whether a port is open?

No. Ping tests ICMP echo replies, not whether a TCP or UDP service port accepts connections.

What does 100% packet loss mean in ping?

No echo replies arrived during that sample. The result alone does not show whether the destination is offline, the route failed, or ICMP replies were filtered.

What is the difference between ping -w and ping -W?

In iputils, -w sets a deadline for the whole run, while -W sets how long to wait for a reply. Check the ping manual for the installed implementation.