Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does `ping` not timeout in Linux? [closed]

Tags:

linux

ping

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.

like image 371
Alex Avatar asked Dec 03 '13 19:12

Alex


People also ask

How do I stop a continuous ping on Linux?

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.

How long does ping take to timeout?

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.

How long does ping run for Linux?

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.

What is default ping timeout in Linux?

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.


1 Answers

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.

like image 54
Laszlo Valko Avatar answered Sep 19 '22 16:09

Laszlo Valko