In the same way that you can set a default gateway on your desktops and servers, you can also set a default gateway of sorts on your Cisco router – the gateway of last resort. While the name is different, the function is the same. Remember that when a router comes across a packet destined for an unknown network, it automatically drops the packet. If we specify a gateway of last resort, a router will forward traffic for networks that it doesn’t know about to the destination router address we specify.
Consider the figure above, in which Router A is connected to many different networks. Router B, on the other hand, is only connected to two networks. In order to allow Router B to get to all of the other networks shown, we would either need to configure a routing protocol (like RIP or IGRP), or define static routes to each network. In this particular scenario, it might actually be easier to use default routing to allow Router B to reach those three networks. Remember that Router B already knows about networks 10.0.40.0/24 and 10.0.50.0/24, since they are directly connected. In order to have Router B forward all traffic destined for other networks to Router A, we should configure a gateway of last resort on Router B. This involves a single routing table entry, with a destination network of 0.0.0.0. If you recall from Chapter 5, this address literally means “all networks”. In other words, we are saying that all other networks can be reached via Router A. When Router B attempts to route packets, it will first look in its routing table for the destination network. If it doesn’t find an entry, it will forward packets to the default route specified.
To configure the gateway of last resort on Router B, use the ip route command, as shown below.
RouterB(config)#ip route 0.0.0.0 0.0.0.0 10.0.40.1
RouterB#sh ip route
Codes: C - connected, S - static, I - IGRP, 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, E - EGP
i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, * - candidate default
U - per-user static route, o - ODR
Gateway of last resort is 10.0.20.1 to network 0.0.0.0
10.0.0.0/24 is subnetted, 2 subnets
C 10.0.50.0 is directly connected, Ethernet0
C 10.0.40.0 is directly connected, Serial0
S* 0.0.0.0/0 [1/0] via 10.0.40.1
Notice that the static route entry used 0.0.0.0 for both the destination IP address and subnet mask, followed by the address of the next hop router. In this case, all traffic not destined for networks 10.0.50.0/24 and 10.0.40.0/24 will be forwarded to 10.0.40.1, interface S0 on Router A. The default route also appears in our routing tables as both the gateway of last result and as a static route. In this scenario, Router A would still need a routing table entry that defines how to reach network 10.0.50.0/24.
Default routes are commonly used when you are routing public IP addresses to the Internet. If you didn’t define a default route, you would literally need to define a next hop address for every network on the Internet!