Table of Contents
Today, we will learn about routing tables in a computer network. But, before moving ahead, let’s see what a router is.
What is a Router?
A router, as the name suggests, performs the routing of a data packet. It uses routing algorithms to transfer a data packet from a source to its destination between computer networks. In other words, a router connects different networks. For example, we can use routers to establish a connection between two cities. Then, using them, we can easily send the data from one city to another.
What does a Router do?
The router checks the packet content when it arrives. A data packet contains information such as origin IP address, destination IP address, and next-hop address, etc. The router checks the data packet’s destination IP address and decides the interface to forward the packet. It does that by using the routing table.
Routing Table (Routing Information Base (RIB))
It is a data table that contains a set of rules to determine the routing of a packet. It has routing entries that have the information of known routes of networks.
Routing Table Fields
Each entry contains the following fields:
- The destination IP address or the network ID.
- The subnet mask of the network. (netmask)
- The IP address of the next-hop, which is the address of the gateway or the next station to which a packet gets forwarded on its way from source to destination.
- The outgoing interface on which the data packet should get routed out when it gets forwarded to the next hop or destination.
- Routing metrics assigned to each available IP route to help the router choose the most optimal path among others to reach a destination. For example, the metric can represent link speed, time delays, and hop count (count of routers (hops) in the path to the destination).
Router Determination Process
When a packet arrives at a router, it checks its destination IP address to find where the packet should be forwarded. Specifically, it performs the bitwise AND operation between the packet’s destination IP address and the subnet mask of each entry in the routing table. Then, it compares each result with the corresponding destination IP address in the routing table. Following cases may arise:
- If the packet’s destination IP address gets matched with only one destination IP address in the routing table, there is no conflict, and it gets forwarded on the corresponding interface.
- If there are multiple matches, the packet gets forwarded to an interface whose entry has the largest subnet mask.
- Otherwise, the packet gets forwarded on the interface corresponding to the default gateway. A default gateway is a path that a router uses to forward a packet when it does not know the packet’s destination address. Its destination IP address is 0.0.0.0 and subnet mask is also 0.0.0.0.
Examples
Let’s take some examples. Consider the routing table of a router that contains one entry for the default gateway and three other entries.
Destination | Subnet Mask | Interface |
---|---|---|
192.168.56.0 | 255.255.255.0 | A |
192.168.56.1 | 255.255.255.255 | B |
192.168.56.255 | 255.255.255.255 | C |
Default | D |
Example I
Consider a packet with a destination IP address of 192.168.56.15. How to find out the interface on which the router will forward the packet?
First, let’s perform the bitwise AND operation between the packet’s destination IP address and each subnet mask, i.e.,
Packet’s destination IP | Subnet mask of Network | Bitwise AND | Match |
---|---|---|---|
192.168.56.15 | 255.255.255.0 | 192.168.56.0 | Yes |
192.168.56.15 | 255.255.255.255 | 192.168.56.15 | No |
192.168.56.15 | 255.255.255.255 | 192.168.56.15 | No |
As shown in the table above, the match only exists with a single entry, i.e., entry with destination IP address 192.168.56.0. Therefore, the packet will get forwarded on its corresponding interface, i.e., interface A.
Example II
Consider a packet with a destination IP address of 192.168.57.3. To which interface will the router send the packet? The bitwise AND operation between the packet’s destination IP address and each subnet mask is as follows:
Packet’s destination IP | Subnet mask of Network | Bitwise AND | Match |
---|---|---|---|
192.168.57.3 | 255.255.255.0 | 192.168.57.0 | No |
192.168.57.3 | 255.255.255.255 | 192.168.57.3 | No |
192.168.57.3 | 255.255.255.255 | 192.168.57.3 | No |
As you can observe, no match occurs with any network’s destination address. Therefore, the packet will get routed over the interface that corresponds to the default gateway, i.e., interface D.
Example III
Consider a packet with a destination IP address of 192.168.56.1. Find out the interface on which the router will forward the packet?
Let’s perform the bitwise AND operation between the packet’s destination IP address and each subnet mask, i.e.,
Packet’s destination IP | Subnet mask of Network | Bitwise AND | Match |
---|---|---|---|
192.168.56.1 | 255.255.255.0 | 192.168.56.0 | Yes |
192.168.56.1 | 255.255.255.255 | 192.168.56.1 | Yes |
192.168.56.1 | 255.255.255.255 | 192.168.56.1 | No |
There exists more than one match. In this case, the packet will get routed out over the interface that corresponds to the longest subnet mask. Since the entry with interface B has a longer subnet mask (255.255.255.255) than the subnet mask of entry with interface A (255.255.255.0), the packet will go to interface B.
[adinserter block=”2″]
How are routing tables populated and maintained?
Let’s now briefly discuss that how routing tables are populated and maintained. They are maintained using default routing, static routing, or dynamic routing mechanisms.
Static Routing
In static routing, the routing table gets configured manually. A network administrator adds an entry for each route in the routing table. Moreover, these routes are fixed, and thus, they do not change automatically unless the network administrator manually changes them.
Dynamic Routing
In Dynamic routing, on the other hand, the routing table gets populated automatically by using a routing protocol, for example, RIP, IGRP, and OSPF, etc. These routing protocols add entries for routes. Moreover, these routes are dynamic, and therefore, they are updated and recalculated automatically whenever some change occurs in the network. This gets done through routing protocols that allow a router to exchange information with other routers in the network.
Default Routing
Here, all packets get configured to forward packets to a single router. This is usually used along with static and dynamic routing.
Software Engineer