Why Can Two Hosts with the Same Subnet Address in LAN Be Pinged?

ipv4protocol-theorytcp

In Subnet Addressing of TCP/IP Illustrated, Vol. 1: The Protocols, there is description:
This makes sense because class A and class B addresses have too many bits allocated for the host ID: 16384 - 2 and 65536 - 2, respectively., I think this is the reason of Subnet Addressing, but I don't know where to find the protocol, which describe the any two hosts can communicate each other only if they have the same network id and subnet id? This is relative to Ethernet? but I did not find the description about it. I know there must be something I missed!

For example,
enter image description here

Here, the gateway has 1.4, aix has 1.92, solaris has 1.32, and above thick line, there is 1.0
I don't know whether I can summary my question, Why in LAN, if the first host want ping the second host, the first one is 140.252.1.4, then the second one must be 140.252.1.x?

For making my question clear, I make a test that I connected my mac and Fedora linux directly by cable, then:

Under mac:

 ~ » sudo ifconfig en0 192.168.90.104                          

Under Fedora Linux:

[abelard@bogon ~] ifconfig eno1 192.168.90.197

and execute the flollowing command under mac:

~ » ping 192.168.90.197                                          abelard@localhost
PING 192.168.90.197 (192.168.90.197): 56 data bytes
64 bytes from 192.168.90.197: icmp_seq=0 ttl=64 time=0.803 ms
64 bytes from 192.168.90.197: icmp_seq=1 ttl=64 time=0.602 ms
64 bytes from 192.168.90.197: icmp_seq=2 ttl=64 time=0.606 ms

But when I changed mac's ip into 192.168.91.104:

     ~ » sudo ifconfig en0 192.168.91.104                          

then

~ » ping 192.168.90.197                                       abelard@localhost
PING 192.168.90.197 (192.168.90.197): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2

why?

Best Answer

An IPv4 address is really just a 32-bit binary number. The entire 32 bits are significant for a host address.

Conceptually an address is divided into two parts: the network part and the host part. The dividing line can be moved by the network mask that determines which bits of an address are for the network part. More recently, the network mask is being replaced with the mask length (address and mask length are a network prefix), and you can easily convert a mask length to a mask by setting the length number of most significant bits to one.

In your example the mask length appears to be 24, but assuming you use 16, that would make the mask 255.255.0.0, meaning the usable network host addresses are from .0.1 to .255.254. If the mask length was 17, then the last usable host number is .127.254, while for 18, it would be .63.254, etc.

You must convert the dotted-decimal notation, that is simply for human readability, into binary to perform your calculations. When you do that, everything becomes obvious. Convert back to dotted-decimal when you are done with your calculations. Remember, IPv4 addresses are really 32-bit binary numbers, and trying to do this in dotted-decimal will lead to confusion and errors.

See this answer for how do do all your IPv4 calculations.


Assuming you have a router that knows how to get to all the other networks, you can actually ping any host address, even hosts not on your network. Traffic is delivered directly from host-to-host by layer-2, e.g. ethernet, on a LAN, but it needs layer-3, e.g. IPv4, to get from one LAN to another LAN.

A host will mask both its address and a destination address to see if both are on the same LAN. If they are, it lets layer-2 deliver directly to the destination. If not, it has layer-2 send to it configured gateway. It is then up to the gateway to get the packets forwarded toward the destination.

Related Topic