This document describes how to configure a default route or gateway of last resort.
There are no specific requirements for this document.
This document is not restricted to specific software and hardware versions. The command outputs shown were taken from a Cisco 3900 Series router with Cisco IOS®Software Release 15M.
The information in this document was created from the devices in a specific lab environment. All of the devices used in this document started with a cleared (default) configuration. If your network is live, ensure that you understand the potential impact of any command.
For more information on document conventions, see theCisco Technical Tips Conventions.
Default routes are used to direct packets addressed to networks not explicitly listed in the routing table. Default routes are invaluable in topologies where it is not desirable to learn all the more specific networks, as in case of stub networks, or not feasible due to limited system resources such as memory and limited resources.
The next IP commands are used and described in more detail:
Use Command ip default-gateway
Theip default-gatewaycommand differs from the other two commands as it must be used only be used whenip routingis disabled on the Cisco router. For instance, if the router is a host in the IP world, you can use this command to define a default gateway for it. You can also use this command when your low end Cisco router is in boot mode in order to TFTP a Cisco IOS® Software image to the router. In boot mode, the router does not haveip routingenabled. This example defines the router on IP address 172.16.15.4 as the default route:
ip default-gateway 172.16.15.4
Use Command ip default-network
Unlike theip default-gatewaycommand, you can useip default-network whenip routingis enabled on the Cisco router. When you configureip default-networkthe router considers routes to that network for installation as the gateway of last resort on the router. For every network configured withip default-network, if a router has a route to that network, that route is flagged as a candidate default route. This network diagram displays the routing table taken from router R1:
Notice that the static route to 192.168.1.0 via 10.44.192.2 and that the gateway of last resort is not set. If you configureip default-network 192.168.1.0, the routing table changes as follows:
The gateway of last resort is now set as 10.44.192.2. This result is independent of any routing protocol, as shown by theshow ip protocolscommand output no routing protocol is configured. You can add another candidate default route with the configuration of another instance ofip default-network:
Note: After theip default-networkcommand was entered you can observe that the network was not flagged as a default network. TheFlag a Default Networksection explains the reason.
Flag a Default Network
Theip default-networkcommand is classful, this means that if the router has a route to the subnet indicated by this command, it installs the route to the major network. At this point neither network has been flagged as the default route. Theip default-networkcommand must be run again, this time with the use of the major network in order to flag the candidate as a default route.
If the original static route had been configured to the major network, the previous step would not have been necessary.
There are still no IP Protocols configured in the router, without any dynamic protocols you can configure your router to choose from a number of candidate default routes based on whether the routing table has routes to networks other than 0.0.0.0/0. Theip default-networkcommand allows you to configure robustness into the selection of a gateway of last resort. Rather than the use of static routes to specific next-hops, you can have the router choose a default route to a particular network based in the routing table information.
If you lose the route to a particular network, the router selects the other candidate default. In that scenario, you can then remove the lost route from the configuration as shown in the next output:
After you remove the static route to the network, the routing table looks like this:
Use Different Routing Protocols
Gateways of last resort selected via theip default-networkcommand are propagated differently based on which routing protocol is used. For EIGRP there are different methods to Configure a Default Route in EIGRP which are preferred. The default route announced with theip default-networkcommand is not propagated by Open Shortest Path First (OSPF) or by Intermediate System-to-Intermediate System (IS-IS). For more detailed information on behavior of default routes with OSPF, refer toHow Does OSPF Generate Default Routes?.
Use Command ip route 0.0.0.0 0.0.0.0
A static route configured with the command ip route 0.0.0.0 0.0.0.0 is another way to set the gateway of last resort on a router. As with theip default-networkcommand, the use of the static route to 0.0.0.0 is not dependent on any routing protocols. However,ip routingmust be enabled on the router.
Note: EIGRP propagates a route to network 0.0.0.0, but the static route must be redistributed into the routing protocol.
In earlier versions of RIP, the default route created through theip route 0.0.0.0 0.0.0.0was automatically advertised by RIP routers. In Cisco IOS Software Release 12 and later, RIP does not advertise the default route if the route is not learned via RIP. It can be necessary to redistribute the route into RIP.
The default routes configured with theip route 0.0.0.0 0.0.0.0command are not propagated by OSPF and IS-IS. Additionally, this default route cannot be redistributed into OSPF or IS-IS through theredistributecommand. Use the default-information originate command to generate a default route into an IS-IS or OSPF routing domain. For more detailed information about the behavior of default routes with OSPF, please refer toHow Does OSPF Generate Default Routes?. The next output is an example on how to configure a gateway of last resort with the use of theip route 0.0.0.0 0.0.0.0command:
R1#configure terminal Enter configuration commands, one per line. End with CNTL/Z.
Note:If you configure multiple networks as candidate default routes via theip default-networkcommand, the network that has the lowest administrative distance is chosen as the network for the gateway of last resort. If all the networks have the same administrative distance then the network listed first in the routing table is chosen as the network for the gateway of last resort. If you use both theip default-networkandip route 0.0.0.0 0.0.0.0commands to configure candidate default networks theip route 0.0.0.0 0.0.0.0command, takes precedence and is chosen for the gateway of last resort. If you use multipleip route 0.0.0.0 0.0.0.0commands to configure a default route, traffic is load-balanced over the multiple routes.
Use theip default-gatewaycommand whenip routingis disabled on a Cisco router. Use theip default-networkorip route 0.0.0.0 0.0.0.0commands to set the gateway of last resort on Cisco routers that haveip routingenabled. The way in which routing protocols propagate the default route information varies for each protocol.