OSPF Virtual Links Explained

OSPF uses two layers of hierarchy for OSPF areas: backbone area and non-backbone area. The backbone area is compulsory. Non-backbone areas are optional. All non-backbone areas must have at least one physical link in the backbone area. If the physical connection is not feasible, you can use a virtual link to connect to the backbone through a non-backbone area.

A virtual link connects a non-backbone area to the backbone area via another non-backbone area having a direct connection to the backbone area. The area the virtual link uses to connect the non-backbone and backbone area is called a transit area. A transit area has the following two requirements:-

  • It can not be a stub area.
  • It must have the complete routing information.

OSPF Virtual links packet tracer example

Create a practice lab and assign IP configuration, as shown in the following image.

ospf lab for virtual links

Download Packet Tracer Practice Lab with IP configuration

OSPF Multi-area configuration

Since a virtual link connects a non-backbone area with the backbone area via another non-backbone area, we need three OSPF areas to practice virtual links. We need two non-backbone areas and one backbone area. We can run a router's interfaces in different OSPF areas. We will use the following layout to create two non-backbone areas and one backbone area.

ospf areas

The following commands configure R1's FastEthernet 0/0 in area 0 and FastEthernet 0/1 in area 1.

Router>enable
Router#configure terminal
Router(config)#router ospf 1
Router(config-router)#network 10.0.0.0 0.255.255.255 area 0
Router(config-router)#network 192.168.1.0 0.0.0.255 area 1
Router(config-router)#exit
Router(config)#exit
Router#

ospf configuration on r1

The following commands configure both interfaces of R2 in area 1.

Router>enable
Router#configure terminal
Router(config)#router ospf 1
Router(config-router)#network 192.168.1.0 0.0.0.255 area 1
Router(config-router)#exit
Router(config)#exit
Router#

ospf configuration r2

The following commands configure R3's FastEthernet 0/1 in area 1 and FastEthernet 0/0 in area 2.

Router>enable
Router#configure terminal
Router(config)#router ospf 1
Router(config-router)#network 20.0.0.0 0.255.255.255 area 2
Router(config-router)#network 192.168.1.0 0.255.255.255 area 1
Router(config-router)#exit
Router(config)#exit
Router#

ospf configuration on r3

With the current configuration, this network will not work. R1 and R2 will not learn about the network 20.0.0.0/8. However, all routers will learn about the network 10.0.0.0/8. We can use the show ip route ospf command to verify it.

Download Packet Tracer Practice Lab with OSPF configuration

The following image shows the output of this command on R1.

verify ospf on r1

The network 10.0.0.0/8 is available on the Fa0/1 interface of R1. Since the router learns it from the local interface configuration, this command does not include it in the output.

The following image shows the output of this command on R2.

verify ospf on r2

The following image shows the output of this command on R3.

verify ospf on r3

To understand why R1 and R2 do not learn about the network 20.0.0.0/8, first, we need to know how OSPF routers exchange routing information.

In a multi-area configuration, OSPF routers exchange routing information through the backbone area. Each non-backbone area has at least one ABR (Area Border Router) router. The ABR connects the non-backbone area with the backbone area. The ABR updates the backbone area routers. Then, the backbone area routers share that information with other non-backbone area routers. Routers in different non-backbone areas do not share routing information directly.

how ospf share routing information

In our network, R3 is the ABR for area 2. R2 is the ABR for area 1. R1 is the ABR for the area 0. R2 and R3 are responsible for updating R1 about their respective routes. R2 has a direct physical link with R1. It can exchange routing information with area 0. R3 has no direct link with R0. It has no way to update area 0. Since R3 can not update R1 and R2 depends on R1 to get routing information, R2 and R1 do not learn about the routing information R3 has. Even though R2 and R3 have a direct connection, they can not directly share routing information. Since they belong to different OSPF areas, they can share routing information only through the backbone area.

A physical link between R3 and R1 is not possible. In this situation, we can create a virtual link between these routers. The following OSPF configuration mode command creates a virtual link.

Router(config-router)# area [area-id] virtual-link [RID]

The area-id is the id of the transit area.

The RID is the RID of the other side router of the virtual link.

