Introduction
This document describes how to configure a default route or gateway of last resort.
Prerequisites
Requirements
There are no specific requirements for this document.
Components Used
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.
Conventions
For more information on document conventions, see the Cisco Technical Tips Conventions.
Background Information
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:
-
ip default-gateway
-
ip default-network
-
ip route 0.0.0.0 0.0.0.0
Use Command ip default-gateway
The ip default-gateway command differs from the other two commands as it must only be used when ip routing is 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 have ip routing enabled. 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 the ip default-gateway command, you can use ip default-network when ip routing is enabled on the Cisco router. When you configure ip default-network, the router considers routes to that network for installation as the gateway of last resort on the router. For every network configured with ip 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:
R1#show ip route
Codes: L - local, C - connected, S - static, 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
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
Gateway of last resort is not set
10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
C 10.44.192.0/24 is directly connected, GigabitEthernet0/0
L 10.44.192.1/32 is directly connected, GigabitEthernet0/0
C 10.108.99.0/24 is directly connected, GigabitEthernet0/1
L 10.108.99.1/32 is directly connected, GigabitEthernet0/1
S 192.168.1.0/24 [1/0] via 10.44.192.2
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 configure ip default-network 192.168.1.0, the routing table changes as follows:
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#ip default-network 192.168.1.0
R1(config)#end
R1#
R1#show ip route
Codes: L - local, C - connected, S - static, 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
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
Gateway of last resort is 10.44.192.2 to network 192.168.1.0
S* 0.0.0.0/0 [1/0] via 10.44.192.2
10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
C 10.44.192.0/24 is directly connected, GigabitEthernet0/0
L 10.44.192.1/32 is directly connected, GigabitEthernet0/0
C 10.108.99.0/24 is directly connected, GigabitEthernet0/1
L 10.108.99.1/32 is directly connected, GigabitEthernet0/1
S* 192.168.1.0/24 [1/0] via 10.44.192.2
R1#
R1#show ip protocols
*** IP Routing is NSF aware ***
Routing Protocol is "application"
Sending updates every 0 seconds
Invalid after 0 seconds, hold down 0, flushed after 0
Outgoing update filter list for all interfaces is not set
Incoming update filter list for all interfaces is not set
Maximum path: 32
Routing for Networks:
Routing Information Sources:
Gateway Distance Last Update
Distance: (default is 4)
R1#
The gateway of last resort is now set as 10.44.192.2. This result is independent of any routing protocol, as shown by the show ip protocols command output, no routing protocol is configured. You can add another candidate default route with the configuration of another instance of ip default-network:
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#ip route 172.17.24.0 255.255.255.0 10.108.99.2
R1(config)#ip default-network 172.17.24.0
R1(config)#end
R1#
R1#show ip route
Codes: L - local, C - connected, S - static, 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
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
Gateway of last resort is 10.44.192.2 to network 192.168.1.0
S* 0.0.0.0/0 [1/0] via 10.44.192.2
10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
C 10.44.192.0/24 is directly connected, GigabitEthernet0/0
L 10.44.192.1/32 is directly connected, GigabitEthernet0/0
C 10.108.99.0/24 is directly connected, GigabitEthernet0/1
L 10.108.99.1/32 is directly connected, GigabitEthernet0/1
172.17.0.0/16 is variably subnetted, 2 subnets, 2 masks
S 172.17.0.0/16 [1/0] via 172.17.24.0
S 172.17.24.0/24 [1/0] via 10.108.99.2
S* 192.168.1.0/24 [1/0] via 10.44.192.2
Note: After the ip default-network command 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
The ip default-network command 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. The ip default-network command must be run again, this time with the use of the major network in order to flag the candidate as a default route.
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#ip default-network 172.17.0.0
R1(config)#end
R1#sh
*Jul 15 22:32:42.829: %SYS-5-CONFIG_I: Configured from console by conso
R1#show ip route
Codes: L - local, C - connected, S - static, 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
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
Gateway of last resort is 172.17.24.0 to network 172.17.0.0
S* 0.0.0.0/0 [1/0] via 172.17.24.0
10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
C 10.44.192.0/24 is directly connected, GigabitEthernet0/0
L 10.44.192.1/32 is directly connected, GigabitEthernet0/0
C 10.108.99.0/24 is directly connected, GigabitEthernet0/1
L 10.108.99.1/32 is directly connected, GigabitEthernet0/1
* 172.17.0.0/16 is variably subnetted, 2 subnets, 2 masks
S* 172.17.0.0/16 [1/0] via 172.17.24.0
S 172.17.24.0/24 [1/0] via 10.108.99.2
S* 192.168.1.0/24 [1/0] via 10.44.192.2
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. The ip default-network command 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:
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#no ip route 172.17.24.0 255.255.255.0 10.108.99.2
R1(config)#end
*Jul 15 22:52:59.047: %SYS-5-CONFIG_I: Configured from console by console
After you remove the static route to the network, the routing table looks like this:
R1#show ip route
Codes: L - local, C - connected, S - static, 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
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
Gateway of last resort is 10.44.192.2 to network 192.168.1.0
S* 0.0.0.0/0 [1/0] via 10.44.192.2
10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
C 10.44.192.0/24 is directly connected, GigabitEthernet0/0
L 10.44.192.1/32 is directly connected, GigabitEthernet0/0
C 10.108.99.0/24 is directly connected, GigabitEthernet0/1
L 10.108.99.1/32 is directly connected, GigabitEthernet0/1
S* 192.168.1.0/24 [1/0] via 10.44.192.2
R1#
Use Different Routing Protocols
Gateways of last resort selected via the ip default-network command 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 the ip default-network command 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 to How 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 the ip default-network command, the use of the static route to 0.0.0.0 is not dependent on any routing protocols. However, ip routing must 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 the ip route 0.0.0.0 0.0.0.0 was 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 the ip route 0.0.0.0 0.0.0.0 command are not propagated by OSPF and IS-IS. Additionally, this default route cannot be redistributed into OSPF or IS-IS through the redistribute command. 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 to How Does OSPF Generate Default Routes?. The next output is an example on how to configure a gateway of last resort with the use of the ip route 0.0.0.0 0.0.0.0 command:
R1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#ip route 0.0.0.0 0.0.0.0 10.108.99.2
R1(config)#end
R1#
R1#show ip route
Codes: L - local, C - connected, S - static, 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
i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
ia - IS-IS inter area, * - candidate default, U - per-user static route
o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP
a - application route
+ - replicated route, % - next hop override, p - overrides from PfR
Gateway of last resort is 10.108.99.2 to network 0.0.0.0
S* 0.0.0.0/0 [1/0] via 10.108.99.2
10.0.0.0/8 is variably subnetted, 4 subnets, 2 masks
C 10.44.192.0/24 is directly connected, GigabitEthernet0/0
L 10.44.192.1/32 is directly connected, GigabitEthernet0/0
C 10.108.99.0/24 is directly connected, GigabitEthernet0/1
L 10.108.99.1/32 is directly connected, GigabitEthernet0/1
D 192.168.1.0/24 [90/130816] via 10.44.192.2, 00:20:24, GigabitEthernet0/0
R1#show ip route 0.0.0.0 0.0.0.0
Routing entry for 0.0.0.0/0, supernet
Known via "static", distance 1, metric 0, candidate default path
Routing Descriptor Blocks:
* 10.108.99.2
Route metric is 0, traffic share count is 1
Note: If you configure multiple networks as candidate default routes via the ip default-network command, 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 the ip default-network and ip route 0.0.0.0 0.0.0.0 commands to configure candidate default networks, the ip route 0.0.0.0 0.0.0.0 command takes precedence and is chosen for the gateway of last resort. If you use multiple ip route 0.0.0.0 0.0.0.0 commands to configure a default route, traffic is load-balanced over the multiple routes.
Summary
Use the ip default-gateway command when ip routing is disabled on a Cisco router. Use the ip default-network or ip route 0.0.0.0 0.0.0.0 commands to set the gateway of last resort on Cisco routers that have ip routing enabled. The way in which routing protocols propagate the default route information varies for each protocol.
Related Information