11

Two host of different subnets, let it be A - 10.1.2.1/24 and B - 10.1.3.1/24 be connect to the same switch S. Can they communicate?

So as far I understand:

  • A sends a packets with IP of B
  • S receives it and compare it with values in Stored Address Table else broadcasts it.
  • B receives the packets, check the IP and accepts it.

Am I right?

19

Unfortunately, no, you are incorrect.

Ron makes a good point, you didn't provide a subnet mask, so if we were to assume the classful mask, the 10.x.x.x address would have a 255.0.0.0 mask, which would actually put the two hosts on the same network. If that is the case, they would have no problem communicating.

However, given the nature of your question, I imagine you intended for each of these hosts to use a smaller mask -- we'll go ahead and use 255.255.255.0, which puts both hosts in two different subnets.

That being said, the heart of what you are missing lies in forgetting about ARP (Address Resolution Protocol). Specifically, in whom HostA decides to ARP for. Let me explain...


Before any host puts any packet on the wire, the first thing it does is determine whether the destination IP is on its own network, or on a foreign network. Let's run through it from the perspective of Host A.

Host A know its IP (10.1.2.1), and its Subnet Mask (/24, or 255.255.255.0). With a little subnetting, HostA determines that its network spans all the IP addresses in the range of 10.1.2.0 through 10.1.2.255. (We'll leave out details of the NetID and BroadcastIP, since for the moment they aren't relevant)

Host A also knows its destination IP is 10.1.3.1, which falls outside of the range of IP addresses within Host A's own network. As such, Host A would would come to the conclusion that the destination IP 10.1.3.1 is on a foreign network, and Host A could only reach a foreign network by speaking through a Router. Or more specifically, through HostA's default gateway.

If HostA isn't configured with a Default Gateway at this point, then the process ends here with a general failure. HostA can not speak to HostB.

If HostA is configured with a Default Gateway, it would send out an ARP Request (which is itself a Broadcast frame), asking for the MAC address of its default gateway -- NOT the MAC address of the final destination IP.

The switch, having received the broadcast frame would flood the packet out all interfaces, to include the one HostB is connected to. HostB would indeed receive the packet, but since the ARP is looking for the Default Gateway's MAC address (and not the MAC address of HostB), HostB would simply drop and ignore the ARP Request, without ever sending any sort of response.

HostA, then, would never receive a MAC address for its default gateway, and would therefore be unable to encapsulate the Layer 3 Packet with a Layer 2 header. The packet would fail there.

You can see the ARP process illustrated in this video.


That said, although somewhat unrelated to your question, I did want to speak to something you said. This may be terminology nuance, but I just want to make sure it is communicated. A switch only does two things: forwards frame for which it know the destination MAC address, or flood frames for which it doesn't know the destination MAC address. A switch never broadcasts.

A broadcast is a frame who's destination MAC address is ffff.ffff.ffff. This is a specially reserved MAC address, specifically designed for broadcast frames. When a switch encounters a frame destined to ffff.ffff.ffff, its behavior is to always flood that frame.

You could look at it like this, since ffff.ffff.ffff is a reserved MAC address, it is un-learn-able by the switch. Therefore, whenever a switch receives something destined to ffff.ffff.ffff, it is forced to flood it out all ports in the VLAN that the frame was originally received in.

2
  • There are edge cases to this answer... hosts can have either no gateway, or their own address configured as their gateway address. This causes the host to ARP for all addresses and proxy-arp enabled routers with a route (even default route) to the destination will reply with their own mac-address.
    – cpt_fink
    Nov 8 '14 at 1:39
  • 3
    There are edge cases for just about any answer/situation. I didn't think going into some of them here would be relevant to the question.
    – Eddie
    Nov 16 '14 at 15:46
2

Yes. If they are under /16 Subnet. For /24 subnet, you need router.

1
  • 1
    You could improve your answer by explaining it more. For instance, explain why it works with /16, but `/24 needs a router.
    – Ron Maupin
    Jul 1 '16 at 14:40
0

If host A and B are on different networks or subnets and connected to the same switch I believe that they can communicate through the default gateway.

1
  • A gateway address must be in the same network as the address configured on a host. Since the gateway address is the address used to send traffic off the network, it must be in the same network as the sending host, otherwise the host would need a gateway to get to the gateway.
    – Ron Maupin
    Feb 10 '17 at 17:22
0

Only if the switch is connected to a router that knows how to route between these 2 subnets.

1
  • Layer 3 switch does not required separate router
    – infra
    Apr 24 '19 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.