We run the above command on both routers that connect via the virtual link. In our example, we will connect R1 with R3 via a virtual link. Hence, we need to run this command on them.

ospf area virtual link setup

OSPF RID

Since the above command needs the RID of the other end router, we also need to configure the RID on both routers. An RID is the identity of the OSFP router. When we start an OSPF router, it checks the following three things to pick the RID:-

  1. The value of the router-id command
  2. The highest IP address among all configured IP addresses on Loopback interfaces
  3. The highest IP address among all configured IP addresses on physical interfaces

The router checks these options in the sequence. If it finds an option's value, it uses that value and does not check the next option.

In our example network, we did not configure custom RIDs and loopback interfaces on routers. Without these options, routers will pick the highest IP address from all IP addresses configured on all physical interfaces. The output of the 'show ip ospf interface' command displays the router's RID.

The following image shows the output of this command on R1.

verify default rid

You can also use this command on R2 and R3 to view their RIDs.

Using loopback interfaces for RIDs

A loopback interface always remains up. If we configure a loopback interface and do not configure a custom RID, the router will pick the loopback interface's IP address as the RID.

The following commands configure a loopback interface and assign the IP address 1.1.1.1/8 on R1.

Router#configure terminal
Router(config)#interface loopback 0
Router(config-if)#ip address 1.1.1.1 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#

configure loopback interface on r1

The following commands configure a loopback interface and assign the IP address 2.2.2.2/8 on R2.

Router#configure terminal
Router(config)#interface loopback 0
Router(config-if)#ip address 2.2.2.2 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#

configure loopback interface on r2

The following commands configure a loopback interface and assign the IP address 3.3.3.3/8 on R3.

Router#configure terminal
Router(config)#interface loopback 0
Router(config-if)#ip address 3.3.3.3 255.0.0.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#

configure loopback interface on r3

An OSPF router picks the RID when we start it. Once it picks the RID, it uses the picked RID until it remains up. Because of this, routers will not pick the new RID until we restart them. Routers keep all running configurations in memory. If we restart a router without saving its running configuration, the running configuration will lost.

The following privileged mode command saves the running configuration.

Router#copy run start

Run this command on all routers. After saving the running configuration, use the following command to restart them.

Router#reload

If you are doing this exercise on Packet Tracer, you can save the lab and restart Packet Tracer instead of running the above commands on all routers.

Download Packet Tracer Practice Lab with loopback interfaces configuration

The output of the 'show ip ospf interface' command displays the router's RID. We can use this command to verify the new RID.

The following image shows the output of this command on R1.

verify new rid

Creating a virtual link

The following commands create and enable a virtual link on R1.

Router(config)#router ospf 1
Router(config-router)#area 1 virtual-link 3.3.3.3

configure virtual link on r3

The following commands create and enable a virtual link on R3.

Router(config)#router ospf 1
Router(config-router)#area 1 virtual-link 1.1.1.1

configure virtual link r1

Download Packet Tracer Practice Lab with the virtual link configuration

Verifying the virtual link

R3 will use this virtual link to share its routing information with R1. R1 will share the received routing information with R2. We can view the OSPF neighbors and routing table entries on all routers to verify this.

Verifying on R1

verify ospf

Verifying on R2

verify virtual link on r2

Verifying on R3

verify virtual link on r3

The show ip ospf virtual-links command

The 'show ip ospf virtual-links' command displays the status of all configured virtual links. We can use this command to verify the virtual link we created.

The following image shows the output of this command on R1.

show virtual links on r1

The following image shows the output of this command on R3.

show virtual link on r3

Verifying the OSPF configuration

We can use the ping command to verify OSPF configuration. The ping command sends ping requests to the destination device. If the destination device is up, it responds to the ping requests.

Send ping requests from PC0 to PC1. If PC0 gets replies, it verifies the OSPF configuration.

verify ping

Conclusion

In a multi-area environment, routers share routing information via the backbone area. Since the backbone area propagates all routing updates, all non-backbone areas must have a link with the backbone area. If a physical link is not feasible, we can use a virtual link to connect a non-backbone area with the backbone area.

ComputerNetworkingNotes CCNA Study Guide OSPF Virtual Links Explained