I've been playing around with static routes and saw some things going on that I don't understand. I feel like I'm overlooking something simple but I'm not sure what it is. I tried to boil it down to just the relevant examples to explain the issues so if I left anything out let me know. R1 and R2 are connected by 2 serial interfaces:
R1:
interface Serial0/0
ip address 10.1.1.1 255.255.255.0
interface Serial0/1
ip address 192.168.1.1 255.255.255.252
R2:
interface Serial0/0
ip address 10.1.1.2 255.255.255.0
interface Serial0/1
ip address 192.168.1.2 255.255.255.252
If I configure a static default route with an exit interface, it seems that other static routes configured with a next-hop that matches the default route are only added if no subnets of the major network for the next-hop exist:
R1(config)#do debug ip routing
R1(config)#ip route 0.0.0.0 0.0.0.0 s0/0
Mar 1 03:48:23.995: RT: add 0.0.0.0/0 via 0.0.0.0, static metric [1/0]
Mar 1 03:48:23.999: RT: NET-RED 0.0.0.0/0
Mar 1 03:48:23.999: RT: default path is now 0.0.0.0 via 0.0.0.0
Mar 1 03:48:23.999: RT: new default network 0.0.0.0
Mar 1 03:48:24.003: RT: NET-RED 0.0.0.0/0
R1(config)#do sh ip rou
Codes: 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
Gateway of last resort is 0.0.0.0 to network 0.0.0.0
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial0/0
192.168.1.0/30 is subnetted, 1 subnets
C 192.168.1.0 is directly connected, Serial0/1
S* 0.0.0.0/0 is directly connected, Serial0/0
R1(config)#ip route 1.0.0.0 255.0.0.0 20.1.1.1
Mar 1 03:52:12.559: RT: SET_LAST_RDB for 1.0.0.0/8
NEW rdb: via 20.1.1.1
Mar 1 03:52:12.559: RT: add 1.0.0.0/8 via 20.1.1.1, static metric [1/0]
Mar 1 03:52:12.563: RT: NET-RED 1.0.0.0/8
R1(config)#ip route 2.0.0.0 255.0.0.0 10.1.1.2
Mar 1 03:53:01.187: RT: SET_LAST_RDB for 2.0.0.0/8
NEW rdb: via 10.1.1.2
Mar 1 03:53:01.187: RT: add 2.0.0.0/8 via 10.1.1.2, static metric [1/0]
Mar 1 03:53:01.191: RT: NET-RED 2.0.0.0/8
R1(config)#ip route 3.0.0.0 255.0.0.0 10.1.2.2
R1(config)#ip route 4.0.0.0 255.0.0.0 192.168.1.2
Mar 1 03:56:36.763: RT: SET_LAST_RDB for 4.0.0.0/8
NEW rdb: via 192.168.1.2
Mar 1 03:56:36.767: RT: add 4.0.0.0/8 via 192.168.1.2, static metric [1/0]
Mar 1 03:56:36.767: RT: NET-RED 4.0.0.0/8
R1(config)#ip route 5.0.0.0 255.0.0.0 192.168.1.6
R1(config)#do sh ip rou
Codes: 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
Gateway of last resort is 0.0.0.0 to network 0.0.0.0
S 1.0.0.0/8 [1/0] via 20.1.1.1
S 2.0.0.0/8 [1/0] via 10.1.1.2
S 4.0.0.0/8 [1/0] via 192.168.1.2
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial0/0
192.168.1.0/30 is subnetted, 1 subnets
C 192.168.1.0 is directly connected, Serial0/1
S* 0.0.0.0/0 is directly connected, Serial0/0
The most specific match for the next-hop of 1.0.0.0 is the default route. No subnets of the major network 20.0.0.0 exist. 1.0.0.0 is added to the routing table.
The most specific match for the next-hop of 2.0.0.0 and 4.0.0.0 are the directly connected routes, and both of them are added to the routing table.
The most specific match for the next-hop of 3.0.0.0 and 5.0.0.0 is the default route. Other subnets of 10.0.0.0 and 192.168.1.0 exist but none that match the next hop. Neither route is added to the routing table.
If I configure any type of static route besides a default route with an exit interface, this behavior no longer happens and other static routes configured with a next-hop that matches the route are added even if other subnets of the major network for the next-hop exist:
<all previous ip route statements deleted>
R1(config)#ip route 0.0.0.0 128.0.0.0 s0/0
Mar 1 03:57:56.547: RT: SET_LAST_RDB for 0.0.0.0/1
NEW rdb: is directly connected
Mar 1 03:57:56.551: RT: add 0.0.0.0/1 via 0.0.0.0, static metric [1/0]
Mar 1 03:57:56.551: RT: NET-RED 0.0.0.0/1
R1(config)#ip route 128.0.0.0 128.0.0.0 s0/0
Mar 1 03:58:13.375: RT: SET_LAST_RDB for 128.0.0.0/1
NEW rdb: is directly connected
Mar 1 03:58:13.375: RT: add 128.0.0.0/1 via 0.0.0.0, static metric [1/0]
Mar 1 03:58:13.375: RT: NET-RED 128.0.0.0/1
R1(config)#do sh ip rou
Codes: 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
Gateway of last resort is not set
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial0/0
192.168.1.0/30 is subnetted, 1 subnets
C 192.168.1.0 is directly connected, Serial0/1
S 0.0.0.0/1 is directly connected, Serial0/0
S 128.0.0.0/1 is directly connected, Serial0/0
R1(config)#ip route 1.0.0.0 255.0.0.0 20.1.1.1
Mar 1 04:00:29.119: RT: SET_LAST_RDB for 1.0.0.0/8
NEW rdb: via 20.1.1.1
Mar 1 04:00:29.119: RT: add 1.0.0.0/8 via 20.1.1.1, static metric [1/0]
Mar 1 04:00:29.123: RT: NET-RED 1.0.0.0/8
R1(config)#ip route 2.0.0.0 255.0.0.0 10.1.1.2
Mar 1 04:00:37.359: RT: SET_LAST_RDB for 2.0.0.0/8
NEW rdb: via 10.1.1.2
Mar 1 04:00:37.359: RT: add 2.0.0.0/8 via 10.1.1.2, static metric [1/0]
Mar 1 04:00:37.359: RT: NET-RED 2.0.0.0/8
R1(config)#ip route 3.0.0.0 255.0.0.0 10.1.2.2
Mar 1 04:00:43.263: RT: SET_LAST_RDB for 3.0.0.0/8
NEW rdb: via 10.1.2.2
Mar 1 04:00:43.263: RT: add 3.0.0.0/8 via 10.1.2.2, static metric [1/0]
Mar 1 04:00:43.267: RT: NET-RED 3.0.0.0/8
R1(config)#ip route 4.0.0.0 255.0.0.0 192.168.1.2
Mar 1 04:00:50.231: RT: SET_LAST_RDB for 4.0.0.0/8
NEW rdb: via 192.168.1.2
Mar 1 04:00:50.235: RT: add 4.0.0.0/8 via 192.168.1.2, static metric [1/0]
Mar 1 04:00:50.235: RT: NET-RED 4.0.0.0/8
R1(config)#ip route 5.0.0.0 255.0.0.0 192.168.1.6
Mar 1 04:00:56.483: RT: SET_LAST_RDB for 5.0.0.0/8
NEW rdb: via 192.168.1.6
Mar 1 04:00:56.483: RT: add 5.0.0.0/8 via 192.168.1.6, static metric [1/0]
Mar 1 04:00:56.483: RT: NET-RED 5.0.0.0/8
R1(config)#do sh ip rou
Codes: 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
Gateway of last resort is not set
S 1.0.0.0/8 [1/0] via 20.1.1.1
S 2.0.0.0/8 [1/0] via 10.1.1.2
S 3.0.0.0/8 [1/0] via 10.1.2.2
S 4.0.0.0/8 [1/0] via 192.168.1.2
S 5.0.0.0/8 [1/0] via 192.168.1.6
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial0/0
192.168.1.0/30 is subnetted, 1 subnets
C 192.168.1.0 is directly connected, Serial0/1
S 0.0.0.0/1 is directly connected, Serial0/0
S 128.0.0.0/1 is directly connected, Serial0/0
3.0.0.0 and 5.0.0.0 were added this time, unlike with the default route.
If I configure a static default route with a next-hop, no other static routes with a next-hop that matches the default route as it's best match are added to the routing table:
<all previous ip route statements deleted>
R1(config)#ip route 0.0.0.0 0.0.0.0 10.1.1.2
Mar 1 04:08:37.607: RT: SET_LAST_RDB for 0.0.0.0/0
NEW rdb: via 10.1.1.2
Mar 1 04:08:37.607: RT: add 0.0.0.0/0 via 10.1.1.2, static metric [1/0]
Mar 1 04:08:37.611: RT: NET-RED 0.0.0.0/0
Mar 1 04:08:37.611: RT: default path is now 0.0.0.0 via 10.1.1.2
Mar 1 04:08:37.611: RT: new default network 0.0.0.0
Mar 1 04:08:37.611: RT: NET-RED 0.0.0.0/0
R1(config)#do sh ip rou
Codes: 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
Gateway of last resort is 10.1.1.2 to network 0.0.0.0
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial0/0
192.168.1.0/30 is subnetted, 1 subnets
C 192.168.1.0 is directly connected, Serial0/1
S* 0.0.0.0/0 [1/0] via 10.1.1.2
R1(config)#ip route 1.0.0.0 255.0.0.0 20.1.1.1
R1(config)#ip route 2.0.0.0 255.0.0.0 10.1.1.2
R1(config)#ip route 3.0.0.0 255.0.0.0 10.1.2.2
R1(config)#ip route 4.0.0.0 255.0.0.0 192.168.1.2
R1(config)#ip route 5.0.0.0 255.0.0.0 192.168.1.6
Mar 1 04:10:17.687: RT: SET_LAST_RDB for 2.0.0.0/8
NEW rdb: via 10.1.1.2
Mar 1 04:10:17.687: RT: add 2.0.0.0/8 via 10.1.1.2, static metric [1/0]
Mar 1 04:10:17.687: RT: NET-RED 2.0.0.0/8
Mar 1 04:10:17.935: RT: SET_LAST_RDB for 4.0.0.0/8
NEW rdb: via 192.168.1.2
Mar 1 04:10:17.935: RT: add 4.0.0.0/8 via 192.168.1.2, static metric [1/0]
Mar 1 04:10:17.935: RT: NET-RED 4.0.0.0/8
R1(config)#do sh ip rou
Codes: 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
Gateway of last resort is 10.1.1.2 to network 0.0.0.0
S 2.0.0.0/8 [1/0] via 10.1.1.2
S 4.0.0.0/8 [1/0] via 192.168.1.2
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial0/0
192.168.1.0/30 is subnetted, 1 subnets
C 192.168.1.0 is directly connected, Serial0/1
S* 0.0.0.0/0 [1/0] via 10.1.1.2
Only 2.0.0.0 and 4.0.0.0, which had better matches than the default route were added.
If I configure a non-default static route with a next-hop, more specific static routes that match it are not put in the routing table but less specific routes are:
<all previous ip route statements deleted>
R1(config)#ip route 2.0.0.0 255.0.0.0 10.1.1.2
Mar 1 04:22:18.731: RT: SET_LAST_RDB for 2.0.0.0/8
NEW rdb: via 10.1.1.2
Mar 1 04:22:18.731: RT: add 2.0.0.0/8 via 10.1.1.2, static metric [1/0]
Mar 1 04:22:18.735: RT: NET-RED 2.0.0.0/8
R1(config)#ip route 2.0.0.0 255.128.0.0 2.255.1.1
R1(config)#ip route 2.0.0.0 254.0.0.0 2.255.1.1
Mar 1 04:22:49.967: RT: SET_LAST_RDB for 2.0.0.0/7
NEW rdb: via 2.255.1.1
Mar 1 04:22:49.967: RT: add 2.0.0.0/7 via 2.255.1.1, static metric [1/0]
Mar 1 04:22:49.971: RT: NET-RED 2.0.0.0/7
R1(config)#do sh ip rou
Codes: 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
Gateway of last resort is not set
S 2.0.0.0/8 [1/0] via 10.1.1.2
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, Serial0/0
192.168.1.0/30 is subnetted, 1 subnets
C 192.168.1.0 is directly connected, Serial0/1
S 2.0.0.0/7 [1/0] via 2.255.1.1
2.0.0.0/7 is added but 2.0.0.0/9 is not even though both have 2.0.0.0/8 as the best match for their next-hop. This seems like possibly a measure to prevent a route from being self recursive but in this case the next-hop for 2.0.0.0/9 is outside of it's own range so 2.0.0.0/8 would be the best match even if 2.0.0.0/9 was in the routing table.
Can anyone explain to me why these things are happening?