> 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/4-routing-preference.md).

# 4) Routing Preference

### Pre-Work

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

```
python3 load_config_on_nodes.py --lab_dir three-routers --config_filename routing.pref.cfg
```

### Lab

OSPFv2 and OSPFv3 are fully setup. On R1, configure "floating" static routes for R2's loopbacks that will be used if OSPF goes down. When OSPF is up, the OSPF paths should be used.

* `2.2.2.2/32` via `10.1.2.2`
* `2001:db8::2/128` via `2001:db8:1:2::2`

If you disable OSPFv2 and OSPFv3 on R1, you should not lose connectivity to R2's loopback addresses.

### Answer

<details>

<summary>Expand to reveal</summary>

```
set routing-options static route 2.2.2.2/32 next-hop 10.1.2.2 preference 11
set routing-options rib inet6.0 static route 2001:db8::2/128 next-hop 2001:db8:1:2::2 preference 11
```

</details>

### Explanation

<details>

<summary>Expand to reveal</summary>

In IOS, we have "administrative distance," which determines which route should be installed in the FIB when there are competing routes for the same prefix known from different protocols. For example, if both OSPF and RIP offer a route for the same prefix, the route known via OSPF is active and installed in the FIB due to OSPF's lower administrative distance.

\
In Junos, this concept is called route preference. The default route preference values for common protocols are in the table below:

| Protocol                     | Route Preference |
| ---------------------------- | ---------------- |
| Direct (connected) and Local | 0                |
| Static                       | 5                |
| OSPF Internal                | 10               |
| IS-IS Level 1 Internal       | 15               |
| IS-IS Level 2 Internal       | 18               |
| OSPF External                | 150              |
| IS-IS Level 1 External       | 160              |
| IS-IS Level 2 External       | 165              |
| BGP                          | 170              |

\
The route preference can also be seen in the RIB, for example `[OSPF/`**`10`**`]` and `[Static/`**`11`**`]`. The **route preference** controls which route is active when deciding between routes from different source protocols. The **route metric** controls which route is active among competing paths from the same source protocol. For example on the OSPF route, we see `metric 1` - this is the route metric. Notice that the `*` symbol indicates the active route, and the `>` symbol indicates the best path for each route from each protocol.

```
admin@R1# run show route 2.2.2.2 

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

2.2.2.2/32         *[OSPF/10] 00:03:30, metric 1
                    >  to 10.1.2.2 via ge-0/0/0.0
                    [Static/11] 00:01:58
                    >  to 10.1.2.2 via ge-0/0/0.0
```

\
In order to have a "floating" static route, or "backup" static route, we must configure the static routes with a route preference that is worse (higher) than OSPF's route preference. Therefore the minimum acceptable value for this lab is 11. We configure the route preference as an attribute of the static routes:

```
set routing-options static route 2.2.2.2/32 next-hop 10.1.2.2 preference 11
set routing-options rib inet6.0 static route 2001:db8::2/128 next-hop 2001:db8:1:2::2 preference 11
```

</details>

### Further Reading

<https://www.juniper.net/documentation/us/en/software/junos/routing-overview/bgp/topics/concept/routing-protocols-default-route-preference-values.html>

<https://community.juniper.net/discussion/route-preference-and-route-metric>

<https://blog.marquis.co/posts/2015-05-26-jncia-refresher-4-routing-fundamentals/#route-preference>

<https://www.youtube.com/watch?v=TuDx5roGfY0&list=PLDQaRcbiSnqHAGz-wapjtd3zQxUg-a8dU&index=16>

* This is a similar concept but not the same thing as in this lab. Qualified next-hop is when you want a second next-hop on a static route with a different route preference.
