Configuring an OSPFv2 distribution list using route maps

You can manage an OSPFv2 distribution list using route maps that apply match operations as defined by an ACL or an IP prefix list. You can also use other options available within the route maps and ACLs to further control the contents of the routes that OSPFv2 provides to the IP route table. This section describes an example of an OSPFv2 distribution list using a route map to specify an OSPFv2 administrative distance for routes identified by an IP prefix list.

To configure an OSPFv2 distribution list using route maps:

  • Configure a route map that identifies the routes you want to manage
  • Optionally configure an OSPFv2 administrative distance to apply to the OSPFv2 routes
  • Configure an OSPFv2 distribution list that uses the route map as input

In the following example, the first two commands identify two routes using the ip prefix-list test1 command. Next, a route map is created using the prefix-list test1 command to identify the two routes and the set distance command to set the OSPFv2 administrative distance of those routes to 200. A distribution list is then configured under the OSPFv2 configuration that uses the route map named “setdistance” as input.

device(config)# ip prefix-list test1 seq 5 permit 10.0.0.2/32 
device(config)# ip prefix-list test1 seq 10 permit 10.102.1.0/24 
device(config)# route-map setdistance permit 1
device(config-routemap setdistance)# match ip address prefix-list test1
device(config-routemap setdistance)# set distance 200
device(config-routemap setdistance)# exit
device(config)# route-map setdistance permit 2
device(config-routemap setdistance)# exit
device(config)# router ospf
device(config-ospf-router)# area 0
device(config-ospf-router)# area 1
device(config-ospf-router)# distribute-list route-map setdistance in
device(config-ospf-router)# exit

Once this configuration is implemented, the routes identified by the ip prefix-list command and matched in the route map will have their OSPFv2 administrative distance set to 200. This is displayed in the output from the show ip route command, as shown below.

device# show ip route
Total number of IP routes: 4
Type Codes - B:BGP D:Connected O:OSPF R:RIP S:Static; Cost - Dist/Metric
BGP  Codes - i:iBGP e:eBGP
OSPF Codes - i:Inter Area 1:External Type 1 2:External Type 2
        Destination        Gateway         Port          Cost          Type Uptime
1       10.0.0.2/32        10.1.1.2        ve 100        200/501       O    1h3m
2       10.102.1.0/24      10.1.1.2        ve 100        200/2         O    1h3m
3       10.102.6.0/24      10.1.1.2        ve 100        110/2         O    1h3m
4       10.102.8.0/30      DIRECT          ve 100        0/0           D    1h4m

Routes 1 and 2 demonstrate the actions of the example configuration as both display an OSPFv2 administrative distance value of 200. Note that the value is applied to both OSPFv2 learned routes that match the route-map instance containing the set distance clause. The other OSPFv2 route (route 3), which does not match the relevant instance, continues to have the default OSPFv2 administrative distance of 110.