CCNA online course

OSPF Overview for CCNA

Learn OSPF for CCNA: link-state operation, neighbors, areas, router IDs, metrics, DR and BDR elections, Cisco IOS configuration, verification, and troubleshooting.

OSPF at a Glance

OSPF means Open Shortest Path First. It is an open-standard interior gateway protocol (IGP), which means it routes traffic inside a single autonomous system. An autonomous system is a collection of networks managed under a common routing policy.

OSPF is a link-state routing protocol. Instead of periodically sending its entire routing table to neighbors, each router describes its connected links and relevant topology information. Routers in the same OSPF area use this information to build a synchronized link-state database (LSDB) and calculate best paths.

Dynamic routing is useful when networks have multiple routers or when links can fail. Compared with manually maintained static routes, OSPF can discover alternate paths, react to topology changes, and reduce the amount of configuration required on every router. Its hierarchical design, loop-resistant SPF calculation, and event-driven updates help it scale and converge quickly.

For a foundation in how routing fits into networking layers, review the OSI reference model.

Important OSPF Characteristics

CharacteristicValue or behaviorWhy it matters
Protocol typeOpen-standard link-state IGPRoutes within one autonomous system using a shared topology view.
Administrative distance110 on Cisco devicesUsed to compare OSPF with routes learned from other sources.
IP protocol number89OSPF is carried directly in IP; it does not use TCP or UDP.
Multicast addresses224.0.0.5 for all OSPF routers; 224.0.0.6 for DR and BDR routersMulticast limits OSPF traffic to devices that need it on the segment.
MetricCostOSPF selects the path with the lowest total cost.
AlgorithmShortest Path First, based on Dijkstra's algorithmCalculates a loop-resistant shortest-path tree from the LSDB.
IPv4 and IPv6 versionsOSPFv2 primarily routes IPv4; OSPFv3 primarily routes IPv6The versions share link-state and area concepts but use different configuration models.
  • OSPF is classless, so it carries subnet-mask information and supports VLSM and CIDR.
  • OSPF supports equal-cost multipath (ECMP), allowing multiple next hops when their total costs are equal.
  • OSPF sends updates when topology changes, rather than periodically sending the entire routing table like a traditional distance-vector protocol. Hellos are still sent regularly to maintain neighbor relationships.

How Link-State OSPF Works

  1. Hello discovery: OSPF-enabled interfaces send Hello packets. A router learns which neighboring routers are reachable and records their router IDs.
  2. Adjacency formation: Neighbors compare required parameters. Some neighbors become fully adjacent and synchronize their link-state information.
  3. Link-state exchange: Routers describe known topology information using link-state advertisements (LSAs). An LSA is a unit of topology information flooded through an OSPF area.
  4. LSDB construction: Routers in an area maintain matching topology information in their LSDB.
  5. SPF calculation: Each router runs the SPF algorithm against the LSDB, using interface costs as edge weights.
  6. Route installation: The best resulting paths are placed in the IPv4 routing table. The routing table then selects the forwarding next hop using its normal route-selection rules.

Because routers calculate from a topology database rather than trusting a neighbor's complete route table, OSPF can respond rapidly to link failures and avoid many routing loops.

For more detail about the topology information exchanged by OSPF, see Link-State Advertisement (LSA).

OSPF Packet Types

Packet typePrimary purposeWhen it is used
HelloDiscover and maintain neighborsSent regularly on OSPF-enabled, non-passive interfaces.
Database Description (DBD)Summarize LSDB contentsUsed during adjacency formation and database synchronization.
Link-State Request (LSR)Request specific missing or newer LSAsSent when a router needs more detail than a DBD provides.
Link-State Update (LSU)Carry one or more LSAsUsed to flood new, changed, or requested topology information.
Link-State Acknowledgment (LSAck)Acknowledge received LSAsHelps provide reliable flooding of link-state information.

Neighbor and Adjacency Requirements

A neighbor is a router discovered through Hello exchanges. An adjacency is a more advanced relationship in which link-state databases are synchronized. A router can know about a neighbor without every neighbor relationship becoming a full adjacency; broadcast networks use DR and BDR behavior to limit unnecessary full adjacencies.

For two directly connected routers to form a relationship, check these requirements:

  • The interfaces must have Layer 3 reachability and be operational.
  • OSPF must be enabled on both interfaces, and neither interface can be passive if it must form a neighbor.
  • The interfaces must belong to the same OSPF area.
  • The interfaces must be on the same subnet. The relevant OSPF network type must also match where applicable.
  • Hello and Dead intervals must match.
  • Authentication settings must match when authentication is enabled.
  • Stub-area-related options must match for routers participating in the same stub area.
  • Each router must have a unique router ID.

Router ID Selection

The router ID is a unique 32-bit identifier for an OSPF router. It is written like an IPv4 address, but it does not have to be assigned to a physical interface.

