Trying to understand ping

10

2

I'm programming a Reachability class that tests whether an IP Address is valid and available. I wrote a Unit Test to test if my class works fine or not and then it happened. I tested with IP Address 192.168.1.255 which I thought to be unreachable in my network but I got IsReachable = true. Huh... how is this possible?

Ok I've got a baseline. I can use the 'ping' application that comes with Windows. Here's the result of that test

# ping 192.168.1.255

Pinging 192.168.1.255 with 32 bytes of data:
Reply from 192.168.1.200: bytes=32 time<1ms TTL=64
Reply from 192.168.1.200: bytes=32 time<1ms TTL=64
Reply from 192.168.1.200: bytes=32 time<1ms TTL=64
Reply from 192.168.1.200: bytes=32 time=1ms TTL=64

Ping statistics for 192.168.1.255:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms

It gets even weirder

# ping 192.168.1.253

Pinging 192.168.1.253 with 32 bytes of data:
Reply from 192.168.1.27: Destination host unreachable.
Reply from 192.168.1.25: Destination host unreachable.
Reply from 137.224.244.1: Destination net unreachable.
Reply from 137.224.244.1: Destination net unreachable.

Ping statistics for 192.168.1.253:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

What is going on here? Can someone explain to me what this result means?

EDIT ADDED IPCONFIG

ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : DESKTOP-CB16LLI
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : wurnet.nl
                                       home

