InetAddress.isReachable() returns false for hosts that respond to ping — inconsistent results across Linux and Windows
0 reputation · 15 Jun 2020, 09:49 UTC
Reachability check disagrees with system ping
I am building a lightweight host-monitoring component in Java that uses InetAddress.getByName(host).isReachable(timeout) to decide whether to raise an alert. The goal is a single boolean signal that works the same way on Linux servers and Windows workstations, without spawning external ping processes.
The documented behavior is that the method may use ICMP echo where permitted and fall back to a TCP connection on the echo port (port 7) on some platforms, which means the result depends on OS, firewall rules, and runtime privileges rather than on a single guaranteed mechanism. The default timeout of 3000 ms is also a concern on higher-latency links, where a slow but healthy host could be flagged as down.
Assume a recent LTS JDK (17 or 21) and standard outbound firewall rules.
Open questions
- Under what documented conditions does
isReachable()returnfalseeven when the target host answers a system-level ping? - Is there any supported way to control which mechanism (ICMP vs. TCP) the JDK uses, or is that entirely implementation-defined per platform?
- How should the timeout be sized so alerts stay timely without producing false negatives on WAN links?