Red Hat Bugzilla – Bug 10263
ping exits with code 0 for unreachable hosts
Last modified: 2008-05-01 11:37:55 EDT
The ping man page states :
" If ping does not receive any reply packets at all it will exit with code
1. On error it exits with code 2. Otherwise it exits with code 0. This
makes it possible to use the exit code to see if a host is alive or not."
The current (RH 6.1) ping does not return a non-zero exit code for
unreachable hosts :
aqua:akonstan> rpm -qf /bin/ping
aqua:akonstan> /bin/ping -c 1 188.8.131.52
PING 184.108.40.206 (220.127.116.11) from 18.104.22.168 : 56(84) bytes of data.
From aqua.cs.columbia.edu (22.214.171.124): Destination Host Unreachable
--- 126.96.36.199 ping statistics ---
1 packets transmitted, 0 packets received, +1 errors, 100% packet loss
aqua:akonstan> echo $?
aqua:akonstan> uname -a
Linux aqua.cs.columbia.edu 2.2.12-20 #1 Mon Sep 27 10:40:35 EDT 1999 i686
This bug has been fixed in iputils version 000305.
Upgrade to the inetd/ping packages from Raw Hide, all known problems with ping
are fixed there. Note carefully that recent versions of Red Hat have changed
the "-c <packets>" to count received (not transmitted) packets, so you will
need to use "-w <secs>" if using ping to test reachability of hosts that may