> 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/4-ospf-inter-area-filtering.md).

# 4) OSPF Inter-Area Filtering

### Pre-Work

Load the config called **policy.cfg** using the **load\_config\_on\_nodes.py** script.

```
python3 load_config_on_nodes.py --lab_dir three-routers --config_filename policy.cfg
```

### Lab

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

OSPF is already setup between R1 and R2.

Configure R2 to filter all prefixes in area 1 from being advertised into area 0. R1 should no longer have a route for `2.2.2.2/32`.

### Answer

<details>

<summary>Expand to reveal</summary>

```
set policy-options policy-statement block-inter-area from area 1
set policy-options policy-statement block-inter-area then reject
set protocols ospf area 0 network-summary-export block-inter-area
```

</details>

### Explanation

<details>

<summary>Expand to reveal</summary>

OSPF and IS-IS behave like distance vector protocols for inter-area routing. Within the area/level we cannot filter routes, as database synchronization is required. However, between area/level boundaries, we can filter and summarize routes. The same route policies we use for redistribution are used to accomplish IGP inter-area filtering.

\
In this lab, R2's Lo0 is in area 1. R2 creates a type 3 LSA for the `2.2.2.2/32` prefix in area 0:

```
admin@R1> show ospf database    

    OSPF database, Area 0.0.0.0
 Type       ID               Adv Rtr           Seq      Age  Opt  Cksum  Len 
Router  *10.0.0.1         10.0.0.1         0x80000003    41  0x22 0xbc3a  84
Router   10.0.0.2         10.0.0.2         0x80000003    42  0x22 0xf80f  72
Summary  2.2.2.2          10.0.0.2         0x80000002    47  0x22 0xc463  28
```

\
As a consequence of OSPF's distance vector nature for inter-area routing, we have control over how routes are advertised into, or out of, areas. We can apply a basic route policy that filters all routes from area 1 as they are advertised into area 0. We match prefixes from area 1 simply using `from area 1`. We apply this policy to area 0, as routes are exported from other areas into area 0.

```
set policy-options policy-statement block-inter-area from area 1
set policy-options policy-statement block-inter-area then reject
set protocols ospf area 0 network-summary-export block-inter-area
```

\
Note that if you applied this to area 1, you would be filtering routes as they are exported from area 0 into area 1.

\
We should see that R1 no longer has the type 3 LSA in its area 0 database:

```
admin@R1> show ospf database    

    OSPF database, Area 0.0.0.0
 Type       ID               Adv Rtr           Seq      Age  Opt  Cksum  Len 
Router  *10.0.0.1         10.0.0.1         0x80000003   199  0x22 0xbc3a  84
Router   10.0.0.2         10.0.0.2         0x80000003   200  0x22 0xf80f  72


admin@R1> show route protocol ospf   

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

224.0.0.5/32       *[OSPF/10] 00:03:35, metric 1
                       MultiRecv
```

</details>

### Further Reading

<https://www.juniper.net/documentation/us/en/software/junos/ospf/topics/topic-map/configuring-ospf-routing-policy.html#id-example-configuring-an-ospf-export-policy-for-network-summaries>
