0

I want to try to use ping to detect if a server goes down. So the idea was to have something ping forever, and then if ping ever timed out( -W flag) it would return and I'd be able to detect it. But if I ping an unreachable address ping just seems to block forever, where i'd expect it to time out and return.

ping 1.1.1.1 -W 1 -v
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
^C
--- 1.1.1.1 ping statistics ---
10 packets transmitted, 0 received, 100% packet loss, time 9071ms

1 Answer 1

1

ping was not blocked, it just didn't showed you the failed transmissions while it was running.

Take a look at the statistics when you stopped it.

10 packets transmitted, 0 received, 100% packet loss, time 9071ms

You see packets were transmitted but not received. You ran it for ~10 seconds and it transmitted 10 packets and waited for 1 second for the timeout period you mentioned before sending the next packet.

If you want to visualize the failed transmissions you can use the -f option with a suitable ping interval using the option -i interval. The value of interval should be greater than 0.2 seconds. You can find more details of it the manual page of ping by running man ping.

ping -f -i .5 -W 1 1.1.1.1

Will produce an output like this.

PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
.......^C
--- 1.1.1.1 ping statistics ---
7 packets transmitted, 0 received, 100% packet loss, time 3048ms

Where each . represents a transmission without any reply and in case of a reply one backspace will be printed removing a ..

I think this is the kind of solution you are looking for. An automated script for periodically checking the connectivity.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .