Without a populated routing table that contains entries for remote networks, routers will not be able to forward packets to those remote networks. The routing table may include specific network entries or simply a single default route. The information in the routing table is used by the forwarding process to forward traffic to the destination network or host. The routing table itself does not actually forward traffic.
Cisco routers use the administrative distance, routing protocol metric, and the prefix length to determine which routes will actually be placed into the routing table, which allows the router to build the routing table. The routing table is built using the following general steps:
- If the route entry does not currently exist in the routing table, add it to the routing table
- If the route entry is more specific than an existing route, add it to the routing table. It should also be noted that the less specific entry is still also retained in the routing table
- If the route entry is the same as an existing one, but is received from a more preferred route source, replace the old entry with the new entry
- If the route entry is the same as an existing one, and is received from the same protocol:
- Discard the new route if the metric is higher than the existing route
- Replace the existing route if the metric of the new route is lower
- If the metric for both routes is the same, use both routes for load-balancing
When building the RIB, by default, the routing protocol with the lowest administrative distance value will always win when the router is determining which routes to place into the routing table. For example, if a router receives the 10.0.0.0/8 prefix via external EIGRP, OSPF, and internal BGP, the OSPF route will be placed into the routing table. If that route is removed or is no longer received, the external EIGRP route will be placed into the routing table. And finally, if both the OSPF and external EIGRP routes are no longer present, the internal BGP route is used.
Once routes have been placed into the routing table, by default the most specific or longest match prefix will always be preferred over less specific routes. This is illustrated in the following example which shows a routing table that contains entries for the 184.108.40.206/8, 220.127.116.11/16, and the 18.104.22.168/24 prefixes. These three route prefixes are received via the EIGRP, OSPF, and RIP routing protocols, respectively.
|R1#show ip route
Codes: C – connected, S – static, R – RIP, M – mobile, B – BGP
D – EIGRP, EX – EIGRP external, O – OSPF, IA – OSPF inter area
N1 – OSPF NSSA external type 1, N2 – OSPF NSSA external type 2
E1 – OSPF external type 1, E2 – OSPF external type 2
i – IS-IS, L1 – IS-IS level-1, L2 – IS-IS level-2, ia – IS-IS inter area
* – candidate default, U – per-user static route, o – ODR
P – periodic downloaded static routeGateway of last resort is not set
R 22.214.171.124/24 [120/1] via 10.1.1.2, 00:00:04, Ethernet0/0.1
Referencing the output shown above, the first route is the 126.96.36.199/24 route. This route is learned via RIP and therefore has a default administrative distance value of 120. The second route is the 188.8.131.52/8 route. This route is learned via internal EIGRP and therefore has a default administrative distance value of 90. The third route is the 184.108.40.206/16 route. This route is learned via OSPF and is an external OSPF route that has an administrative distance of 110.
NOTE: Because the routing protocol metrics are different, they are a non-factor in determining the best route to use when routes from multiple protocols are installed into the routing table. The following section will describe how Cisco IOS routers build the routing table
Based on the contents of this routing table, if the router received a packet destined to 220.127.116.11, it would use the RIP route because this is the most specific entry, even though both EIGRP and OSPF have better administrative distance values and are therefore more preferred route sources. The show ip route 18.104.22.168 command can be used to verify this statement:
|R1#show ip route 22.214.171.124
Routing entry for 126.96.36.199/24
Known via “rip”, distance 120, metric 1
Redistributing via rip
Last update from 10.1.1.2 on Ethernet0/0.1, 00:00:15 ago
Routing Descriptor Blocks:
* 10.1.1.2, from 10.1.1.2, 00:00:15 ago, via Ethernet0/0.1
Route metric is 1, traffic share count is 1