When we are using windows ping , it will show the failed pings. Does Ubuntu have similar function?
The failed ping is quite useful when debugging the network. How you guys solve this? Well, I only want simple solution, I don't want to get a long script.
When Windows' ping says "Request timed out.", it is not an error per se. Microsoft arbitrarily chose a timeout of 4 seconds, after which they assume "failure" and report it. If you were to ping anything from Mars, that's a guaranteed false alarm, but even on Earth RTT (round-trip time) over 4s is perfectly possible. The timeout is configurable with a
/w <millisec>
switch.On Linux, ping utility does not assume that timeout is a failure and doesn't wait for reply. Normally, it prints all received replies immediately and as-is, including "late" ones, out-of-order ones, duplicates and and conflicting responses (e.g. a valid reply after "Destination unreachable").
Having said that, there usually are options to see when a reply isn't received for too long. Even on my Android phone, stock ping utility supports these 2 options:
-D
prints a timestamp before every message, makes gaps easier to spot.-O
prints a message when reply is not received before sending next ping, and this is more or less what was asked. The "timeout" is fixed to ping interval (-i
), though.However, these options do not seem to be supported everywhere (e.g. Debian Wheezy lacks them as far as I know, while Jessie has them.
busybox ping
does not support them yet).Here is an example output I managed to get (unimportant ping replies skipped):
Note how #130 is first reported "missing", then received after #131, and finally packet loss is reported to be zero. Windows' ping would never give such a result: it waits until a reply or a timeout and only then sends next ping, ignoring any late or non-first replies.
Going partially off the answer by EvgEnZh, but with my own version:
That makes it print a message when a reply takes too long or never comes back (
-O
) and suppresses messages for when they do come back (-q
). The result is that you only get output when packets go missing. This can make finding intermittent problems much easier by making it so you don't have to sift through a pile of "it worked" messages for the few places it broke.Maybe
ping -f
is suitable for you. From ping manual:For 1 echo_request every second it would look like
ping -i 1 -f 8.8.8.8
This is apparently no longer the case. Just a year after you posted this, iputils/ping broke so now it is entirely possible that nothing gets printed.
https://github.com/iputils/iputils/issues/320
Even with the -v option, ping don't do that. See this question. But if this is really important (or fun) for you, you can download the source, modify the code to include a suitable printf call. A good place to to that would be at the end of method 'send_probe' (line 619 on 12.10)...
First you get the source
Make edits
Build, and install generated package...
Thanks for all the answers. It seems like the latest ubuntu ping can show the ping failed.
Thanks again.