I just figured out, that ping
on a Linux platform (Ubuntu 13.10) does not timeout as described. I tried
ping -w 2 unreachable.com
and
ping -W 2 unreachable.com
but in neither case there was a timeout after 2 seconds. How can I use ping
with a definite timeout? Is that possible at all? I want the command to stop after 2 seconds, regardless of any connection status.
To stop the ping command in Linux, we should use Ctrl+C to stop sending packets to the target host. The command will stop all the processes in the terminal.
Timeout – changes the timeout before the utility waits for a reply from the destination. On Windows systems, the default value is 4,000 milliseconds, or 4 seconds. Size – changes the size of the ping packet. The default value on Windows is 32 bytes, many Unix/Linux systems default to 64 bytes.
The default interval between each ping request is set to one second. You can increase or decrease that time using the -i switch. To decrease the ping interval, use values lower than 1.
Some Basic Ping functions The default time interval between sending each packet is 1 second in Linux. You can increase the time interval by setting a value greater than 1 and decrease it by setting a value less than 1.
ping -c 5 -W 2
will send out 5 pings, waiting 2 seconds max for each of them (a total max of 10 seconds).
ping -w 5
will send out pings, but will stop after 5 seconds.
You have to be careful with name resolution: if you use a name instead of an IP address, the resolution of the name does not count into these timeouts & waits (pinging and time measurements start only after the name resolution has finished). If you use DNS, you can set DNS timeouts in /etc/resolv.conf
- see its man page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With