PrioritySourceNotes
1Configured router IDPreferred method because it is explicit and stable.
2Highest loopback IPv4 addressSelected when no manual ID exists. Loopbacks are usually stable because they are not tied to one physical link.
3Highest active physical-interface IPv4 addressUsed when no manual ID and no loopback address exist.

After changing an established router ID, OSPF must restart its relevant process state before the new ID is used. On Cisco IOS, clear ip ospf process does this, but it tears down OSPF adjacencies and should be used carefully in a production network.

OSPF Areas and Hierarchy

An area is a logical OSPF topology boundary. Areas reduce the size of each router's LSDB and limit the scope of SPF calculations and some LSA flooding. A small deployment commonly uses one area, while a larger deployment can use multiple areas for scalability.

  • Area 0: The backbone area. Normal interarea traffic is exchanged through Area 0.
  • Internal router: All OSPF interfaces belong to one area.
  • Backbone router: At least one OSPF interface belongs to Area 0.
  • Area Border Router (ABR): Has interfaces in Area 0 and at least one other area.
  • Autonomous System Boundary Router (ASBR): Introduces routes from another routing domain, such as static routes or another routing protocol.

Non-backbone areas should connect to Area 0 for normal hierarchical operation. Multi-area OSPF is a scalability concept; single-area Area 0 is the standard introductory deployment.

OSPF Network Types, DR, and BDR

OSPF behaves differently according to the link type. Ethernet is normally a broadcast multiaccess network, where many routers share one segment. Point-to-point links connect two routers directly and normally do not require a DR or BDR election.

On a broadcast segment, every router forming a full adjacency with every other router would create unnecessary control-plane overhead. OSPF therefore elects a Designated Router (DR) and Backup Designated Router (BDR). The DR helps coordinate adjacency and LSA flooding, while the BDR is prepared to take over if the DR fails. Other routers are often called DROTHERs.

  • The highest interface priority wins the DR election.
  • If priorities tie, the highest router ID wins.
  • An interface priority of 0 prevents that interface from becoming DR or BDR.
  • The election is non-preemptive. A newly arriving router with a higher priority does not automatically replace an existing DR.
  • 224.0.0.5 is the all-OSPF-routers multicast address; 224.0.0.6 is used to reach DR and BDR routers.

OSPF Cost and Path Selection

Cost is the OSPF metric assigned to an interface. Cisco's general formula is:

OSPF cost = reference bandwidth / interface bandwidth

The router adds the interface costs along each candidate path. The path with the lowest total cost is preferred. If multiple paths have the same total cost, OSPF can install them as ECMP routes.

Historically, Cisco's default reference bandwidth is 100 Mbps. With that value, a 100 Mbps interface and a 1 Gbps interface can both receive a calculated cost of 1. This can produce undesirable decisions on modern networks because the default reference does not distinguish many high-speed links. Use auto-cost reference-bandwidth consistently on every router in the OSPF domain, or assign an explicit interface cost where appropriate.

R1(config)# router ospf 1
R1(config-router)# auto-cost reference-bandwidth 10000

R1(config)# interface GigabitEthernet0/0
R1(config-if)# ip ospf cost 10

The reference-bandwidth value is expressed in Mbps. A consistent value is important because different reference values can cause neighboring routers to calculate different path costs.

Cost Example

With a 100 Mbps reference, a 100 Mbps link and a 1 Gbps link may both have cost 1. A path using two such links can therefore have a total cost of 2. If the reference bandwidth is raised to 10,000 Mbps, the calculated costs distinguish these speeds more effectively. Always compare the complete path cost, not just one interface.

Basic Single-Area OSPFv2 Configuration

OSPFv2 is the OSPF version primarily used to route IPv4. The following example enables process 1, assigns a router ID, and advertises two IPv4 networks into Area 0.

R1(config)# router ospf 1
R1(config-router)# router-id 1.1.1.1
R1(config-router)# network 192.0.2.0 0.0.0.255 area 0
R1(config-router)# network 10.0.12.0 0.0.0.3 area 0

The process number is locally significant; it does not need to match on neighboring routers. The network command uses a Cisco wildcard mask, which is the inverse of a subnet mask. A matched interface is enabled for OSPF and is associated with the specified area. This is more than merely describing a route: it activates OSPF on matching interfaces and allows those interfaces' connected prefixes to be advertised.

Interface-Based Configuration

Cisco IOS also supports enabling OSPF directly under an interface:

R1(config)# interface GigabitEthernet0/0
R1(config-if)# ip ospf 1 area 0

This approach avoids wildcard-mask matching and can make the intended participating interfaces clearer. Use one approach consistently enough that the resulting OSPF-enabled interfaces are easy to audit.

Passive Interfaces

A passive interface advertises its connected network into OSPF but does not send Hellos or form OSPF neighbors. This is useful for a user LAN where no OSPF-speaking router should be present.

R1(config)# router ospf 1
R1(config-router)# passive-interface GigabitEthernet0/1

Keep router-to-router transit interfaces non-passive so that they can discover neighbors. A passive LAN can still appear as an OSPF route because its connected prefix is advertised by the router.

Single-Area Topology Example

