Skip to content
Linux ping Mastery: Troubleshoot Network Issues Beyond Simple Connectivity
Operations 12 min read

Linux ping Mastery: Troubleshoot Network Issues Beyond Simple Connectivity

This guide explains how the Linux ping command works via ICMP, interprets key output fields like RTT and packet loss, covers essential options for scripting and IPv4/IPv6 testing, and provides a step-by-step troubleshooting workflow from local loopback to gateway, DNS, and HTTP service validation, including MTU discovery and intermittent latency analysis.

Linux Tech Enthusiast
Linux Tech Enthusiast
Linux Tech Enthusiast

What a Single Round Trip Actually Tests

ping

sends an ICMP Echo Request to the target address. If the target responds, it returns an ICMP Echo Reply. The time between sending the request and receiving the reply is the round-trip time (RTT). IPv4 uses ICMP; IPv6 uses ICMPv6. One RTT includes both the forward and return paths, which may follow different routes.

Local host sends ICMP Echo Request to target; target replies with Echo Reply. RTT is the time from request sent to reply received.
Local host sends ICMP Echo Request to target; target replies with Echo Reply. RTT is the time from request sent to reply received.

Receiving a reply only confirms that this ICMP probe can make the round trip. Browser HTTPS access additionally requires a TCP connection, TLS handshake, and HTTP response; a failure can occur at any of those steps.

The command accepts only an IP address or domain name. Given a URL like https://example.com/news, ping tests only example.com. To see what the /news path returns, use curl with the full URL.

Start with Four Packets and Read the Output

Practice on the loopback address 127.0.0.1 (works offline). The examples below use the common iputils implementation. Run ping -c 4 127.0.0.1 to send four probes and stop; press Ctrl+C to stop early and view statistics.

ping -c 4 127.0.0.1
Loopback ping example. First reply shows icmp_seq=1, TTL=64, RTT=0.036 ms. Sent 4, received 4, 0% loss, avg RTT 0.037 ms, mdev 0.004 ms.
Loopback ping example. First reply shows icmp_seq=1, TTL=64, RTT=0.036 ms. Sent 4, received 4, 0% loss, avg RTT 0.037 ms, mdev 0.004 ms.

icmp_seq is the sequence number; time is the single RTT. If the sequence jumps from 2 to 4, check whether the third reply arrives late, then consult the final packet-loss summary. ttl is the remaining TTL on the IPv4 reply; to infer the return hop count you must know the initial TTL the responder used.

packet loss shows how many requests received no reply. Sending 4 and receiving 3 yields 25% loss. With only 4 samples, occasional hiccups can skew the result; increase the count for more stability. The final line min/avg/max/mdev reports minimum, average, maximum RTT and standard deviation. When averages are similar, use max to spot spikes and mdev to gauge jitter. For example, two runs averaging ~20 ms but one showing a 200 ms spike: correlate that spike with the time of a video-conference stall.

Lowercase -w vs Uppercase -W : Two Different Timeouts

ping -c 4 -W 2 -w 6 127.0.0.1

With only -c 4, ping stops after sending four requests. Adding -w 6 sets a 6-second overall deadline for the probing phase; it can finish early if all four replies arrive. -W 2 sets the per-probe timeout (seconds) when no reply has been received at all; once replies start arriving, iputils dynamically adjusts the wait based on measured RTT.

For scripting, check the exit code: 1 means no replies received (or, when both -c and -w are used, the required count wasn't met by the deadline); 2 indicates other runtime errors. Use -4 and -6 to force IPv4 or IPv6 on dual-stack hosts. Add -n to skip reverse DNS lookups and show numeric addresses only; note that the system still resolves the hostname to an IP before sending probes.

Troubleshooting Workflow: Localhost → Gateway → Target → Service

First, verify localhost to gateway. 127.0.0.1 only tests the local loopback. Find the default gateway with ip -4 route show default and ping the address after via. If the gateway normally replies but suddenly doesn't, check the NIC, Wi-Fi or cable, and whether the gateway is online.

ip -4 route show default
ping -c 4 192.168.1.1

Next, check the target and DNS resolution. Replace example.com with the domain under investigation. If the target IPv4 is known, ping the IP first, then the domain. If the IP works but the domain fails resolution, use getent ahostsv4 example.com to see whether the local resolver can produce an IPv4 address, then verify the domain spelling or local DNS configuration.

getent ahostsv4 example.com
ping -4 -c 4 -w 6 example.com

Finally, test the actual service. Use curl to request the specific URL and observe connection, TLS, and HTTP response. Receiving a 403 or 502 means an HTTP response arrived; investigate permissions or the backend service. To compare with the IPv4 ping, add -4 to curl as well.

curl -v --max-time 8 -o /dev/null https://example.com/

If the failure appears only inside a container, run the same checks from within the container. With VPNs or multiple NICs, run ip route get <target> and examine the dev and src fields to confirm which interface and source address the kernel selected.

Handling Unreachable, 100% Loss, and Intermittent Stalls

Seeing Destination Host Unreachable: look at the From field to identify which hop generated the error. If the error originates from the local host and the target is on the same subnet, run ip neigh to inspect neighbor (ARP) state. If traffic must traverse a gateway, check the gateway's neighbor state instead.

Seeing only 100% packet loss means no Echo Replies were received this round. Causes include path failure, firewall filtering, or rate limiting on the target. If the website still loads, examine the business request's status code and latency directly.

For occasional stalls, add timestamps to the output. Replace the example address with the actual gateway or target IP. The -O flag reports outstanding (unanswered) probes before sending the next one; late replies may appear afterward. Correlate the timestamps with application logs, and run parallel tests against the gateway and the target to narrow the fault domain.

ping -D -O -c 30 192.168.1.1

Small Packets Work, Large Packets Stall: MTU Discovery

If small requests succeed over a VPN but large file transfers hang, test the maximum packet size that traverses the path. Use an IPv4 target on the same path that replies to ICMP. Start with the default size, then try a large packet.

ping -4 -c 3 -M do -s 1472 192.0.2.10
-M do

sets the Don't Fragment bit; -s 1472 specifies 1472 bytes of payload. Together with the 8-byte ICMP header and typical 20-byte IPv4 header, the total is 1500 bytes (standard Ethernet MTU). If the command reports "packet too large", reduce -s and retest, then check the VPN or link MTU settings. If large packets simply produce no reply, combine with business logs or other tests to determine the cause.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

network troubleshootingpingcurlMTUDNS resolutionLinux commandsICMPRTT
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.