Redistributing Static Routes into OSPF

Redistributing Static Routes into OSPF

Problem

You want OSPF to propagate one or more static routes.

Solution

To redistribute static routes into an OSPF process, use the redistribute static configuration command:

Router1#configure terminal 
Enter configuration commands, one per line. End with CNTL/Z.
Router1(config)#ip route 192.168.10.0 255.255.255.0 172.22.1.4
Router1(config)#ip route 172.24.1.0 255.255.255.0 172.22.1.4
Router1(config)#ip route 10.100.1.0 255.255.255.0 172.22.1.4
Router1(config)#router ospf 55
Router1(config-router)#redistribute static
% Only classful networks will be redistributed
Router1(config-router)#exit
Router1(config)#end
Router1#

Discussion

As the warning message indicates, OSPF will only redistribute classful network routes by default. In the example, we included three static routes. Of these routes, only 192.168.10.0/24 is classful. If we then look at the routing table on a different router, we can see that the other two routes are not present:

Router5#show ip route ospf
O E2 192.168.10.0/24 [110/20] via 172.25.1.5, 00:02:49, Ethernet0
172.16.0.0/24 is subnetted, 1 subnets
O 172.16.2.0 [110/20] via 172.25.1.5, 00:02:49, Ethernet0
172.20.0.0/16 is variably subnetted, 3 subnets, 3 masks
O IA 172.20.10.0/24 [110/1582] via 172.25.1.5, 00:02:49, Ethernet0
O IA 172.20.1.0/30 [110/1572] via 172.25.1.5, 00:02:49, Ethernet0
O IA 172.20.100.1/32 [110/1573] via 172.25.1.5, 00:02:49, Ethernet0
172.22.0.0/24 is subnetted, 1 subnets
O 172.22.1.0 [110/20] via 172.25.1.5, 00:02:49, Ethernet0
172.25.0.0/16 is variably subnetted, 3 subnets, 2 masks
O 172.25.25.1/32 [110/11] via 172.25.1.5, 00:02:49, Ethernet0
10.0.0.0/8 is variably subnetted, 2 subnets, 2 masks
O IA 10.2.2.2/32 [110/1573] via 172.25.1.5, 00:02:49, Ethernet0
O IA 10.1.1.0/30 [110/1572] via 172.25.1.5, 00:02:49, Ethernet0
Router5#

You can ensure that all routes are redistributed, regardless of whether they are classful or not, by including the subnets keyword:

Router1#configure terminal 
Enter configuration commands, one per line. End with CNTL/Z.
Router1(config)#router ospf 55
Router1(config-router)#redistribute static subnets
Router1(config-router)#exit
Router1(config)#end
Router1#

As you can see, all three static routes are advertised now:

Router5#show ip route ospf
O E2 192.168.10.0/24 [110/20] via 172.25.1.5, 00:04:23, Ethernet0
172.16.0.0/24 is subnetted, 1 subnets
O 172.16.2.0 [110/20] via 172.25.1.5, 00:04:23, Ethernet0
172.20.0.0/16 is variably subnetted, 3 subnets, 3 masks
O IA 172.20.10.0/24 [110/1582] via 172.25.1.5, 00:04:23, Ethernet0
O IA 172.20.1.0/30 [110/1572] via 172.25.1.5, 00:04:23, Ethernet0
O IA 172.20.100.1/32 [110/1573] via 172.25.1.5, 00:04:23, Ethernet0
172.22.0.0/24 is subnetted, 1 subnets
O 172.22.1.0 [110/20] via 172.25.1.5, 00:04:23, Ethernet0
172.25.0.0/16 is variably subnetted, 3 subnets, 2 masks
O 172.25.25.1/32 [110/11] via 172.25.1.5, 00:04:23, Ethernet0
172.24.0.0/24 is subnetted, 1 subnets
O E2 172.24.1.0 [110/20] via 172.25.1.5, 00:00:24, Ethernet0
10.0.0.0/8 is variably subnetted, 3 subnets, 3 masks
O IA 10.2.2.2/32 [110/1573] via 172.25.1.5, 00:04:23, Ethernet0
O IA 10.1.1.0/30 [110/1572] via 172.25.1.5, 00:04:23, Ethernet0
O E2 10.100.1.0/24 [110/20] via 172.25.1.5, 00:00:24, Ethernet0
Router5#

Another useful thing to notice about this output is the fact that all of these external static routes are marked as type E2, meaning that they are external routes of Type 2. As we discussed in the Introduction to this chapter, any time you distribute a foreign route into OSPF, it is always considered external. This helps OSPF to ensure that it doesn't create any loops through an external network when there are multiple connection points.

When OSPF distributes Type 2 External routes, it doesn't add the internal link cost to the net route cost. OSPF always prefers Type 1 to Type 2 External routes because Type 1 routes do include the internal path cost in the metric. If you want to distribute static routes as Type 1 instead of the default type 2, you need to include the metric-type keyword in the redistribute static command:

Router1#configure terminal 
Enter configuration commands, one per line. End with CNTL/Z.
Router1(config)#router ospf 55
Router1(config-router)#redistribute static subnets metric 40 metric-type 1
Router1(config-router)#exit
Router1(config)#end
Router1#

In this example, we have also set the default metric for these static routes to a value of 40. Notice that the next hop router now shows the total cost of the path as 60 because it now includes the internal link cost of 20:

Router5#show ip route 192.168.10.0
Routing entry for 192.168.10.0/24
Known via "ospf 87", distance 110, metric 60, type extern 1
Redistributing via ospf 87
Last update from 172.25.1.5 on Ethernet0, 00:01:20 ago
Routing Descriptor Blocks:
* 172.25.1.5, from 172.25.25.1, 00:01:20 ago, via Ethernet0
Route metric is 60, traffic share count is 1
Router5#