Is Ping a reliable way to check if a server is available?
Solution 1:
The best way to tell if any given remote service is alive is to ask it to service a request in the way it's meant to - in fact it's the only way to truly know something is working correctly.
As an example I always get my load-balancers to get an actual 'head' response back from our web servers, you could do the same for a small select on a DB box if you wanted to, or whatever your actual server serves. As a tip you can create an 'online.txt' (or whatever name you want to give it) on your web servers, have your LBs try to get that file and if it fails then it removes the server from the VIP, this is a nice way of manually taking individual servers out of your VIPs simply by renaming a single file.
Ping only tests for the ability to respond to pings, so that's base OS, parts of the IP stack and the physical links - but that's all, everything else could be down and you'd not know.
I know this is mentioned below, but it bears repeating again and again.
ICMP Echo Requests (aka "Pings") (aka ICMP Type 8) are built onto the IP stack spec, yes, but are not required to be either implemented or used. As a matter of fact, there are a large number of internet providers who refuse to forward those and silently drop those requests, as they are a form of network attack (called a pingflood).
As mentioned above, this is handled by the OS (specifically at the network stack level) and so it is up to the OS configuration to respond to those or not. If this is turned off (a security precaution?), you can't do anything about receiving ping replies from the other end. This is why it's not reliable.
Solution 2:
Most of time, yes, however:
some servers block ping requests
just because the server is responding doesn't automatically mean the website (or whatever service you expect to use) is working, you should also check if the response matches the expected contents.
Solution 3:
It is true that on many occasions ICMP traffic is filtered out so it could be unreliable...
A better way perhaps could be to telnet the server at the service port you are interested in.
i.e. telnet 127.0.0.1 8080
Solution 4:
If the server is only required to respond to pings then this is a good method of determining it's availability. If is is required to provide for example a web service then you should carry out some form of test to see if that is working similarly for fileservices etc.
Solution 5:
ping has 2 drawbacks:
- ping sends icmp, that can be filtered by the firewall
- the tcp or udp port your application uses could be busy or not open - ping doesn't check that
a better solution is to check your udp/tcp port directly, to see if the service is still available... :-)