As you might have learned in CCNA or CCNP, OSPF will use cost as the metric to choose the shortest path for each destination, this is true but it’s not entirely correct. OSPF will first look at the “type of path” to make a decision and, secondly look at the metric. This is the preferred path list that OSPF uses:
- Intra-Area (O)
- Inter-Area (O IA)
- External Type 1 (E1)
- NSSA Type 1 (N1)
- External Type 2 (E2)
- NSSA Type 2 (N2)
After the path selection, it will look at the lowest-cost path. To give a quick example…when Prefix “X” is learned as an intra-area route (O) and as an inter-area route (O IA), then OSPF will always select the intra-area route, even if the inter-area route has a lower cost.
Since Cisco IOS release 15.1(2)S, Cisco uses the path selection order from RFC 3101, which obsoletes RFC 1587. This means that it prefers N1 routes before E1 and N2 over E2 routes. In other words, the preferred path list is O > O IA > N1 > E1 > N2 > E2.
I will demonstrate this behavior to you using the following topology:

We will create a loopback0 interface on R2 – R7 using the same prefix 1.1.1.1/32 and advertise it in OSPF as following:
- R2: Intra-Area (O)
- R3: Inter-Area (O IA)
- R4: External Type 1 (E1)
- R5: External Type 2 (E2)
- R6: NSSA Type 1 (N1)
- R7: NSSA Type 2 (N2)
We will check R1 to see what path it will prefer. Let’s configure OSPF first:
R1(config)#router ospf 1
R1(config-router)#router-id 11.11.11.11
R1(config-router)#network 192.168.12.0 0.0.0.255 area 0
R1(config-router)#network 192.168.13.0 0.0.0.255 area 0
R1(config-router)#network 192.168.14.0 0.0.0.255 area 0
R1(config-router)#network 192.168.15.0 0.0.0.255 area 0
R1(config-router)#network 192.168.16.0 0.0.0.255 area 167
R1(config-router)#network 192.168.17.0 0.0.0.255 area 167
R1(config-router)#area 167 nssa
First, we’ll advertise the correct areas on R1. Don’t forget to make area 167 the NSSA area. Let’s continue with the other routers:
R2(config)#router ospf 1
R2(config-router)#router-id 22.22.22.22
R2(config-router)#network 192.168.12.0 0.0.0.255 area 0
R2(config-router)#network 1.1.1.1 0.0.0.0 area 0
On R2, we will advertise 1.1.1.1/32 as an intra-area route.
R3(config)#router ospf 1
R3(config-router)#router-id 33.33.33.33
R3(config-router)#network 192.168.13.0 0.0.0.255 area 0
R3(config-router)#network 1.1.1.1 0.0.0.0 area 3
R3 will advertise 1.1.1.1/32 in area 3 to make it an inter-area route.
R4(config)#router ospf 1
R4(config-router)#router-id 44.44.44.44
R4(config-router)#network 192.168.14.0 0.0.0.255 area 0
R4(config-router)#redistribute connected subnets metric-type 1
R4 will redistribute prefix 1.1.1.1/32 as an external type 1 route.
R5(config-if)#router ospf 1
R5(config-router)#router-id 55.55.55.55
R5(config-router)#network 192.168.15.0 0.0.0.255 area 0
R5(config-router)#redistribute connected subnets metric-type 2
R5 will redistribute prefix 1.1.1.1/32 as an external type 2 route.
R6(config)#router ospf 1
R6(config-router)#router-id 66.66.66.66
R6(config-router)#network 192.168.16.0 0.0.0.255 area 167
R6(config-router)#redistribute connected subnets metric-type 1
R6(config-router)#area 167 nssa
R6 is an NSSA ABR and will advertise 1.1.1.1/32 as an N1 route.
R7(config)#router ospf 1
R7(config-router)#router-id 77.77.77.77
R7(config-router)#network 192.168.17.0 0.0.0.255 area 167
R7(config-router)#redistribute connected subnets metric-type 2
R7(config-router)#area 167 nssa
Lastly, R7 will redistribute 1.1.1.1/32, so it shows up as an N2 route.
Since I’m creating a loopback interface with the same IP address on router R2-R7, we will have duplicate OSPF router ids. Make sure you make them unique on each router with the router-id
command.
Let’s verify our configuration:
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
55.55.55.55 1 FULL/BDR 00:00:38 192.168.15.5 FastEthernet0/3
44.44.44.44 1 FULL/BDR 00:00:38 192.168.14.4 FastEthernet0/2
33.33.33.33 1 FULL/BDR 00:00:38 192.168.13.3 FastEthernet0/1
22.22.22.22 1 FULL/BDR 00:00:37 192.168.12.2 FastEthernet0/0
77.77.77.77 1 FULL/BDR 00:00:30 192.168.17.7 FastEthernet0/5
66.66.66.66 1 FULL/BDR 00:00:39 192.168.16.6 FastEthernet0/4
All OSPF neighbor adjacencies are working. Let’s take a look at the routing table to see what path OSPF has decided to use:
R1#show ip route ospf
1.0.0.0/32 is subnetted, 1 subnets
O 1.1.1.1 [110/2] via 192.168.12.2, 00:07:55, FastEthernet0/0
Above, you see that R1 has decided to use the path to R2 to reach 1.1.1.1/32. The loopback and FastEthernet interface each have a cost of 1, so the total cost is 2. This path has been selected because it’s an intra-area route. What do you think will happen if we increase the cost? Let’s find out:
R2(config)#interface loopback 0
R2(config-if)#ip ospf cost 1000
Let’s change the cost to 1000, so this route isn’t very interesting anymore, and check the routing table:
R1#show ip route ospf
1.0.0.0/32 is subnetted, 1 subnets
O 1.1.1.1 [110/1001] via 192.168.12.2, 00:02:02, FastEthernet0/0
The cost has been increased to 1001, but R1 still prefers the path to R2. This is because intra-area paths are preferred over anything else…even if the cost is higher! Let’s shut the interface to R2 to see what path we will take next:
R2(config)#interface loopback0
R2(config-if)#shutdown
R1#show ip route ospf
1.0.0.0/32 is subnetted, 1 subnets
O IA 1.1.1.1 [110/2] via 192.168.13.3, 00:00:16, FastEthernet0/1
With the intra-area route out of the way, R1 prefers the inter-area route to R3…even if we increase the cost, we will stick to this path. Let me show you:
R3(config)#interface loopback 0
R3(config-if)#ip ospf cost 900
R1#show ip route ospf
1.0.0.0/32 is subnetted, 1 subnets
O IA 1.1.1.1 [110/901] via 192.168.13.3, 00:00:15, FastEthernet0/1
Even if I increase the cost to 901, OSPF will stick to the inter-area route over all the other paths. OSPF puts a lot of faith in its path selection. Now you know that path selection is done before the lowest cost selection. Let’s see what OSPF prefers when this inter-area route is no longer reachable:
R3(config)#interface loopback 0
R3(config-if)#shutdown
R1#show ip route ospf
1.0.0.0/32 is subnetted, 1 subnets
O E1 1.1.1.1 [110/21] via 192.168.14.4, 00:00:12, FastEthernet0/2
With the intra-area and inter-area paths out of the way, OSPF will prefer the external type 1 route. Let’s shut it to see what’s next:
R4(config)#interface loopback 0
R4(config-if)#shutdown
R1#show ip route ospf
1.0.0.0/32 is subnetted, 1 subnets
O N1 1.1.1.1 [110/21] via 192.168.16.6, 00:00:13, FastEthernet0/4
The next one is the external type 1 from the NSSA area. Let’s continue:
R6(config)#interface loopback 0
R6(config-if)#shutdown
R1#show ip route ospf
1.0.0.0/32 is subnetted, 1 subnets
O E2 1.1.1.1 [110/20] via 192.168.15.5, 00:00:09, FastEthernet0/3
Now it prefers the external type 2…one more interface to shut:
R5(config)#interface loopback 0
R5(config-if)#shutdown
R1#show ip route ospf
1.0.0.0/32 is subnetted, 1 subnets
O N2 1.1.1.1 [110/20] via 192.168.17.7, 00:00:07, FastEthernet0/5
Last but not least, we will use the external type 2 from the NSSA area.
Keep this in mind before looking at the lowest-cost path…OSPF will first compare the different paths and select one according to the table at the beginning of this lesson. If you have any questions feel free to leave a comment!
Unit 1: Introduction to OSPF
- Introduction to OSPF
- Basic OSPF Configuration
- OSPF Multi Area Configuration
- OSPF Reference Bandwidth
- OSPF Plain Text Authentication
- OSPF MD5 Authentication
- OSPF SHA-HMAC Authentication
- OSPF TTL Security Check
- OSPF Default Route
Unit 2: OSPF Neighbor Adjacency
- OSPF LSA Types
- OSPF LSAs and LSDB Flooding
- OSPF Hello and Dead Interval
- OSPF Router ID
- OSPF Packets and Neighbor Discovery
- OSPF DR/BDR Election
- OSPF Passive Interface
- Troubleshooting OSPF Neighbor Adjacency
Unit 3: OSPF Network Types
- OSPF Non-Broadcast Network Type
- OSPF Broadcast Network Type
- OSPF Point-to-Multipoint Network Type
- OSPF Point-to-Multipoint Non-Broadcast Network Type
- OSPF Point-to-Point Network Type
- OSPF Next Hop with Network Types
Unit 4: OSPF Stub Areas
- Introduction to OSPF Stub Areas
- How to configure OSPF Stub Area
- How to configure OSPF Totally Stub
- How to configure OSPF NSSA (Not So Stubby) Area
- How to configure OSPF Totally NSSA (Not So Stubby) Area
- OSPF NSSA P-bit explained
Unit 5: Advanced OSPF Topics
- OSPF Summarization
- OSPF Distribute-List Filtering
- OSPF LSA Type 3 Filtering
- OSPF LSA Type 5 Filtering
- OSPF Virtual Link
- OSPF Virtual Link Authentication
- OSPF Path Selection Explained
- How to read the OSPF Database
- OSPFv3 for IPv4
- Troubleshooting OSPF Route Advertisement
- OSPF SPF Scheduling and Throttling
- OSPF LSA Throttling
- OSPF Incremental SPF
- OSPF Prefix Suppression
- OSPF Stub Router
- OSPF Graceful Shutdown
- OSPF Graceful Restart
- OSPF Loop-Free Alternate (LFA) Fast Reroute (FRR)
- OSPF Remote Loop-Free Alternate (LFA) Fast Reroute (FRR)