Ethernet adapter Ethernet 3:

   Connection-specific DNS Suffix  . : wurnet.nl
   Description . . . . . . . . . . . : NCP Secure Client Virtual NDIS6 Adapter
   Physical Address. . . . . . . . . : 02-00-AD-4F-70-18
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 137.224.245.97(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : vrijdag 30 maart 2018 08:20:26
   Lease Expires . . . . . . . . . . : donderdag 17 mei 2018 21:25:51
   Default Gateway . . . . . . . . . :
   DHCP Server . . . . . . . . . . . : 137.224.245.98
   DNS Servers . . . . . . . . . . . : 10.90.3.31
                                       10.91.3.31
   NetBIOS over Tcpip. . . . . . . . : Enabled

Ethernet adapter Ethernet 1:

   Connection-specific DNS Suffix  . : home
   Description . . . . . . . . . . . : Surface Ethernet Adapter
   Physical Address. . . . . . . . . : C4-9D-ED-E8-5D-1E
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   IPv4 Address. . . . . . . . . . . : 192.168.1.27(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : vrijdag 30 maart 2018 08:12:39
   Lease Expires . . . . . . . . . . : zaterdag 31 maart 2018 08:12:50
   Default Gateway . . . . . . . . . : 192.168.1.254
   DHCP Server . . . . . . . . . . . : 192.168.1.254
   DNS Servers . . . . . . . . . . . : 192.168.1.254
   NetBIOS over Tcpip. . . . . . . . : Enabled

Wireless LAN adapter Local Area Connection* 1:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter
   Physical Address. . . . . . . . . : BE-83-85-E7-C5-48
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Bluetooth Device (Personal Area Network)
   Physical Address. . . . . . . . . : BC-83-85-E7-C4-4A
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . : home
   Description . . . . . . . . . . . : Marvell AVASTAR Wireless-AC Network Controller
   Physical Address. . . . . . . . . : BC-83-85-E7-C4-49
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::49ca:6fd:8fa4:a099%3(Preferred)
   IPv4 Address. . . . . . . . . . . : 192.168.1.25(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : vrijdag 30 maart 2018 08:12:49
   Lease Expires . . . . . . . . . . : zaterdag 31 maart 2018 08:13:08
   Default Gateway . . . . . . . . . : 192.168.1.254
   DHCP Server . . . . . . . . . . . : 192.168.1.254
   DHCPv6 IAID . . . . . . . . . . . : 79463301
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-22-4C-14-89-C4-9D-ED-E8-5D-1E
   DNS Servers . . . . . . . . . . . : fe80::2aff:3eff:fe3d:f5%3
                                       192.168.1.254
   NetBIOS over Tcpip. . . . . . . . : Enabled

Tunnel adapter Local Area Connection* 11:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Teredo Tunneling Adapter
   Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes

EDIT Above pings were with VPN connection open. Below are with VPN connection closed

ping 192.168.1.253

Pinging 192.168.1.253 with 32 bytes of data:
Reply from 192.168.1.27: Destination host unreachable.
Reply from 192.168.1.27: Destination host unreachable.
Reply from 192.168.1.27: Destination host unreachable.
Reply from 192.168.1.27: Destination host unreachable.

Paul Sinnema

Posted 2018-03-30T08:58:11.083

Reputation: 213

Note that you have two interfaces (Ethernet 1 and Wi-Fi) on the same network, which is usually a good way to get into lots of weird issues. I recommend you only connect to on at a time. – jcaron – 2018-03-30T16:13:19.053

1@jcaron I believe it is much bettern to teach the OP how to handle multiple interfaces. The class should teach him something right? You cannot go to a server rack and turn down all interfaces except one for testing reachability... considering that you might log in from one and need to test a different one; or if you have virtual interfaces (e.g. some docker container etc), they can bite sometimes. So your "fix" only works in trivial situations where reachability testing is not really an issue. – Bakuriu – 2018-03-30T18:07:38.123

It’s hard to answer definitively without seeing your routing table, especially since you have two adapters on the same subnet. – Ex Umbris – 2018-03-30T18:37:46.903

Answers

10

0 and 255 are not valid addresses to have machine at on a 255.255.255.0 subnet network.

255 is the "broadcast" address an 0 is the "network address.

Related reading Why can't IP addresses start with 0 or 255?. The answer addresses the broad case of the wide IP addresses, but the rule apply to subnetted addresses as well so for a 255.255.255.0 subnet the first and last IPs are reserved.


Regarding the pinging of .253... in your first ping it is essentially asking every network adaptor it has if it has a route to the host.

In two of the cases they have replied Destination host unreachable. which is essentially saying "if it was here then we'd let you know, but it is unreachable for some reason"

The weirder one is the VPN network gateway which instead says Destination net unreachable. in this case it is saying that due to subnetting and other factors is has absolutely no way it can talk to any machine over on that network.

Your final ping looks like what I would expect to see. Your local network adaptor is just telling you the address is unreachable.

Mokubai

Posted 2018-03-30T08:58:11.083

Reputation: 64 434

Ok, thanks. Didn't know that. As 'wigy' said any host can reply and even lie to the caller. Is that what is happening with the 253 in the address? – Paul Sinnema – 2018-03-30T09:10:54.030

Do you have multiple network interfaces in that machine? Even virtual ones? Ping can query all the gateways he machine knows and is getting unreachable replies. – Mokubai – 2018-03-30T09:13:24.720

Added ipconfig /all output. 1 Address is close but does not quite match (137.224.245.97) – Paul Sinnema – 2018-03-30T09:17:38.197

The other 2 192.168.1.25 and 27 are definitely reachable on port 80 in my network (IIS) – Paul Sinnema – 2018-03-30T09:20:12.843

Obviously the weirdest reply is from 137.224.244.1 that I can only attribute to a misconfigured gateway that let the 192.168.x.x packet out onto the WAN. – wigy – 2018-03-30T09:20:49.730

I think I confused myself here. I have a VPN connection open at the moment so I'm on the corporate network. That could explain the weirdness I guess. I'll do the same test again without the VPN connection. – Paul Sinnema – 2018-03-30T09:23:29.660

That the only explanation I can see too. The .25 and .27 are your local wifi and ethernet network adaptors responding that they have no path to the destination. I'm not sure why ping would be going to the third gateway. – Mokubai – 2018-03-30T09:24:00.497

That seems more sensible. Your local adaptor is basically announcing that it cannot find a route to .253 – Mokubai – 2018-03-30T09:26:39.927

Added new ping results to question. Formatting was bad in the comment. – Paul Sinnema – 2018-03-30T09:27:55.493

Added comparison of the reply IPAddress with the original IPAddress that is still not complete I guess. I could receive multiple replies or should I accept 'first one wins'? – Paul Sinnema – 2018-03-30T09:48:21.247

No first one wins does not solve the problem. Hmmm it's more complex than I thought. Back to the drawingboards. Thanks for clarifying things. – Paul Sinnema – 2018-03-30T09:49:41.447

Just to clarify for the OP, x.y.z.0 and x.y.z.255 are not invalid in general – you must not reject them blindly, without knowing the subnet mask. – user1686 – 2018-03-30T15:28:29.217

1

The ICMP protocol works directly on top of IPv4 (in this case). It has different routing rules than unicast UDP or TCP has. Basically any host that has seen the ICMP packet can answer (and even lie).

So it is not just the replies by the destination that you see in the received packet count.

wigy

Posted 2018-03-30T08:58:11.083

Reputation: 375

Ok, ICMP is kind of a broadcast that all hosts can see? So when I want to be sure I should check the reply and compare IP Addresses? – Paul Sinnema – 2018-03-30T09:06:16.667

The address 192.168.1.255 was indeed a broadcast to all machines behind your router. All 0s and all 1s in a subnet are special and their handling is defined in the IPv4 protocol. This case all hosts feel addressed. – wigy – 2018-03-30T09:10:55.483

1@PaulSinnema: ICMP is not a broadcast, but the address you used is (that's why it's not a valid address for individual devices to have). This answer kind of muddles the two concepts. – Lightness Races with Monica – 2018-03-30T14:16:20.347

There are no "different routing rules". TCP isn't allowed to use broadcast addresses (it doesn't make sense, since it needs to establish point-to-point connections), but UDP certainly is. – Barmar – 2018-03-30T19:19:12.410