Default gateway routes in routing tables allow routers to forward all unmatched data packets. Routers use default gateway routes as the last route to forward data packets.
When a router receives a data packet, it matches the packet's destination address with the destination address of all routes available in the routing table.
- If it finds a match, it forwards the packet from the matching route.
- If it finds multiple matches, it forwards the packet from the route matching the maximum number of IP bits.
- If it does not find a match, it discards the packet.
If you want the router to forward all unmatched packets to a specific destination instead of discarding them, you can configure a default route to that destination. If a router has a default route, it uses it to forward all unmatched packets.
This tutorial is part of the tutorial series "Understanding route types in the routing table.". Other parts of this series are the following.
Chapter 1 The show IP route command on Routers
Chapter 2 Routing table updating methods
Chapter 3 Directly connected routes and Local routes
Chapter 4 Static and Floating Static Routes Explained
Chapter 5 Static and Dynamic routes in the routing table
Chapter 6 Default Route in the Routing Table
Chapter 7 Network Routes and Host Routes Explained
Let us take an example.
The following image shows the routing table of a router. The show ip route command prints the routing table's entries.
The router receives a data packet for the destination 20.0.0.1/8. The router compares the destination address with all routes' destination addresses. It finds two matches: 20.0.0.0/8 (directly connected route - C) and 20.0.0.1/32 (local route - L).
As mentioned earlier, if a router finds two or more matches, it selects the route that has the maximum matching IP bits. In this case, the local route has the maximum matching IP bits. It matches all 32 bits. Hence, the router selects this route.
Routers select a route only when its network bits (number of bits specified after the slash) exactly match the packet's destination address's network bits.
For example, the router will take the route 20.0.0.0/8 when the packet's destination address's first 8 bits exactly match. The router will take the route 20.0.0.1/32 when the packet's destination address's all 32 bits exactly match.
Let us suppose the router receives another data packet for the destination 20.0.0.10/8. In this case, the router cannot take the local route 20.0.0.1/32. Only 8 bits of this route match with the destination address. The router can take this route only when all 32 bits are the same.
The second route requires the first 8 matching bits. The packet's destination address's first 8 bits exactly match with the first 8 bits of this route. Therefore, the router will take the second route 20.0.0.0/8.
Let us one more example.
The router receives a data packet for the destination address 50.0.0.1/8. The router finds no routes having the matching bits. In this case, the router will check the default route. If the routing table does not have a default route, the router will discard the packet. If the routing table has a default route, it will use it to forward the packet. This routing table has a default route. The router will use the default route to forward the packet.
That's all for this tutorial. In this tutorial, we learned what the default routes are in the routing table and how routers use them to forward data packets.