0

I am currently facing a problem and can't get a definitive answer to how the router will decide the correct interface to forward my packet to.

Given that an IP datagram has destination address of 192.168.1.10 and my router has this two following entries:

192.168.1.0/24

192.168.1.16/27

In this case, which entry will be chosen here? I would think that the answer is 192.168.1.16/27 since it has the longest prefix that matches. However, some of my peers suggest it is 192.168.1.0/24 since the interface that contains 192.168.1.16 only accepts IPs that start from 192.168.1.16 so 192.168.1.10 does not exist inside of it.

  • 2
    192.168.1.16/27 isn't a valid route. It has bits set outside the network portion of the address. The closest matches would be 192.168.1.0/27 or 192.168.1.16/28. – Niels Apr 27 '25 at 12:47

1 Answers1

1

A prefix has only bits set in its network part, in your case the first 27 bits.

192.168.1.16 has the 28th bit set, so 192.168.1.16/27 is a host address plus mask, not a prefix. The matching prefix would be 192.168.1.0/27. See this excellent Q&A for how IP addresses and netmasks work.

Generally, routing prefers more specific = longer prefixes over more general = shorter prefixes.

Zac67
  • 90,111
  • 4
  • 75
  • 141