Suppose there is a host, HOST_A
, on LAN1
and is sending a packet.
The destination address of that packet is: 10.10.11.77
HOST_A
will refer to it's routing table and see that that there is no entry for 10.10.11.77
and will forward the packet to the default gateway, 0.0.0.0/0
. Assuming that the arp cache has the mac address of the default gateway, HOST_A
will encapsulate the packet to in an Ethernet frame destination to the mac address of the default gateway.
After being sent to default gateway, it reaches a router, ROUTERX
, in the default zone. The router needs to forward the packet out the right interface. The router is directly is on 5 subnets.
The interfaces and the their IPs:
so-0/0/0
has an IP of10.0.12.1/24
so-0/0/1
has an IP of10.0.19.1/24
so-0/0/2
has an IP of10.0.17.1/24
so-0/0/3
has an IP of10.0.23.1/24
Network | Prefix | Next-Hop | Interface -------------------------------------------- 10.10.0.0 | /20 | 10.0.12.0 | so-0/0/0 scope global 10.10.8.0 | /21 | 10.0.19.0 | so-0/0/1 scope global 10.10.8.0 | /22 | 10.0.17.0 | so-0/0/2 scope global 10.10.10.0 | /24 | 10.0.23.0 | so-0/0/3 scope global
The packet would get forwarded out interface so-0/0/2 because it is the most specific match. We do not send it out of so-0/0/3 because despite having a longer prefix, the 24th bit does not match
Edit: Here's is the source of my confusion, an excerpt from The Illustrated Network: How TCP/IP works in a modern network 2nd Ed.
I use LAN1
in my example instead of LAN2
and the section in the middle is describing the look up process.
Consider a packet sent to 10.10.11.77 ( bsdclient ) from LAN2. Remember,the network is 10.10.11.0/24 ...
...There is no longer entry. This makes the /22 entry the longest match for the destination address, and the packet is forwarded to 10.10.17.2. The rest of the bits are used for local delivery of the packet on LAN2.