> For the complete documentation index, see [llms.txt](https://jncia-workbook.gitbook.io/workbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jncia-workbook.gitbook.io/workbook/junos-routing-policy/5-ospf-local-rib-filtering.md).

# 5) OSPF Local RIB Filtering

### Pre-Work

Load the config called **static.redist.challenge.cfg** using the **load\_config\_on\_nodes.py** script.

```
python3 load_config_on_nodes.py --lab_dir three-routers --config_filename static.redist.challenge.cfg
```

### Lab

<figure><img src="/files/E1JHkfEkeEQBB1pnw1jz" alt=""><figcaption></figcaption></figure>

OSPF is already setup between R1 and R2. R1 is redistributing static routes into OSPF.

Configure R2 to filter all external prefixes from being installed into its local RIB.

### Answer

<details>

<summary>Expand to reveal</summary>

```
set policy-options policy-statement BLOCK_EXTERNALS then reject

set protocols ospf import BLOCK_EXTERNALS
```

</details>

### Explanation

<details>

<summary>Expand to reveal</summary>

In all previous labs, we have been using **export** policies. These control the export of routes from the RIB into a protocol such as OSPF or BGP. Essentially, export policies are redistribution policies.

\
In this lab, we see the use for **import** policies. These control how routes are received from routing sources and installed/imported into the RIB.

\
Junos does not allow you to be able to filter intra/inter-area routes from being installed into the RIB. Note that this capability does exist on IOS using a `distribute-list in` under the `router ospf` process. However, Junos *does* allow us to filter OSPF external routes from being installed in the RIB. LSA flooding is not affected by this; import policy only affects local installation of routes into the RIB.

> In the `import` statement, you list the name of the routing policy used to filter OSPF external routes from being installed into the routing tables of OSPF neighbors. You can filter the routes, but not link-state address (LSA) flooding. An external route is a route that is outside the OSPF Autonomous System (AS). The import policy does not impact the OSPF database. This means that the import policy has no impact on the link-state advertisements. The default import policy for OSPF is to accept all learned routes and import them into the routing table.

<https://www.juniper.net/documentation/us/en/software/junos/ospf/topics/topic-map/configuring-ospf-routing-policy.html#id-understanding-ospf-routing-policy>

\
Since this feature only blocks external routes, we can simply match everything in the route filter.

```
set policy-options policy-statement BLOCK_EXTERNALS then reject

set protocols ospf import BLOCK_EXTERNALS
```

\
We should see that the external routes that R1 is redistributing are no longer present in the routing table on R2:

```
admin@R2> show route protocol ospf   

inet.0: 9 destinations, 9 routes (9 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

1.1.1.1/32         *[OSPF/10] 00:01:23, metric 1
                    >  to 10.1.2.1 via ge-0/0/0.0
                       to 10.101.102.1 via ge-0/0/3.0
224.0.0.5/32       *[OSPF/10] 00:01:33, metric 1
                       MultiRecv
```

\
The type 5 LSAs are still present in the LSDB on R2, they are just blocked from being installed in the RIB:

```
admin@R2> show ospf database external 
    OSPF AS SCOPE link state database
 Type       ID               Adv Rtr           Seq      Age  Opt  Cksum  Len 
Extern   10.0.0.0         10.0.0.1         0x80000001   131  0x22 0xfe15  36
Extern   10.0.1.0         10.0.0.1         0x80000001   131  0x22 0xf31f  36
Extern   10.2.0.0         10.0.0.1         0x80000001   131  0x22 0xe62b  36
```

</details>

### Further Reading

<https://www.juniper.net/documentation/us/en/software/junos/ospf/topics/topic-map/configuring-ospf-routing-policy.html#id-understanding-ospf-routing-policy>
