第2层交换机上有两个不同子网的主机 - 为什么这样做? [英] Two hosts with different subnets on layer 2 switch - why does this work?

查看:570
本文介绍了第2层交换机上有两个不同子网的主机 - 为什么这样做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正准备在大学里测试网络测试。
我目前正在尝试子网,我发现连接到第2层交换机的两个设备可以互相通信,尽管它们有不同的子网!

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!

设备A:192.168.0.1子网掩码:255.255.255.0

Device A: 192.168.0.1 subnet mask : 255.255.255.0

设备B:192.168.1.1子网掩码:255.255.255.0

Device B: 192.168.1.1 subnet mask : 255.255.255.0

问题是为什么我可以从设备A ping到B,反之亦然?
没有路由器,只有两个设备和一个开关。

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.

根据我的理解,他们不应该看到对方。
当未知IP位于不同的子网中时,操作系统甚至不应发送ARP请求。

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?

推荐答案

这是可能的您的计算机可能有一个路由条目,该条目条目不会将与其他特定路由条目匹配的数据包发送到路由器。这也称为默认网关。通常,同一子网中的计算机直接连接,大多数时候都不通过网关。

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.

为了更清楚地解释它,如果你在Linux机器上,运行 route -n

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      

第一个条目的目的地范围为14.0.1.0到14.0.1.255。此匹配的网关为0.0.0.0。该表表明这些系统是直接连接的。另一方面,当数据包与其他条目都不匹配时,目标字段中的条目0.0.0.0将匹配。这个网关就是路由器地址(在我的例子中是172.16.80.1)。所有没有上述指定范围内IP的数据包都会进入路由器进行进一步路由。一旦路由器获得了数据包,它就会根据它拥有的路由信息​​做出进一步的决定。

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.

仔细查看ARP。在ping到其他子网的情况下,ARP将发送到路由器。另一方面,如果在网络内ping,则ARP将直接到达目的地。这是传统的情况。当然,这完全取决于系统中的路由表。您始终可以使所有数据包通过网关或没有数据包通过网关。

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.

这篇关于第2层交换机上有两个不同子网的主机 - 为什么这样做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