Home > How a router makes a forwarding decision

How a router makes a forwarding decision

We all know when a packet reaches a router interface, the router will send the packet to the destination. But how can a router determines which route is the best to use to send the packet? In this tutorial we will learn more about how a router makes the forwarding decision.

introduction.jpg

To make the routing decision, the router must first build a table which contains all the best routes. When the packets arrive, the router just needs to check this table to choose the best match. This is called the routing table.

So what are stored in the routing table of a router? Let’s have a look with the “show ip route” command which will display the routing table of the local router.

R1# show ip route
--output omitted--
D	192.168.20.0/26 [90/24513456] via 10.10.10.1
R	192.168.20.0/24 [120/5] via 10.10.10.2
O	192.168.0.0/19 [110/219414] via 10.10.10.13
D	192.168.20.0/27 [90/4123710] via 10.10.10.12
D	192.168.20.0/25 [90/14464211] via 10.10.10.11
S*	0.0.0.0/0 [1/0] via 10.10.10.14

There are some notes about this routing table:

1. We see many routes of 192.168.20.0 with different prefix lengths (subnet masks) in this routing table. For example “/26”, “/24”, “/19″… This is normal because routes with different prefix lengths are considered different routes.

2. The routes of 192.168.20.0 were learned via different routing protocols, which are symbolized by different letters at the beginning of each entry. For example, letter “D” means “EIGRP”; letter “O” means “OSPF”, letter “R” means “RIP”.

3. The next hop of each entry is the IP address after the word “via”. For example we have next hops of 10.10.10.1, 10.10.10.2, 10.10.10.13…

Suppose R1 received a packet destined to 192.168.20.57. Which next hop will the router choose for the packet?

The router chooses the best path in the routing table based on this single rule:

Longest Prefix Matching Rule: The longest prefix that matches the route is preferred.

Let’s check from longest prefix down to shortest prefix:
+ 192.168.20.0/27 ranges from 192.168.20.0 – 192.168.31 so the IP address 192.168.20.57 does not belong to this prefix -> ignore.
+ 192.168.20.0/26 ranges from 192.168.20.0 – 192.168.20.63 so the IP address 192.168.20.57 belongs to this prefix -> router will choose this route to forward packets. We don’t need to check other shorter prefixes like /25 or /19.

To find out the range of each prefix you need to do subnetting well. If you still cannot do subnetting in your head then please read our Subnetting Tutorial – Subnetting Made Easy.

Wait, how about Administrative Distance and Metric values?

Maybe you will be surprised when we say “longest prefix match” is the only rule that the router uses to choose the path. Yes, in fact it is correct for routes that were installed into the routing table. The Administrative Distance (AD) and Metric values are only used to choose which prefixes will be installed into the routing table.

Let’s learn more about how these two values are used before a route is chosen to install into the routing table:

1. Lowest AD value: Same prefixes (which means same routes with same prefix lengths) use the Administrative Distance to choose the route to install into the routing table. For example, our router learns of the following networks via different routing protocols as follows:

  • 192.168.1.0/24 using OSPF (AD = 110) with next hop IP of 10.1.1.1
  • 192.168.1.0/24 using RIP (AD = 120) with next hop IP of 10.1.2.1
  • 192.168.1.0/24 using EIGRP (AD = 90) with next hop IP of 10.1.3.1

Then the third route with EIGRP will be installed into the routing table as the AD of EIGRP is smallest.

2. Lowest Metric value: This value is used as a tie-break when same prefixes have same AD. The route with the lowest metric is preferred. Use the same example above but with metric values:

  • 192.168.1.0/24 using OSPF (AD = 110) with next hop IP of 10.1.1.1
  • 192.168.1.0/24 using RIP (AD = 120) with next hop IP of 10.1.2.1
  • 192.168.1.0/24 using EIGRP (AD = 90) with metric of 30000 and next hop IP of 10.1.3.1
  • 192.168.1.0/24 using EIGRP (AD = 90) with metric of 25000 and next hop IP of 10.1.4.1

Then the fourth route (EIGRP with metric of 25000) will be chosen to install into the routing table because of lowest AD and lowest metric.

With additional configuration then load balancing may take place as EIGRP supports this feature. But load balancing is out of scope in this tutorial.

Conclusion

In summary, before a prefix is installed into the routing table, two values are compared in this order:
1. Administrative Distance
2. Metric

After a prefix is installed into the routing table then only the longest prefix match rule is used to choose the best route as the routing table is already filtered of all but the best routes, regardless of AD or metric.

A prefix is a network address with a subnet mask. For example 192.68.20.0/26 is a prefix.

Comments (5) Comments
  1. Amjed
    January 12th, 2024

    nice one

  2. SugarWaterMix
    April 15th, 2024

    This is super simplified and I appreciate it

  3. parth
    May 21st, 2024

    super explain easy to understand

  4. zain
    June 2nd, 2024

    thank you !

  5. Lingu
    September 13th, 2024

    Very well expllained

Add a Comment