Consider three routers connected by transit links. R1 has LAN prefix 192.0.2.0/24, R2 has LAN prefix 198.51.100.0/24, and R3 has LAN prefix 203.0.113.0/24. All transit and LAN interfaces participate in Area 0, with LAN interfaces made passive. Assign unique IDs such as 1.1.1.1, 2.2.2.2, and 3.3.3.3.

R1 forms Full adjacencies with its directly connected OSPF neighbors. It then learns the remote LAN prefixes and installs them as OSPF routes. OSPF does not need a separate static route for every remote LAN; enabling OSPF on the relevant interfaces advertises those connected prefixes.

Route Advertisement and Route Codes

OSPF advertises prefixes associated with OSPF-enabled interfaces. A connected network is not automatically advertised simply because it exists in the routing table; the interface or prefix must be included in the OSPF configuration. Route filters, summarization, area design, and redistribution can also affect what other routers learn.

CodeRoute typeMeaning
OIntra-areaLearned within the same OSPF area.
O IAInterareaLearned from another OSPF area through an ABR.
O E1External type 1Includes the external metric plus the internal OSPF cost to reach the ASBR.
O E2External type 2Uses the external metric as the primary metric; internal cost is considered separately for tie-breaking.

An ASBR can inject routes learned from another routing source through redistribution. OSPF can also originate a default route so that routers use it for destinations not otherwise known. These are introductory functions that require careful policy design in production networks.

OSPFv2 and OSPFv3

OSPFv2 is primarily used for IPv4 routing. OSPFv3 is primarily used for IPv6 routing. Both use link-state databases, LSAs, SPF calculations, router IDs, areas, and neighbor relationships. Their packet formats and configuration models differ, and OSPFv3 commonly enables routing behavior in an IPv6-specific way under interfaces or address families. This overview does not replace an IPv6 configuration guide.

Verification Workflow

  1. Check interfaces: Confirm addressing, subnet masks, operational state, and Layer 3 reachability.
  2. Check the OSPF process: Confirm the process exists and identify participating interfaces and passive interfaces.
  3. Check neighbors: Confirm the expected router ID, area, and state. A fully synchronized adjacency normally reaches Full.
  4. Check identity and topology: Verify the router ID, interface details, timers, network type, and area assignment.
  5. Check the LSDB: Confirm that the expected topology and prefixes are present.
  6. Check routes: Confirm OSPF entries, next hops, administrative distance, and metric in the routing table.
show ip ospf neighbor
show ip ospf interface brief
show ip ospf interface
show ip ospf
show ip ospf database
show ip protocols
show ip route ospf
show ip route

Troubleshooting OSPF

SymptomLikely causeVerificationCorrection
No neighbor discoveredOSPF is not enabled, an interface is down, addressing is wrong, areas differ, the interface is passive, or timers and authentication do not match.Check interface status and addressing, show ip ospf interface, passive settings, timers, and authentication.Restore Layer 3 connectivity, enable OSPF on both ends, match area and timers, and remove unintended passive configuration.
Neighbor stuck in InitHello communication is one-way, the local router ID is not seen in received Hellos, or Layer 2/multicast handling is failing.Check neighbor state, bidirectional connectivity, multicast handling, and OSPF activity on both ends.Correct the one-way or filtering issue and verify both interfaces can exchange Hellos.
Neighbor stuck in ExStart or ExchangeOften an MTU mismatch or a Database Description exchange problem.Compare interface MTU values and inspect detailed OSPF interface information.Correct the MTU mismatch rather than relying on a workaround.
Neighbor relationship drops repeatedlyUnstable links, mismatched timers, intermittent Layer 2 connectivity, authentication problems, or resource pressure.Review interface errors, logs, timers, authentication, and detailed neighbor information.Fix the underlying link, timer, authentication, or resource problem.
Neighbor is Full but a remote route is absentThe prefix is not advertised, its interface is down, filtering or summarization affects it, another route source wins, or the prefix is outside the expected area.Inspect the OSPF database, OSPF routes, remote participating interfaces, and the complete routing table.Correct advertisement or policy configuration and confirm the route's area and metric.

Unexpected Path Selection

If OSPF chooses an unexpected path, compare the interface bandwidth values, calculated costs, manual costs, and reference bandwidth on every router. A reference bandwidth that is too low can make fast links appear equal. Multiple equal-cost paths may also be intentional ECMP behavior.

OSPF Roles Summary

RoleDefinitionTypical location
Internal routerAll OSPF interfaces are in one area.Inside a single area.
Backbone routerHas at least one interface in Area 0.Area 0 or a router connecting to the backbone.
Area Border RouterConnects Area 0 to at least one other area.Boundary between OSPF areas.
Autonomous System Boundary RouterRedistributes routes from another routing domain into OSPF.At an external routing boundary.
Designated RouterCoordinates relationships and flooding on an applicable multiaccess segment.Broadcast Ethernet segment.
Backup Designated RouterMaintains a backup role and can assume DR duties.Broadcast Ethernet segment.