> 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/5-vrfs.md).

# 5) VRFs

### Pre-Work

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

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

### Lab

Connect to R1, and configure `ge-0/0/0` in a VRF called "R2\_VRF." Configure the addresses as normal: `10.1.2.1/24` and `2001:db8:1:2::1/64`.&#x20;

Run OSPFv2 and OSPFv3 on this VRF, and form an adjacency with R2 using a `p2p` interface-type. R2 is already pre-configured.

### Answer

<details>

<summary>Expand to reveal</summary>

```
set interfaces ge-0/0/0.0 family inet address 10.1.2.1/24
set interfaces ge-0/0/0.0 family inet6 address 2001:db8:1:2::1/64
set routing-instances R2_VRF instance-type virtual-router
set routing-instances R2_VRF interface ge-0/0/0.0
set routing-instances R2_VRF protocols ospf area 0 interface ge-0/0/0.0 interface-type p2p
set routing-instances R2_VRF protocols ospf3 area 0 interface ge-0/0/0.0 interface-type p2p
```

</details>

### Explanation

<details>

<summary>Expand to reveal</summary>

On Junos, VRFs are configured under the `routing-instance` stanza. You define the routing-instance with a type of `virtual-router`.&#x20;

```
set routing-instance <name> instance-type virtual-router
```

\
Interfaces are associated under the routing-instance, not under the interface config as in IOS.

```
set routing-instance <name> interface <logical interface name>
```

\
Interface IP address configuration still belongs under the `interfaces` configuration, but configuration like routing protocols, static routes, etc., goes directly under the `routing-instance` configuration.

```
set routing-instance <name> routing-options static route ...
set routing-instance <name> protocols ospf ...
```

\
Besides `virtual-router`, there are instance-types such as `virtual-switch`, `vpls`, `nonforwarding` (for filter-based forwarding, also known as PBR), etc. There is also a type of `vrf`. You might wonder why we didn't use this, and what the difference is. Type `virtual-router` is similar to "VRF lite" on IOS. VRF lite means you are using VRFs without doing MPLS L3VPN - simply creating a separate routing table and placing interfaces in this table, running routing protocols in this table, etc. Type `vrf` would be L3VPN and requires RDs and RTs, which is not what we are doing here.

\
Show and operational commands reference the routing-instance name using keywords like `instance` and `routing-instance`. Also note that the table names are `<routing-instance name>.inet.0` and `<routing-instance name>.inet6.0`.

```
admin@R1> show route instance R2_VRF 
Instance             Type
         Primary RIB                                     Active/holddown/hidden
R2_VRF               virtual-router 
         R2_VRF.inet.0                                   6/0/0
         R2_VRF.inet6.0                                  8/0/0


admin@R1> show route table R2_VRF.inet.0 

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

2.2.2.2/32         *[OSPF/10] 00:01:10, metric 1
                    >  to 10.1.2.2 via ge-0/0/0.0
3.3.3.3/32         *[OSPF/10] 00:01:10, metric 2
                    >  to 10.1.2.2 via ge-0/0/0.0
10.1.2.0/24        *[Direct/0] 00:01:19
                    >  via ge-0/0/0.0
10.1.2.1/32        *[Local/0] 00:01:19
                       Local via ge-0/0/0.0
10.2.3.0/24        *[OSPF/10] 00:01:10, metric 2
                    >  to 10.1.2.2 via ge-0/0/0.0
224.0.0.5/32       *[OSPF/10] 00:01:20, metric 1
                       MultiRecv


admin@R1> show route table R2_VRF.inet6.0 

R2_VRF.inet6.0: 8 destinations, 8 routes (8 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both

2001:db8::2/128    *[OSPF3/10] 00:01:13, metric 1
                    >  to fe80::aac1:abff:fe63:ff25 via ge-0/0/0.0
2001:db8::3/128    *[OSPF3/10] 00:01:13, metric 2
                    >  to fe80::aac1:abff:fe63:ff25 via ge-0/0/0.0
2001:db8:1:2::/64  *[Direct/0] 00:01:14
                    >  via ge-0/0/0.0
2001:db8:1:2::1/128*[Local/0] 00:01:14
                       Local via ge-0/0/0.0
2001:db8:2:3::/64  *[OSPF3/10] 00:01:13, metric 2
                    >  to fe80::aac1:abff:fe63:ff25 via ge-0/0/0.0
fe80::aac1:abff:fe01:1eba/128
                   *[Local/0] 00:01:14
                       Local via ge-0/0/0.0
ff02::2/128        *[INET6/0] 00:01:25
                       MultiRecv
ff02::5/128        *[OSPF3/10] 00:01:25, metric 1
                       MultiRecv
```

\
View interfaces in the routing instance:

```
admin@R1> show interfaces terse routing-instance R2_VRF 
Interface               Admin Link Proto    Local                 Remote
ge-0/0/0.0              up    up   inet     10.1.2.1/24     
                                   inet6    2001:db8:1:2::1/64
                                            fe80::aac1:abff:fe01:1eba/64
                                   multiservice
```

\
Ping within the routing-instance:

```
admin@R1> ping 3.3.3.3 routing-instance R2_VRF 
PING 3.3.3.3 (3.3.3.3): 56 data bytes
64 bytes from 3.3.3.3: icmp_seq=0 ttl=63 time=2.749 ms
64 bytes from 3.3.3.3: icmp_seq=1 ttl=63 time=2.476 ms
```

\
View OSPF output in the routing-instance:

```
admin@R1> show ospf neighbor instance R2_VRF 
Address          Interface              State           ID               Pri  Dead
10.1.2.2         ge-0/0/0.0             Full            10.0.0.2         128    33

admin@R1> show ospf3 neighbor instance R2_VRF 
ID               Interface              State     Pri   Dead
10.0.0.2         ge-0/0/0.0             Full      128     38
  Neighbor-address fe80::aac1:abff:fe63:ff25
```

</details>

### Further Reading

<https://www.juniper.net/documentation/us/en/software/junos/routing-overview/topics/concept/routing-instances-overview.html>

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

<https://community.juniper.net/discussion/instance-type-vrf-vs-virtual-router>

<https://www.reddit.com/r/networking/comments/4u7mr3/question_about_junos_vrfs_and_ipsec_vpns/>
