Two hosts with different subnets on layer 2 switch

2019-09-07 19:15发布

问题:

I am just preparing for a test in college about networking. I'm currently trying around with sub netting and I found out that two devices attached to a layer 2 switch can talk to each other although they have different subnets!

Device A: 192.168.0.1 subnet mask : 255.255.255.0

Device B: 192.168.1.1 subnet mask : 255.255.255.0

The question is why I can ping from device A to B and vice versa? There's no router, just the two devices and a switch.

From my understanding they should not see each other. The OS should not even send the ARP request when the unknown IP is in a different subnet.

Could this be a caching issue?

回答1:

Many Cisco Layer 2 switches are capable to ping the connected systems.



回答2:

It is possible that your computer might have a route entry that sends a packet which matches no other specific route entry to your router. This is also called as the default gateway. Conventionally the computers in the same subnet are connected directly and most of the times, do not go through the gateway.

To explain it more clearly, If you're on a Linux machine, run route -n.

Destination     Gateway         Genmask
14.0.1.0        0.0.0.0         255.255.255.0
0.0.0.0         172.16.80.1     0.0.0.0      

The first entry has a destination ranging from 14.0.1.0 to 14.0.1.255. The gateway for this match is 0.0.0.0. The table implies that these systems are connected directly. On the other hand, the entry 0.0.0.0 in the destination field will get matched when the packet matches none of the other entries. The gateway for this is the router address (which in my case in 172.16.80.1). All the packets that do not have IPs in the range that I specified above go to the router for further routing. Once the router gets the packet, it takes the further decision based on its routing information that it posses.

In your case the router happens to know that the other subnet is attached to it and hence passed your packet onto that subnet.

Have a closer look at the ARP. The ARP would be addressed to the router in your case of pinging to the other subnet. On the other hand, if pinging within the network, the ARP would be to the destination directly. This is the conventional case. Of course, it all depends on the routing tables in your system. You can always make all packets go through the gateway or no packets to go through the gateway.