Redistribute Routes into OSPF
1. Use the source route’s cost if from another OSPF process
2. Cost is 1 for routes learned from BGP
3. Cost is 20 for all other routes
External Type 1 OSPF routes have incrementing costs.
External Type 2 OSPF routes maintain the same cost throughout the AS and are the default type when redistributing.
So, for the most part routes will be external type 2 and have a cost of 20 by default unless you are using BGP (say, for either an Internet connection or MPLS configuration),
in which case those routes will have a cost of 1. If you are running two OSPF processes and redistributing between them, then the cost is carried over.
But what if you want to manipulate the cost of those routes? Here area few examples on how to go about doing that.
Set the default for all redistributed routes:
RedistributeRouter(config)# router ospf 1
RedistributeRouter(config-router)# default-metric 37
RedistributeRouter(config-router)# redistribute eigrp 1 subnets
R3#show ip route
…
10.0.0.0/24 is subnetted, 3 subnets
O E2 10.1.10.0 [110/37] via 172.20.0.1, 00:00:50, FastEthernet0/0
O E2 10.1.1.0 [110/37] via 172.20.0.1, 00:00:50, FastEthernet0/0
O E2 10.1.0.0 [110/37] via 172.20.0.1, 00:00:50, FastEthernet0/0
Notice the metric is set to the cost of 37 configured above instead of 20. This would apply to any of the routes that are being redistributed into that OSPF process.
Setting the metric for route source :
The alternative to setting metric for all redistributed routes under a process is to specify a metric for the specific source of the routes under the redistribute router subcommand.
router ospf 10
log-adjacency-changes
redistribute eigrp 1 metric 61 subnets
network 172.20.10.0 0.0.0.255 area 1
network 172.20.0.0 0.0.255.255 area 0
default-metric 37
R3#show ip route
…
10.0.0.0/24 is subnetted, 3 subnets
O E2 10.1.10.0 [110/61] via 172.20.0.1, 00:00:04, FastEthernet0/0
O E2 10.1.1.0 [110/61] via 172.20.0.1, 00:00:04, FastEthernet0/0
O E2 10.1.0.0 [110/61] via 172.20.0.1, 00:00:04, FastEthernet0/0
Notice the default-metric 37 subcommand has no effect when the metric keyword is used in the redistribute subcommand.
Setting different metrics for routes learned from a single source :
Using a route-map in the redistribute command gives you very granular control over what metric is set for specific networks. The following example matches one of the three networks being redistributed into OSPF and sets a higher cost for that route. The previous configured metric setting in the redistribute command is still applied to all other routes.
router ospf 10
log-adjacency-changes
redistribute eigrp 1 metric 61 subnets route-map TAG
network 172.20.10.0 0.0.0.255 area 1
network 172.20.0.0 0.0.255.255 area 0
default-metric 37
!
access-list 7 permit 10.1.1.0 0.0.0.255
!
route-map TAG permit 10
match ip address 7
set metric 750
!
route-map TAG permit 20
R3#show ip route
10.0.0.0/24 is subnetted, 3 subnets
O E2 10.1.10.0 [110/61] via 172.20.0.1, 00:00:11, FastEthernet0/0
O E2 10.1.1.0 [110/750] via 172.20.0.1, 00:02:34, FastEthernet0/0
O E2 10.1.0.0 [110/61] via 172.20.0.1, 00:00:11, FastEthernet0/0
Keep in mind, the second statement in the route-map TAG has to be there if you want the remaining routes to be permitted. Not having that line in the route-map has a similar effect as an access control list and Denies all remaining routes that don’t match! Definitely not something to be trying on a production network.
Hopefully these examples help explain the ways to modify the default metric values when redistributing routes into OSPF.