By the end of this lesson you can
- Explain how OSPF neighbours form and build a shared LSDB
- Configure single area OSPFv2 with a fixed router ID and passive interfaces
- Predict DR and BDR election results and use point to point links
- Read OSPF costs and equal cost paths in the routing table
- Troubleshoot neighbours that will not reach FULL
Link state routing in plain words
Static routes from lesson 3.7 work until a link fails and nobody updates them. A dynamic routing protocol lets routers tell each other what they can reach and recalculate when something changes. OSPF (Open Shortest Path First) is the open standard one you will meet everywhere, and OSPFv2 carries IPv4.
- Each router finds neighbours by sending hello packets out of its OSPF interfaces (to multicast 224.0.0.5).
- Neighbours exchange LSAs (link state advertisements): descriptions of each router's links, subnets and costs.
- Every router in an area ends up with an identical link state database (LSDB), a map of the area.
- Each router runs the SPF (Dijkstra) algorithm on that map, with itself as the root, and installs the lowest cost paths in its routing table as
Oroutes with administrative distance 110.
This lesson covers single area OSPF: everything is in area 0, the backbone. Multi area design exists for large networks and is beyond CCNA depth.
Becoming neighbours: states, timers and the must-match list
Hellos go out every 10 seconds on Ethernet, and a neighbour is declared dead after 40 seconds of silence (the dead interval). Two routers only become neighbours when these match:
| Must match | What happens if it does not |
|---|---|
| Area ID | No adjacency. The hello is ignored. |
| Subnet and mask on the link | No adjacency on broadcast links. |
| Hello and dead intervals | No adjacency. Changing one side drops an existing neighbour when the dead timer runs out. |
| Authentication settings | No adjacency. |
| Stub area flag | No adjacency (not used in this lesson). |
| MTU | Neighbours get stuck in ExStart or Exchange. |
What does not need to match: the process ID in router ospf 1. It is local to the router. Router IDs must be unique.
Router ID (a 32 bit name written like an IPv4 address) is chosen in this order: the router-id command; else the highest IP on a loopback interface that is up; else the highest IP on an active physical interface. A router ID only changes when the process restarts, so after changing it you run clear ip ospf process.
DR and BDR on shared LANs, and why point to point skips it
If ten routers share one Ethernet segment and every pair formed a full adjacency, that would be 45 adjacencies flooding the same updates. OSPF instead elects a designated router (DR) and a backup (BDR). Everyone forms a Full adjacency with the DR and BDR; the others (DROTHERs) stay at 2-Way with each other.
- Highest OSPF interface priority wins (default 1, range 0 to 255). Priority 0 means "never be DR or BDR".
- On a tie, the highest router ID wins.
- The election is not preemptive. A router that joins later with a higher priority does not take over. The DR changes only if it fails (then the BDR is promoted) or the OSPF processes are restarted.
A link with only two routers (a /30 between R1 and R3, say) gains nothing from an election. ip ospf network point-to-point on both ends removes the DR/BDR step and the wait that comes with it, so the adjacency forms faster. Both ends must use the same network type.
| Command | Where | Effect |
|---|---|---|
ip ospf priority 200 | Interface | Makes this router the likely DR on that segment (at the next election). |
ip ospf priority 0 | Interface | Never DR or BDR on that segment. |
ip ospf network point-to-point | Interface, both ends | No DR/BDR election; neighbour shows FULL/ -. |
Configuring single area OSPF
R1(config)#interface Loopback0
R1(config-if)#ip address 1.1.1.1 255.255.255.255
R1(config-if)#exit
R1(config)#router ospf 1
R1(config-router)#router-id 1.1.1.1
R1(config-router)#network 172.16.100.0 0.0.0.255 area 0
R1(config-router)#network 10.0.13.0 0.0.0.3 area 0
R1(config-router)#network 192.168.1.0 0.0.0.255 area 0
R1(config-router)#network 1.1.1.1 0.0.0.0 area 0
R1(config-router)#passive-interface GigabitEthernet0/0/1
R1(config-router)#auto-cost reference-bandwidth 10000
! alternative to network statements, per interface:
R1(config)#interface GigabitEthernet0/0/1
R1(config-if)#ip ospf 1 area 0- A
networkstatement does not advertise a prefix by itself. It says "run OSPF on every interface whose IP falls in this range", and those interfaces' subnets get advertised. It uses a wildcard mask: 0.0.0.255 for a /24, 0.0.0.3 for a /30, 0.0.0.0 for exactly one address. passive-interfacestops hellos on a LAN port but still advertises its subnet. Every user facing interface should be passive.passive-interface defaultfollowed byno passive-interfaceon router links is the safer habit.default-information originateshares this router's default route with the rest of the area. Others see it asO*E2 0.0.0.0/0.
Cost: how OSPF picks the best path
OSPF's metric is cost, added up along the path. Interface cost = reference bandwidth / interface bandwidth, with a minimum of 1. The default reference is 100 Mb/s, which means FastEthernet, Gigabit and 10 Gigabit links all cost 1 and OSPF cannot tell them apart.
| Link | Cost, reference 100 (default) | Cost, reference 10000 |
|---|---|---|
| 100 Mb/s | 1 | 100 |
| 1 Gb/s | 1 | 10 |
| 10 Gb/s | 1 | 1 |
Fix it with auto-cost reference-bandwidth 10000 (in Mb/s) on every router, or set a link's cost directly with ip ospf cost N. In the routing table, [110/20] means AD 110 and total cost 20. If two paths have the same cost, OSPF installs both (up to 4 by default on IOS) and shares the load.
Practise on R1
R1's interfaces are already addressed. R2 and R3 are modelled by this console: R2 has already been given OSPF priority 200 on the shared LAN by a colleague, and R3's end of the point to point link is configured to match whatever you do. All three routers use the same reference bandwidth. Treat outputs as a close guide, not a real protocol run.
Missions 0/16
Flashcards: do you remember?
Tap a card to flip it. Try to answer in your head first; recalling is what makes it stick.
Quick quiz
Instant feedback on every answer. Score 70% or more to pass this lesson's quiz.
Q1Two routers on the same link show no OSPF neighbour. Which mismatch causes this?
Hello and dead timers must match. Process IDs are local.
Q2A router with priority 255 joins a LAN that already has a DR with priority 1. What happens?
DR election is not preemptive.
Q3Two DROTHERs on a shared LAN show 2WAY/DROTHER with each other. This is:
DROTHERs only go Full with the DR and BDR.
Q4With the default reference bandwidth, what is the cost of a 10 Gb/s link?
100 / 10000 is below 1, and the minimum cost is 1.
Q5Which wildcard matches the 10.0.13.0/30 subnet in a network statement?
A /30 has 4 addresses, so the wildcard is 0.0.0.3.
Q6Why make LAN interfaces passive?
It blocks rogue OSPF speakers and wasted hellos.
Hands-on lab
Packet Tracer lab 3.8: OSPF with DR election and a point to point link
You need: Cisco Packet Tracer (free with a Cisco Networking Academy account; version 9.0.1 was the current download on the NetAcad Resource Hub when this lesson was written). Devices: 3 x ISR4331, 4 x 2960 (SW0 for the shared LAN plus one per LAN), 3 x PC-PT.
Simulator lab, zero risk. This lab runs inside Cisco Packet Tracer, so it touches no real network. Packet Tracer is free with a Cisco Networking Academy account (netacad.com). It simulates a subset of Cisco IOS, so where support for a feature is uncertain we say so instead of promising it works.
Topology and addressing
| Device | Interface | IPv4 address / prefix | Default gateway or note |
|---|---|---|---|
| R1 | Gi0/0/0 / Gi0/0/1 / Gi0/0/2 | 172.16.100.1/24 / 192.168.1.1/24 / 10.0.13.1/30 | Lo0 1.1.1.1/32 |
| R2 | Gi0/0/0 / Gi0/0/1 | 172.16.100.2/24 / 192.168.2.1/24 | Lo0 2.2.2.2/32 |
| R3 | Gi0/0/0 / Gi0/0/1 / Gi0/0/2 | 172.16.100.3/24 / 192.168.3.1/24 / 10.0.13.2/30 | Lo0 3.3.3.3/32 |
| PC1 / PC2 / PC3 | Fa0 | 192.168.1.10 / 192.168.2.10 / 192.168.3.10 (/24) | gateway .1 in each LAN |
Address everything, including loopbacks
Use the table. Bring every router interface up with
no shutdownand ping across each link before touching OSPF.OSPF on R1 (adapt the networks for R2 and R3)
R1(config)#router ospf 1 R1(config-router)#router-id 1.1.1.1 R1(config-router)#network 172.16.100.0 0.0.0.255 area 0 R1(config-router)#network 10.0.13.0 0.0.0.3 area 0 R1(config-router)#network 192.168.1.0 0.0.0.255 area 0 R1(config-router)#network 1.1.1.1 0.0.0.0 area 0 R1(config-router)#passive-interface GigabitEthernet0/0/1 R1(config-router)#auto-cost reference-bandwidth 10000 R1(config)#interface GigabitEthernet0/0/2 R1(config-if)#ip ospf network point-to-pointUse the same reference bandwidth on all three routers and set point to point on R3's Gi0/0/2 too.
Make R2 the DR
R2(config)#interface GigabitEthernet0/0/0 R2(config-if)#ip ospf priority 200 R1#clear ip ospf process Reset ALL OSPF processes? [no]: yesRun
clear ip ospf processon all three routers, because the election is not preemptive.Share a default route from R1
R1(config)#interface Loopback1 R1(config-if)#ip address 203.0.113.1 255.255.255.255 R1(config-if)#exit R1(config)#ip route 0.0.0.0 0.0.0.0 Loopback1 R1(config)#router ospf 1 R1(config-router)#default-information originateBreak and fix
R3(config)#interface GigabitEthernet0/0/0 R3(config-if)#ip ospf hello-interval 5 ! wait for the dead timer, watch the ADJCHG messages, then: R3(config-if)#no ip ospf hello-intervalVerify
R1#show ip ospf neighbor R1#show ip ospf interface brief R1#show ip protocols R2#show ip route ospf R1#show ip ospf database
You are done when: On R1, show ip ospf neighbor lists R2 as FULL/DR and R3 as FULL/BDR on Gi0/0/0, and R3 again as FULL/ - on Gi0/0/2. R2 and R3 show O routes to the other LANs and an O*E2 default route. PC1 pings PC2 and PC3.
Packet Tracer limits and notes
- You will not see 2WAY/DROTHER with only three routers. Add a fourth router to SW0 if you want to see two DROTHERs at 2-Way with each other.
show ip ospf interface briefis reported by a third party site as added in Packet Tracer 8.2. UNVERIFIED against Cisco release notes; useshow ip ospf interfaceif it is missing.ip ospf network point-to-pointon Packet Tracer Ethernet interfaces is UNVERIFIED. If it is rejected, leave that link as broadcast: the two routers will elect a DR and BDR, and everything else still works.- The interface form
ip ospf 1 area 0is UNVERIFIED on every Packet Tracer image. The network statements above are the reliable way. - OSPF authentication in Packet Tracer is UNVERIFIED and outside this lesson's depth.
- Packet Tracer simulates a subset of IOS. If a command here is rejected in your version, note it, skip that step and carry on; the concept still applies to real Cisco gear.
Download the lab checklist (.txt) Print it or keep it open beside Packet Tracer.
Key takeaways
- OSPF routers share one map per area and each runs SPF on it.
- Area, subnet, timers and authentication must match; the process ID does not.
- DR and BDR: highest priority then router ID, and the election is not preemptive.
- Raise the reference bandwidth on every router so fast links get different costs.
- Make user facing interfaces passive, and treat an unexpected new neighbour as an incident.
Finished the sections, quiz and lab? Mark the lesson complete. Progress is saved only in this browser.