Single-area OSPFv2 and OSPFv3: neighbors, network types, DR/BDR and router ID
Why this matters
OSPF is the routing protocol a junior network engineer is most likely to meet inside a company network. A branch router learns the head office subnets from it, a core switch learns every access-layer VLAN from it, and when a link fails OSPF finds the other path in seconds without anyone typing a static route. The day-to-day work is small but constant: bring up a new router so it forms neighbors, check that a new subnet is advertised, and work out why two routers that should talk are not talking.
When OSPF is misconfigured, the failure is rarely loud. Two routers with mismatched timers simply never become neighbors, so the routes behind one of them vanish from the other's routing table. A router that copies another's router ID causes adjacencies to flap. A network statement with the wrong wildcard leaves one interface out of OSPF entirely. Every one of these is visible in a few show commands, if you know what the output should look like.
The lesson
Open Shortest Path First (OSPF) is a link-state routing protocol. Each router describes its own links in link-state advertisements (LSAs), floods them to its neighbors, and builds an identical database. Each router then runs the shortest path first algorithm on that database to find its best routes. OSPFv2 carries IPv4 routes. OSPFv3 carries IPv6 routes. This lesson keeps to a single area, area 0, the backbone, so every router holds the same database.
Turning OSPFv2 on takes a process and a way of saying which interfaces join it. There are two ways. The older way is the network command, which matches interface addresses with a wildcard mask. The newer way is an interface command.
R1(config)#router ospf 1
R1(config-router)#router-id 1.1.1.1
R1(config-router)#network 10.0.12.0 0.0.0.3 area 0
R1(config-router)#passive-interface GigabitEthernet0/2
R1(config-router)#exit
R1(config)#interface GigabitEthernet0/0
R1(config-if)#ip ospf 1 area 0
The number after router ospf is the process ID. It only matters inside this router. R1 can run process 1 while its neighbor runs process 2, and they still form an adjacency.
A wildcard mask is the inverse of the subnet mask: subtract each octet of the mask from 255. A 0 bit means "must match", a 1 bit means "any value". Worked examples, step by step:
- Interface 10.10.20.1/27. The mask is 255.255.255.224. 255 minus 224 is 31, so the wildcard is 0.0.0.31. The subnet is 10.10.20.0 to 10.10.20.31, so the statement is
network 10.10.20.0 0.0.0.31 area 0. Writing 0.0.0.32 is a common slip: 32 is the block size, not the inverse. - Link 172.16.0.4/30. The mask is 255.255.255.252, so the wildcard is 0.0.0.3, matching .4 to .7 only. A wildcard of 0.0.0.7 would also enable the link, but it matches eight addresses.
- Interface 192.168.50.77/28. The block size of a /28 is 16, so the subnets start at .0, .16, .32, .48, .64, .80. The address .77 falls in the block that starts at .64 and ends at .79. The statement is
network 192.168.50.64 0.0.0.15 area 0. A statement for .80 starts one block too late and misses the interface. - Four LANs, 172.16.8.0/24 to 172.16.11.0/24. Four /24 blocks make one /22, because 4 is 2 to the power 2, and 24 minus 2 is 22. A /22 mask is 255.255.252.0, so the wildcard is 0.0.3.255. The statement is
network 172.16.8.0 0.0.3.255 area 0. 0.0.7.255 would also catch 172.16.12.0 to 172.16.15.255, and 0.0.1.255 stops at 172.16.9.255.
A passive interface still has its subnet advertised, but OSPF sends no hellos on it and ignores any it receives. Use it on user LANs, where no router should ever appear. If a router is placed on that LAN later, no neighbor will ever form there until the passive setting is removed.
Forming neighbor adjacencies (authentication left aside)
Routers find each other with hello packets. OSPFv2 sends hellos to the multicast address 224.0.0.5, all OSPF routers. Updates sent toward the DR and BDR go to 224.0.0.6. OSPFv3 uses the IPv6 equivalents, FF02::5 and FF02::6.
Two routers become neighbors only when their hellos agree on these values:
- the area ID of the connected interfaces;
- the hello and dead intervals (by default 10 and 40 seconds on Ethernet);
- the subnet and mask of the link, for OSPFv2;
- the network type of both ends;
- authentication, if any is set (not examined in this lesson);
- the stub area flag, which a single-area design leaves alone.
Things that do not need to match: the process ID, which is local, and the interface priority, which only affects the DR election. The router ID must be unique, never the same.
The IP MTU is a special case. Hellos do not carry it, so routers with different MTUs do become neighbors. They then try to swap database descriptions, the larger packets are refused, and the pair sticks in EXSTART or EXCHANGE.
The neighbor states, in order, are Down, Init (I have heard you), 2WAY (you have heard me too), EXSTART and EXCHANGE (we are comparing databases), LOADING (I am requesting LSAs I lack) and FULL (our databases match).
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 1 EXSTART/DR 00:00:36 10.0.12.2 GigabitEthernet0/1
If that line stays in EXSTART for minutes, check show interfaces on both ends for a different MTU. A hello timer mismatch looks different: the neighbor never appears in the table at all. R1 with the default 10/40 and R2 with ip ospf hello-interval 5 and ip ospf dead-interval 20 drop each other's hellos and never become neighbors. An area mismatch is the same. If R1's Gi0/1 has ip ospf 1 area 0 and R2's Gi0/1 has ip ospf 2 area 1, R1 logs a mismatched area ID. The fix is to put R2's interface in area 0. R2 may keep process 2.
Point-to-point links
A point-to-point network type means exactly two routers on the link. There is no one to elect, so OSPF chooses no DR and no BDR. The two routers move straight to FULL. Hellos still go to 224.0.0.5 every 10 seconds, and neighbors are still found automatically.
Serial links are point-to-point by default. An Ethernet link is not: Ethernet defaults to broadcast, even when only one cable joins two routers. On such a link the election is pointless and adds a short delay, so engineers set the type by hand on both ends.
R1(config)#interface GigabitEthernet0/1
R1(config-if)#ip ospf network point-to-point
R2(config)#interface GigabitEthernet0/1
R2(config-if)#ip ospf network point-to-point
Both ends must change. If only one end is point-to-point and the other is broadcast, the network types do not match and the adjacency will not work properly. Setting priority 0 on both ends is not a substitute. It leaves a broadcast network with no router eligible to be DR, so the two routers stay in 2WAY and never reach FULL.
On a point-to-point link the neighbor table shows a dash where the role would be:
R1#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 0 FULL/ - 00:00:34 10.0.12.2 GigabitEthernet0/1
Broadcast segments and the DR/BDR election
On a broadcast network type, the Ethernet default, many routers can share one segment. If every router formed a full adjacency with every other, the number of adjacencies would grow fast and LSAs would be flooded many times over. OSPF avoids this with a designated router (DR) and a backup designated router (BDR). Every other router is a DROTHER. Each DROTHER becomes FULL with the DR and the BDR only. Two DROTHERs stay in 2WAY with each other, and that is normal.
The election works like this:
- The highest interface OSPF priority wins. The default is 1, the range is 0 to 255.
- If priorities tie, the highest router ID wins.
- A priority of 0 makes an interface ineligible. It still forms adjacencies with the DR and BDR, but it can never hold either role.
Worked example. Four routers start at the same moment on one segment: R1 priority 1, router ID 4.4.4.4; R2 priority 10, 1.1.1.1; R3 priority 10, 2.2.2.2; R4 priority 0, 9.9.9.9. R4 is out, because priority 0 is ineligible, even though it has the highest router ID. R2 and R3 tie on priority 10, so the router ID breaks the tie. R3 (2.2.2.2) becomes DR and R2 (1.1.1.1) becomes BDR. R1 is a DROTHER.
The election is not preemptive. Once a DR and BDR exist, a new router with priority 200 joins as a DROTHER and waits. It rises only when a current DR or BDR fails, or OSPF is reset on the segment. When the DR fails, the BDR is promoted to DR without a new contest, and only the BDR role is elected again. So if R1 is DR, R2 is BDR, R3 has priority 50 and R4 priority 1, and R1 loses power, R2 becomes DR and R3 becomes the new BDR.
To keep a router out of the roles but still adjacent, set ip ospf priority 0 on that interface. To make it the likely winner, raise the priority, then reset OSPF so the new value counts.
R3#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
1.1.1.1 1 FULL/DR 00:00:33 10.1.1.1 GigabitEthernet0/0
2.2.2.2 1 FULL/BDR 00:00:31 10.1.1.2 GigabitEthernet0/0
4.4.4.4 1 2WAY/DROTHER 00:00:38 10.1.1.4 GigabitEthernet0/0
R3 is a DROTHER here: FULL with the DR and BDR, 2WAY with the other DROTHER. Nothing is broken. The interface view gives the same picture from R1's side:
R1#show ip ospf interface brief
Interface PID Area IP Address/Mask Cost State Nbrs F/C
Gi0/1 1 0 10.0.12.1/30 1 P2P 1/1
Gi0/0 1 0 10.1.1.1/24 1 DR 3/3
The State column gives R1's role on each link. F/C means fully adjacent neighbors over the count of neighbors. 3/3 on Gi0/0 says R1 is the DR and FULL with all three neighbors there. Gi0/1 is a point-to-point link with one FULL neighbor.
How a router chooses its router ID
The router ID is a 32-bit number written like an IPv4 address. It names the router in every LSA, so it must be unique across the OSPF domain. IOS chooses it in this order:
- The
router-idcommand under the OSPF process. - If there is none, the highest IPv4 address on an up loopback interface.
- If no loopback is up, the highest IPv4 address on an up physical interface.
Worked example. R1 has no router-id. Its up interfaces are Gi0/0 10.1.1.1, Gi0/1 192.168.5.1, Loopback0 172.16.0.1 and Loopback1 10.255.255.1. Step 1 gives nothing. Step 2 compares only the loopbacks: 172.16.0.1 is higher than 10.255.255.1, so the router ID is 172.16.0.1. The higher physical address 192.168.5.1 is never considered, because a loopback is up.
The router ID is chosen when the process starts, and it does not change while OSPF runs. If you type router-id 9.9.9.9 on a router that has run for weeks as 1.1.1.1, IOS accepts the command and warns that it takes effect after a reload or a process reset:
R1(config-router)#router-id 9.9.9.9
% OSPF: Reload or use "clear ip ospf process" command, for this to take effect
R1(config-router)#end
R1#clear ip ospf process
Reset ALL OSPF processes? [no]: yes
The reset drops and rebuilds every adjacency, so do it in a maintenance window. If two routers share a router ID, R5 logs that it detected a duplicate router ID from a neighbor, and the pair will not become fully adjacent. The fix is to give one router a unique router-id and clear its OSPF process. Changing a process ID does nothing, because process IDs are never compared between routers.
OSPFv3 for IPv6
OSPFv3 works the same way: the same hellos, states, network types, DR/BDR election and router ID rules. The differences that matter:
- IPv6 routing must be on first, with
ipv6 unicast-routing. Without it, the router will not route IPv6 at all. - OSPFv3 is enabled per interface, never with a
networkstatement. - The router ID is still a 32-bit dotted-decimal value. IOS can derive it only from an IPv4 address. A router with no IPv4 address anywhere cannot start OSPFv3 until you set
router-idunder the process. - OSPFv3 sends its packets from link-local addresses, so routes it installs point to the neighbor's FE80 link-local address, not its global address.
R7(config)#ipv6 unicast-routing
R7(config)#ipv6 router ospf 1
R7(config-rtr)#router-id 7.7.7.7
R7(config-rtr)#exit
R7(config)#interface GigabitEthernet0/0
R7(config-if)#ipv6 ospf 1 area 0
On a router that already runs OSPFv2 and has IPv4 addresses, the router ID comes for free, and only ipv6 unicast-routing and ipv6 ospf 1 area 0 on the interface are needed. The interface command creates the process if it does not exist.
R1#show ipv6 route ospf
O 2001:DB8:20::/64 [110/2]
via FE80::2, GigabitEthernet0/0
What the exam is really asking
- Never a neighbor versus stuck neighbor. A neighbor missing from the table points at hellos: area, timers, subnet, network type, a passive interface. A neighbor stuck in EXSTART or EXCHANGE points at MTU.
- 2WAY is not always a fault. Between two DROTHERs on a broadcast segment it is correct. Between the only two routers on a link, it means something is wrong, such as priority 0 at both ends.
- Process ID versus area ID. The process ID is local and may differ. The area ID must match.
- Priority before router ID. Priority decides the election. Router ID only breaks a tie. Priority 0 means never DR or BDR, but still adjacent.
- No preemption. A better router arriving late does not take over. The BDR, not the highest priority, inherits a failed DR's role.
-
Loopback before physical. With no
router-id, the highest up loopback wins even when a physical address is higher. A new router ID needsclear ip ospf processor a reload. - Wildcard, not mask. 0.0.0.31 for a /27, not 0.0.0.32 or 0.0.0.224. Find the block an address sits in before writing the statement.
- OSPFv3 details. FF02::5 for hellos, link-local next hops, a 32-bit router ID that an IPv6-only router must be given by hand. Lesson 13 shows how these routes appear in the routing table beside static routes from lesson 14.
Practise what you just read
1. R1 has no router-id command under router ospf 1. Its interfaces, all up/up, are Gi0/0 10.1.1.1, Gi0/1 192.168.5.1, Loopback0 172.16.0.1 and Loopback1 10.255.255.1. Which router ID does R1 choose?
Select one
Show answer
B. With no router-id command, OSPF takes the highest IPv4 address on an up loopback interface, so 172.16.0.1 on Loopback0 beats 10.255.255.1 on Loopback1. 192.168.5.1 is the highest address overall, but a physical interface is used only when no loopback interface is up.
2. Four routers on one Ethernet segment start OSPF at the same moment: R1 priority 1, router ID 4.4.4.4; R2 priority 10, router ID 1.1.1.1; R3 priority 10, router ID 2.2.2.2; R4 priority 0, router ID 9.9.9.9. Which router becomes the DR?
Select one
Show answer
C. The highest interface priority wins the DR election and the highest router ID breaks a tie, so R3 beats R2 on router ID and becomes DR, with R2 as BDR. R4 has the highest router ID, but priority 0 makes it ineligible for either role.
3. Two routers are joined by a single link, and both interfaces use the OSPF point-to-point network type. Which statement describes OSPF on that link?
Select one
Show answer
A. A point-to-point network type has only two routers, so OSPF elects neither a DR nor a BDR and the neighbors go straight to FULL, shown as FULL/ - in show ip ospf neighbor. Electing a DR with no BDR never happens; the hello interval stays at 10 seconds and neighbors are found by multicast hellos.
22 more questions on this exam topic are part of the full practice bank.
Hands-on labs
Every lab runs in Cisco Packet Tracer on your own computer (or on paper), costs nothing, never touches a real network, and ends by saving your work for the next lab.
Part of the free Cisco CCNA 200-301 course — 29 lessons and 28 hands-on labs.
This is an independent study companion for the Cisco CCNA 200-301 v2.0 exam and is not produced by or endorsed by Cisco. Cisco, CCNA and IOS are trademarks of Cisco Systems, Inc.