Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

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).


Before you begin:


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 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 and has a direct connection to device R1. R2 has an OSPF import policy configured that matches the static route to the network and prevents the static route from being installed in R2’s routing table. R2’s OSPF neighbor is device R1.


CLI Quick Configuration

To quickly configure an OSPF import policy, paste them into a text file, remove any line breaks, change any details necessary to match your network configuration, copy and paste the commands into the CLI at the [edit] hierarchy level, and then enter commit from configuration mode.

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 theCLI User Guide.

To configure an OSPF import policy:

  1. Configure the interfaces.
  2. Enable OSPF on the interfaces.Note

    For OSPFv3, include the ospf3 statement at the [edit protocols] hierarchy level.

  3. On R1, redistribute the static route into OSPF.
  4. On R2, configure the OSPF import policy.
  5. If you are done configuring the devices, commit the configuration.


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.


Confirm that the configuration is working properly.

Verifying the OSPF Database


Verify that OSPF is advertising the static route in the OSPF database.


From operational mode, enter the show ospf database for OSPFv2, and enter the show ospf3 database command for OSPFv3.

Verifying the Routing Table


Verify the entries in the routing table.


From operational mode, enter the show route command.

Related Documentation