How can ping know if my host is out of service?

The differences between the answers are not really determined by the ICMP itself, but indirectly.

ICMP can distinguish between the following:

        0 = unreachable network;

1 = unreachable host;

2 = unreachable protocol;

3 = unreachable port;

4 = necessary fragmentation and set of DF;

5 = the origin route failed.

But it does it with other network resources. Codes 0, 1, 4 and 5 can be received from a gateway. Codes 2 and 3 can be received from a host.

If, according to the information in the routing tables of the gateway, the destination network is unreachable (for example, the distance to the network is infinite), the gateway can send a destination message not accessible to the host of the Internet source of the datagram. Also, in some networks, the gateway can determine if the Internet destination host can not be accessed. It is the gateways in these networks that can send destination unreachable messages to the originating host when the destination host is not available, so ICMP does not actually make the determinations.

In the case that on the destination host, the IP module can not deliver the datagram because the indicated protocol module or process port are not active, then the destination host can send a message of "inaccessible destination" to the origin host.

Finally, if a datagram must be fragmented to be forwarded by a gateway but the "Do not fragment" flag is enabled, the gateway will discard the datagram and return a "destination unreachable" message.

Now, unlike the 2 separate cases: the waiting time out of request means that echo response messages were not received within the established time. This can be due to many different causes: ARP request failure, network congestion, packet filtering, routing error or even silent discard.

When you receive a response from [IP address]: & # 39; Host inaccessible destination & # 39 ;, then the problem occurred on / after a remote router, whose address is indicated by the [IP address]. So it's a router that tells you there's a problem between it and the destination address.