Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "is not reachable" and "unknown host"

Tags:

java

url

ping

I've a small java code which test a bunch of hosts which is not reachable.
The important part is this:

for (String host : hosts) {
    try {
        if (!InetAddress.getByName(host).isReachable(5000)) {
            System.err.println(host + " is not reachable!");
        }
    } catch (UnknownHostException e) {
        System.err.println(host + " is unknown");
    } catch (IOException e) {
        System.err.println(host + "throws IOException!");
    }
}

hosts is a String[]-Array full of URL's to test. When I run it, some URL's comes "... is not reachable!" and sometimes it comes "... is unknown".

But what is the difference between these two?
Not reachable -> No answer after 5sec to the ping
Unknown -> No host found to ping

These are only my thoughts and I can't find any confirmations or improvements in google.

like image 570
Michael Schmidt Avatar asked Sep 13 '13 09:09

Michael Schmidt


2 Answers

Unknown host means that it couldn't resolve a DNS entry, so it doesn't know what IP address to contact.

Not reachable means that it had an IP and tried to contact it but failed (either because of a timeout or because it received a destination unreachable message).

like image 160
chrylis -cautiouslyoptimistic- Avatar answered Oct 08 '22 05:10

chrylis -cautiouslyoptimistic-


Unknown host - Not enough information is available to contact a host / it does't know which host to contact
Unreachable - Enough information is available to contact the host but contact is not happening due to some reason (network error, timeout-host didn't respond on time, privilege issue etc.)

like image 42
Aneesh Avatar answered Oct 08 '22 06:10

Aneesh