Router – Why Can a Router Make Two PCs in Different Subnets Access Each Other?

Networkroutersubnet

Case 1: PC A: 192.168.1.2 / 24, and it connects to LAN port1 of router A PC B: 192.168.2.3 / 24, and it connects to LAN port2 of router A Given above we know A and B can't talk to each other due to different subnets

Case 2: PC A: 192.168.1.2 / 24, and it connects to LAN port1 of router A PC B: 192.168.2.3 / 24, and it connects to LAN port1 of router B router A: its WAN port connects to router B's LAN port 2, router B has been configured to route packets for PC A to router A

My question: in case 2, the packet will move in the path PC B -> router B -> router A -> PC A successfully, however I wonder since the packet still has its source IP as 192.168.2.3 and target IP as 192.168.1.2 which are of different subnet, when PC A receives the packet, it will still check the packet's source IP with 255.255.255.0 to get PC B's subnet which will be different from PC A's like how it will in Case 1, which should again prevent the packet from reaching PC A. What has the router done to make the packet successfully reach?

Many thanks!

Best Answer

I wonder since the packet still has its source IP as 192.168.2.3 and target IP as 192.168.1.2 which are of different subnet, when PC A receives the packet, it will still check the packet's source IP with 255.255.255.0 to get PC B's subnet which will be different from PC A's like how it will in Case 1, which should again prevent the packet from reaching PC A.

No. A host receiving an IP packet only cares that the destination IP address is its IP address. It does not care what the source address is for the purpose of accepting the packet.

As explained in this answer, the problem of two different network-layer networks on the same data-link network is that the source host will not send a frame to the destination host if the network-layer destination address is for a different network-layer network.

The source sends a datalink frame for a packet destined to a different network-layer network to its configured gateway (router), not the destination host data-link address, so the destination host on the same data-link network but a different network-layer network will never get the frame with the IP address.


Bridges (including switches) deliver data-link frames on the same data-link network, but the source host will not use the data-link address for a host on a different network-layer network. Routers route network-layer packets between different network-layer networks, so each router interface has an address in a different network-layer network.