Can we connect two subnets to the same switch.
Say, if i have 2 PCs connected to a L2 switch
Pc1 – 10.232.167.10
Pc2 – 192.168.3.1
Is it possible to ping pc1 from pc2 and vice-versa ?
Theoretically, it must be possible – because switch operated only at L2. If i send a ping packet from Pc1, the switch (since the mapping table is not updated) sends broadcast on all its connected ports.
When the Pc2 received the packet, sees that it is for its own IP address and should accept the packet, and hence forth a mapping gets created in switch (source MAC + port -> Destination port). From there after, I can ping Pc2 from Pc1.
However it did not work practically. I would like to know the reason ?
Reason: if the ip is not in it’s range of the device, it automatically sends it to the default gateway, that’s why it won’t work in different subnets with just a L2 switch attached. Broadcast packets “who has ip x.x.x.x” (used in ARP) only occur when the ip is in the same subnet as the machine sending it.
The only solution is to connect a router to that switch with the 2 subnets configured on LAN side, connected to the L2 switch. If possible you can work with subinterfaces or just use 2 interfaces.
If you just want a bigger range, you can adapt the subnetmask if they are in the following subnet:
192.168.1.0 / 255.255.255.0 => 255.255.254.0
this allows 192.168.0.x to talk to 192.168.1.x.
This however is just widening your range, it doesn’t have the advantages of vlan’s or subnetting.