ping: Usage, Options & Common CI Errors
ping checks whether a host is reachable by sending ICMP echo requests.
ping is the first reachability check, but in CI it is unreliable as a gate: it needs -c so it does not run forever, and many container networks and cloud firewalls drop ICMP even when TCP works fine.
What it does
ping sends ICMP echo-request packets to a host and reports replies and round-trip time. By default it loops forever, so CI must bound it with -c (count) and -W (timeout) to use it as a non-interactive check.
Common usage
ping -c 4 example.com # send 4 packets then exit
ping -c 1 -W 2 10.0.0.5 # one packet, 2s timeout (quick gate)
ping -c 3 -i 0.2 host # 0.2s interval
ping -4 example.com # force IPv4
ping -c 1 host >/dev/null 2>&1 && echo reachableOptions
| Flag | What it does |
|---|---|
| -c <N> | Stop after N packets (required in scripts) |
| -W <secs> | Per-reply timeout |
| -i <secs> | Interval between packets |
| -4 / -6 | Force IPv4 / IPv6 |
| -w <secs> | Overall deadline regardless of replies |
Common errors in CI
Without -c, ping never exits and hangs the job until timeout - always pass -c. "ping: socket: Operation not permitted" appears in unprivileged containers without CAP_NET_RAW or a permissive net.ipv4.ping_group_range; ping is not a good readiness probe there - use TCP (nc -z or curl). Crucially, 100% packet loss does NOT mean the service is down: many networks block ICMP while allowing TCP/HTTP, so a failing ping with a working curl is normal. "Name or service not known" is a DNS failure, not a reachability failure.