Console9

How to test network connectivity with ping

Verify whether a remote host is reachable over the network by sending ICMP echo requests with the ping command on Linux, macOS, and Windows.

Send ICMP echo requests to a remote host to verify network reachability, measure round-trip latency, and detect packet loss using the ping command on Linux, macOS, and Windows.

Prerequisites

  • Linux, macOS, or Windows (ping is preinstalled on all three operating systems)
  • Terminal or Command Prompt access
  • The hostname or IP address of the remote host to test

Step-by-Step: Test Network Connectivity with ping

1. Send ICMP Echo Requests to a Host with ping

The ping command sends Internet Control Message Protocol (ICMP) echo request packets to the target host and waits for echo reply packets. Run ping with the target hostname or IP address:

ping example.com

The ping command displays each reply with the round-trip time (RTT) in milliseconds, the TTL (Time to Live) value, and the packet sequence number:

PING example.com (93.184.216.34): 56 data bytes
64 bytes from 93.184.216.34: icmp_seq=0 ttl=56 time=11.4 ms
64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=11.2 ms
64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=11.3 ms

On Linux and macOS, the ping command runs continuously until stopped with Ctrl+C. On Windows, the ping command sends four packets and stops automatically.

2. Limit the Number of Ping Packets

The ping command accepts the -c flag (Linux/macOS) or -n flag (Windows) to send a specific number of ICMP echo requests and then stop:

=== "Linux / macOS"

```bash
ping -c 5 example.com
```

=== "Windows"

```cmd
ping -n 5 example.com
```

The ping command sends exactly 5 packets and then prints a summary showing packet loss percentage and round-trip time statistics (minimum, average, maximum, and standard deviation).

3. Test Connectivity to an IP Address with ping

The ping command accepts an IP address instead of a hostname to bypass DNS resolution entirely. Use an IP address to isolate network connectivity issues from DNS resolution failures:

ping -c 3 8.8.8.8

If ping succeeds with an IP address but fails with a hostname, the problem is DNS resolution — not network connectivity. Use the host commandor the dig commandto diagnose DNS issues.

How to Verify Network Connectivity Was Confirmed with ping

The ping command prints a summary after completing the requested number of packets. A successful connectivity test shows 0% packet loss:

--- example.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 11.2/11.3/11.4/0.1 ms

A result of 0% packet loss confirms the remote host is reachable and responding to ICMP traffic. Any packet loss above 0% indicates network instability, congestion, or ICMP filtering between the source and destination.

Common Issues When Testing Connectivity with ping

ping shows "Destination Host Unreachable"— The ping command received an ICMP "Destination Unreachable" message from a router along the path. The target host may be offline, or a routing issue prevents packets from reaching it. See ping: Destination Host Unreachablefor diagnosis steps.

ping shows "Request timed out" or 100% packet loss— The target host does not respond to ICMP echo requests. Many firewalls and cloud security groups block ICMP traffic by default. The host may be reachable on TCP ports (HTTP, SSH) while ignoring ping entirely. Test TCP connectivity with curl or telnet to confirm.

ping resolves to the wrong IP address— The ping command relies on DNS resolution before sending packets. If the domain resolves to an incorrect IP, the ping test reaches the wrong host. Verify DNS resolution separately using host example.com or dig example.com before interpreting ping results.

ping latency is very high— Round-trip times above 200 ms for a host on the same continent indicate network congestion, routing inefficiency, or a saturated link. Use the traceroute commandto identify which network hop introduces the latency.