However, what happens when the subnet masks are different?
Let’s expand on our previous example
in this example, we have 4 routers
router 4 is learning about network 10.1.1.0/27
from router 1 via RIP version 2
router 4 is learning about network 10.1.0.0/16 from router 2 via BGP
and router 4 is learning about network 10.0.0.0/8 from router 3 via OSPF.
Notice the administrative distances RIP is 120
BGP is 200 in this example, OSPF is 110
which way will router 4 send traffic if you ping 10.1.1.1 on router 4.
Will it go to router 1? Because of the routes received via RIP
or will it let go to router 2 or will it go to router 3?
Notice OSPF has a lower administrative distance than RIP
and RIP has a lower administrative distance than BGP.
Which path is chosen by router 4?
The important lesson here is that the length of the route
takes precedence over administrative distance.
In other words, administrative distance is only used
if multiple routing protocols are trying to put
the same route into the routing table.
Router 4 is learning about network 10.1.1.0/27
10.1.0.0/16 and 10.0.0.0/8
the router will see this as 3 separate and distinct routes.
the 3 routes will be put into the routing table as they are seen as separate routes
but out of the 3 of them, network 10.1.1.0/27 is chosen as it has the longest match.
So, in other words, the ping from router 4 will go via router 1
because it’s the best match or longest match in the routing table
even though RIP has a high administrative distance than OSPF
longest match routes take precedence over administrative distance.