Related Documentation
- LN Series
- OSPF Routing Policy Overview
- M Series
- OSPF Routing Policy Overview
- Configuring Match Conditions in Routing Policy Terms
- Configuring Actions in Routing Policy Terms
- MX Series
- OSPF Routing Policy Overview
- PTX Series
- Configuring Match Conditions in Routing Policy Terms
- Configuring Actions in Routing Policy Terms
- T Series
- OSPF Routing Policy Overview
- Configuring Match Conditions in Routing Policy Terms
- Configuring Actions in Routing Policy Terms
Example: Configuring an OSPF Import Policy
This example shows how to create an OSPF import policy. OSPF import policies apply to external routes only. An external route is a route that is outside the OSPF autonomous system (AS).
Requirements
Before you begin:
- Configure static routes. See Examples: Configuring Static Routes.
- Configure the router identifiers for the devices in your OSPF network. See Example: Configuring an OSPF Router Identifier.
- Control OSPF designated router election. See Example: Controlling OSPF Designated Router Election.
- Configure a single-area OSPF network. See Example: Configuring a Single-Area OSPF Network .
Overview
External routes are learned by AS boundary routers. External routes can be advertised throughout the OSPF domain if you configure the AS boundary router to redistribute the route into OSPF. An external route might be learned by the AS boundary router from a routing protocol other than OSPF, or the external route might be a static route that you configure on the AS boundary router.
For OSPFv3, the link-state advertisement (LSA) is referred to as the interarea prefix LSA and performs the same function as a network-summary LSA performs for OSPFv2. An area border router (ABR) originates an interarea prefix LSA for each IPv6 prefix that must be advertised into an area.
OSPF import policy allows you to prevent external routes from being added to the routing tables of OSPF neighbors. The import policy does not impact the OSPF database. This means that the import policy has no impact on the link-state advertisements. The filtering is done only on external routes in OSPF. The intra-area and interarea routes are not considered for filtering. The default action is to accept the route when the route does not match the policy.
This example includes the following OSPF policy settings:
- policy-statement—Defines the routing policy. You specify the name of the policy and further define the elements of the policy. The policy name must be unique and can contain letters, numbers, and hyphens ( - ) and be up to 255 characters long.
- export—Applies the export policy you created to be evaluated when network summary LSAs are flooded into an area. In this example, the export policy is named export_static.
- import—Applies the import policy you created to prevent external routes from being added to the routing table. In this example, the import policy is named filter_routes.
The devices you configure in this example represent the following functions:
- R1—Device R1 is in area 0.0.0.0 and has a direct connection to device R2. R1 has an OSPF export policy configured. The export policy redistributes static routes from R1’s routing table into R1’s OSPF database. Because the static route is in R1’s OSPF database, the route is advertised in an LSA to R1’s OSPF neighbor. R1’s OSPF neighbor is device R2.
- R2—Device R2 is in area 0.0.0.0 and has a direct connection to device R1. R2 has an OSPF import policy configured that matches the static route to the 10.0.16.0/30 network and prevents the static route from being installed in R2’s routing table. R2’s OSPF neighbor is device R1.
Configuration
CLI Quick Configuration
To quickly configure an OSPF import policy, copy the following commands, removing any line breaks, and then paste the commands into the CLI.
Configuration on Device R1:
Configuration on Device R2:
Step-by-Step Procedure
The following example requires you to navigate various levels in the configuration hierarchy. For information about navigating the CLI, see Modifying the Junos OS Configuration in CLI User Guide.
To configure an OSPF import policy:
- Configure the interfaces.[edit]user@R1# set interfaces so-0/2/0 unit 0 family inet address 10.0.2.1/30[edit]user@R2# set interfaces so-0/2/0 unit 0 family inet address 10.0.2.2/30
- Enable OSPF on the interfaces.

Note: For OSPFv3, include the ospf3 statement at the [edit protocols] hierarchy level.
[edit]user@R1# set protocols ospf area 0.0.0.0 interface so-0/2/0[edit]user@R2# set protocols ospf area 0.0.0.0 interface so-0/2/0 - On R1, redistribute the static route into OSPF.[edit]user@R1# set protocols ospf export export_staticuser@R1# set policy-options policy-statement export_static from protocol staticuser@R1# set policy-options policy-statement export_static then accept
- On R2, configure the OSPF import policy.[edit]user@R2# set protocols ospf import filter_routesuser@R2# set policy-options policy-statement filter_routes from route-filter 10.0.16.0/30 exactuser@R2# set policy-options policy-statement filter_routes then reject
- If you are done configuring the devices, commit the configuration.[edit]user@host# commit
Results
Confirm your configuration by entering the show interfaces, show policy-options, and show protocols ospf commands on the appropriate device. If the output does not display the intended configuration, repeat the instructions in this example to correct the configuration.
Output for R1:
Output for R2:
To confirm your OSPFv3 configuration, enter the show interfaces, show policy-options, show routing-options, and show protocols ospf3 commands on the appropriate device.
Verification
Confirm that the configuration is working properly.
Verifying the OSPF Database
Purpose
Verify that OSPF is advertising the static route in the OSPF database.
Action
From operational mode, enter the show ospf database for OSPFv2, and enter the show ospf3 database command for OSPFv3.
Verifying the Routing Table
Purpose
Verify the entries in the routing table.
Action
From operational mode, enter the show route command.
Related Documentation
- LN Series
- OSPF Routing Policy Overview
- M Series
- OSPF Routing Policy Overview
- Configuring Match Conditions in Routing Policy Terms
- Configuring Actions in Routing Policy Terms
- MX Series
- OSPF Routing Policy Overview
- PTX Series
- Configuring Match Conditions in Routing Policy Terms
- Configuring Actions in Routing Policy Terms
- T Series
- OSPF Routing Policy Overview
- Configuring Match Conditions in Routing Policy Terms
- Configuring Actions in Routing Policy Terms

