How Router Select The Best Path
a month ago
A router works as a transformer. It receives some packets and then sends them to further destined IP addresses by choosing the best path.
But our concern is, how does a router choose the best path? This is what we’ll explore here in this blog post.
First of all, know that there are three factors that act in the process of choosing a path for a router. Therefore, to know about this topic, we’ll have to look for each aspect closely in order to understand this phenomenon.
The three factors are:
- Administrative distance
It’s better to note that the factors do not always take place in the process. They only become part of this dispute when the process is manipulated by the similarities between them.
Below we’ve discussed them in detail; take a look at them. Longest prefix length – Multiple routes with a different prefix length The longest prefix length is the factor that comes first when selecting a route. Let’s say there are multiple routers with different prefix lengths leading to a destination. Then, for a router, the best path will be the IP address with maximum length, and in this process, there will be no more factors going to act on it. Even the type of protocol used does not matter.
These are the destinations with different prefix lengths.
10.1.1.0/22 10.1.1.0/25 10.1.1.0/28
And suppose a packet with an IP address of 10.1.1.1 is tended to reach the destination that is listed above. Now, the router will pick the 10.1.1.0/28, which is the largest among them regardless of the type of protocol, and it is because the longest prefix always matches the most. Here is why?
The listed example addresses have the following binary representation:
The Destined IP address is:
10.1.1.0 → 00001010.00000001.00000001.00000000
The destination IP addresses explored.
/20 → 00001010.00000001.0000|0001.00000000 /24 → 00001010.00000001.00000001|.00000000 /27 → 00001010.00000001.00000001.000|00000
As you can justify, from the given subnets the 10.1.1.0/27 is the longest prefix, and it makes it the best match of the address 10.1.1.1. That’s why the router will select this route first above all. Conclusively, it will always pick the longest prefix.
- Administrative distance – When multiple routes with the same prefix length
This is the second way to choose a path for a router, and it exists when there are multiple prefixes with the same length, then a router follows the path depending upon the administrative distance, length values.
As a general rule of thumb, in this way, the protocol is an important subject. For instance, if there are static routers, BGP, OSPF, etc. you may know that already, each of these values has been assigned as the level of trust, and they all scale by a certain value. Where the lower the value means that the more trust for a router.
In the below table, you can see the administrative distance values of each protocol.
Protocol Administrative Distance Connected 0 Static 1 eBGP 20 EIGRP internal 90 IGRP 100 OSPF 110 IS-IS 115 RIP 120 EIGRP external 170 iBGP 200
Let’s say if there is a destination IP address with the same prefix length. Then a router will look for the second way, which is administrative values. Below is an example. These are the three IP addresses with the same prefix length but the difference in protocol.
10.1.1.0/27 static 10.1.1.0/27 EBGP 10.1.1.0/27 IGRP
According to the rule of choosing the best path, the router will select the static route in order to forward the packet since it has the lowest administrative distance, which means more trust.
Note that if the prefix lengths are not equal and the static protocol IP’s prefix is lower than EBGP. Something like that;
10.1.1.0/22 static 10.1.1.0/28 EBGP
In this case, the router will go with the length prefix method, regardless of the protocol associated with them.
- Metrics – When multiple routes with the same prefix length and protocol
This is the last way to choose the best path for a router, and it comes to exist when all the parameters are the same. For example, the prefix length, the protocols for multiple IP addresses are the same for each. At that point, a router follows the in-depth paths as speed, hops, distance, etc. And choose the one according to these scales.
A routing protocol can learn multiple paths for the same destination. In this case, each routing protocol uses its own internal metrics, for example, based on distance, speed, hops, etc.) to calculate which of those paths is the best one. For example: Suppose there are destined IP addresses with the same characters.
10.1.1.0/22 static 10.1.1.0/22 static 10.1.1.0/22 static 10.1.1.0/22 static
At this stage, a router chooses the one which has the more stability, speed, hops, and closer to it.
Summary A router chooses the first by looking at the prefix length with the more excellent value by the given information. Mind that, the prefix should be different from each one. In case the prefix values are the same, then a router chooses the path by looking at the administrative weight, which ultimately relates to protocols. The lower value protocol is the best path for a router; for instance, the direct protocol has the 0 value, and static has one value.
Lastly, when the protocol and the prefix lengths both are the same in the various IP addresses. At that moment, a router chooses the path according to their sub-values, including speeds, distance, hops, and the list goes on, covering the many parameters that sometimes are hard to put in words.