CCNA 200-301 · 11 of 16

OSPF: routers that agree on the same map

How link-state routing differs from counting hops, what has to match before two routers become neighbours, why a designated router exists, how areas keep the database small, and the configuration and show commands that prove it works.

Updated 2026-09-09
On this page

Older routing protocols worked by rumour: a router told its neighbours which networks it could reach and how far away they were, and everyone believed it. OSPF works by cartography. Every router describes only its own links, floods that description to everyone, and each router independently builds an identical map and computes its own shortest paths across it. That shift — from believing summaries to sharing raw facts — is what makes OSPF converge in seconds and scale to networks that RIP could never hold together.

The map

Read this first when short on time. Every branch is a section below.

Figure 1. The whole article on one page. Every branch is a section below; fold what you know, open what you do not.

Why link-state beat distance-vector

A distance-vector protocol such as RIP tells its neighbours conclusions: "I can reach 10.2.0.0/16, and it is three hops away." The neighbour has no idea how, through whom, or whether that path also passes through itself. Everything is second-hand, which produces two chronic problems: convergence takes many rounds of updates, and routing loops form easily enough that half the protocol is devoted to preventing them.

A link-state protocol shares facts instead. Each router describes only what it can see directly — its own interfaces, their costs, and its neighbours — in a link-state advertisement. Every LSA is flooded unchanged to every router in the area. Each router assembles them into a link-state database, and every router in the area ends up with an identical copy.

Then each router runs Dijkstra's shortest path first algorithm against that database, with itself as the root, producing a tree of shortest paths to every destination. The best routes from that tree go into the routing table.

Distance vector (RIP)Link state (OSPF)
What is sharedRoutes and distancesDescriptions of links
What each router knowsOnly what neighbours told itThe full topology of its area
ConvergenceMinutes, in roundsSeconds
Loop riskHigh, needs split horizon and hold-downsLow — everyone sees the same map
Resource useVery lowCPU and memory for the database and SPF
MetricHop count, maximum 15Cost from bandwidth, effectively unbounded

The cost of the approach is exactly where you would expect: memory to hold the database and CPU to run SPF. That cost is why areas exist, and it is the reason the whole second half of OSPF's design is about limiting how far information has to travel.

Becoming neighbours

Before anything is exchanged, two routers must agree that they are neighbours. They discover each other with hello packets sent to the multicast address 224.0.0.5, every 10 seconds on Ethernet, with a dead interval of 40 seconds — four missed hellos and the neighbour is declared gone.

A hello carries a list of conditions, and every one of them must match or the adjacency never forms:

Must matchWhy it fails silently
Area IDDifferent areas cannot be neighbours on the same link
Hello and dead intervalsChange one end and the other times out repeatedly
Subnet and maskInterfaces must be in the same subnet — a mask typo is a classic cause
AuthenticationType and key must match exactly
Stub area flagsOne router configured as stub, the other not
MTUNot checked in hellos, but breaks the database exchange later

The MTU one is the cruellest, because the neighbour relationship starts forming and then hangs. The states are worth knowing for exactly this reason:

stateDiagram-v2
  [*] --> Down
  Down --> Init: hello received
  Init --> TwoWay: my router ID is in their hello
  TwoWay --> ExStart: adjacency needed
  ExStart --> Exchange: master and slave agreed
  Exchange --> Loading: database headers swapped
  Loading --> Full: missing LSAs requested and received
Figure 2. OSPF neighbour states. A relationship stuck in ExStart almost always means an MTU mismatch, because the database description packets are too large for one end to accept.

Two-way deserves a note, because it looks like a failure and often is not. On a multi-access segment, two routers that are both neither the designated router nor its backup stop at two-way deliberately. They know about each other and do not exchange databases directly, because they will both synchronise with the designated router instead. Seeing 2WAY/DROTHER in the neighbour table is normal and correct.

Router# show ip ospf neighbor

Neighbor ID     Pri   State           Dead Time   Address       Interface
2.2.2.2           1   FULL/DR         00:00:33    10.255.0.2    GigabitEthernet0/1
3.3.3.3           1   FULL/BDR        00:00:31    10.255.0.3    GigabitEthernet0/1
4.4.4.4           0   2WAY/DROTHER    00:00:35    10.255.0.4    GigabitEthernet0/1
5.5.5.5           1   FULL/  -        00:00:38    10.255.1.6    Serial0/0/0

The dash in the last line is a point-to-point link, where there is no designated router because there are only ever two routers on the segment.

The designated router

Put five routers on one Ethernet segment and full adjacencies between every pair would need ten relationships, each flooding to the others — ten copies of everything. With n routers it is n(n−1)/2, which grows badly.

OSPF elects a designated router to act as the hub. Every router forms a full adjacency with the DR and with the backup designated router, and only two-way with everyone else. Updates are sent to the DR at 224.0.0.6, and the DR floods them to everyone at 224.0.0.5. Five routers need eight adjacencies instead of ten, and fifty routers need ninety-eight instead of 1,225.

The election has two rules and one surprise:

  1. Highest interface priority wins. Default is 1; a priority of 0 means the router will never be DR or BDR.
  2. Ties are broken by the highest router ID.
  3. There is no preemption. A router that boots later with a better priority does not take over. The existing DR keeps the role until it fails.

That third rule catches everyone. Whichever router happened to be powered on first becomes DR and stays DR — which is often a small access-layer router rather than the well-connected core switch you would have chosen. Setting priority does not fix it retroactively; you have to clear the OSPF process or bounce the interfaces for a new election.

! make this router the preferred DR on this segment
Router(config-if)# ip ospf priority 255

! and take this one out of the running entirely
Router(config-if)# ip ospf priority 0
Watch out

There is no designated router on point-to-point links, and configuring ip ospf network point-to-point on an Ethernet link between exactly two routers is a common and sensible optimisation: it skips the election, speeds up convergence, and removes the type 2 LSA from the database entirely.

The database: what is actually flooded

OSPF carries several LSA types. Four matter for most purposes.

TypeNameOriginated byDescribesScope
1Router LSAEvery routerIts own interfaces, costs and neighboursWithin one area
2Network LSAThe DRWhich routers are attached to this multi-access segmentWithin one area
3Summary LSAArea border routerA prefix that exists in another areaAcross areas
5External LSAAutonomous system border routerA prefix redistributed from outside OSPFWhole domain

The type 1 and type 2 LSAs together are the map: type 1 says "I am router 2.2.2.2, I have these links at these costs", type 2 says "on this segment, these routers are present". Everything else is a way of talking about places you cannot see the map of.

LSAs are re-flooded every 30 minutes even when nothing changes, so that a database entry cannot silently rot; and a genuine change floods immediately, which is where the fast convergence comes from. Each LSA carries a sequence number and an age so routers can tell a newer copy from an older one.

Router# show ip ospf database

            OSPF Router with ID (1.1.1.1) (Process ID 1)

                Router Link States (Area 0)
Link ID         ADV Router      Age    Seq#       Checksum Link count
1.1.1.1         1.1.1.1         412    0x80000009 0x00A1B2  3
2.2.2.2         2.2.2.2         388    0x8000000C 0x0044F1  4

                Net Link States (Area 0)
Link ID         ADV Router      Age    Seq#       Checksum
10.255.0.2      2.2.2.2         388    0x80000003 0x00E2A9

Every router in an area holds an identical copy of this. If two routers in the same area show different databases, they are not fully adjacent — and that is a more precise diagnosis than any amount of staring at routing tables.

Areas: keeping the database small

Everything above happens per area. All routers in an area hold the same database and run SPF over it, so a single flapping link makes every router in that area recompute. In a network of five hundred routers that is unworkable, and the answer is to divide it.

OSPF areas have one structural rule: every area must connect to area 0, the backbone. Traffic between two non-backbone areas always passes through it. This is not a suggestion — it is what makes the design loop-free, because inter-area routing behaves like distance-vector between areas and needs a hub to stay safe.

flowchart TD
  A1["Area 1<br/>internal routers"] --- ABR1["ABR<br/>one foot in each area"]
  ABR1 --- A0["Area 0<br/>the backbone"]
  A0 --- ABR2["ABR"]
  ABR2 --- A2["Area 2<br/>internal routers"]
  A0 --- ASBR["ASBR<br/>redistributes external routes"]
Figure 3. Area structure. An area border router holds a separate database for each area it touches and passes prefixes between them as type 3 summaries — the detailed topology never crosses.
Router roleMeans
Internal routerAll its interfaces are in one area
Backbone routerHas at least one interface in area 0
Area border router (ABR)Interfaces in two or more areas, including area 0; holds a database per area
Autonomous system border router (ASBR)Redistributes routes into OSPF from elsewhere

The benefit is containment. A link flapping in area 1 causes SPF to run in area 1. Routers in area 2 see, at most, a type 3 summary appear or disappear, which is far cheaper to process. Area borders are also the only place OSPF can summarise, which is why address plans are designed so that each area owns a contiguous block.

For anything under about fifty routers, a single area 0 is entirely reasonable and much simpler to operate. Areas are a scaling tool, not a badge of seriousness.

Cost, and the mistake everyone makes once

OSPF's metric is cost, and the cost of an interface is:

cost = reference bandwidth / interface bandwidth

default reference bandwidth = 100 Mbps
LinkCost with default referenceCost with reference 100000
10 Mbps1010,000
100 Mbps11,000
1 Gbps1100
10 Gbps110

Look at the middle column. The formula rounds anything below 1 up to 1, so every link at 100 Mbps or faster has a cost of 1. A gigabit link and a ten-gigabit link are indistinguishable, and OSPF cheerfully sends traffic down the slower one.

The fix is to raise the reference bandwidth so that modern links produce distinct values:

Router(config-router)# auto-cost reference-bandwidth 100000   ! 100 Gbps, in Mbps

It must be set identically on every router in the domain. A mismatch means routers compute different costs for the same links, producing asymmetric paths and occasionally routing loops. Cisco logs a warning when you set it, and the warning is worth heeding.

Individual interfaces can also be set directly with ip ospf cost 50, which overrides the formula entirely and is the cleanest way to steer traffic away from a link you know to be expensive or unreliable.

Configuring it

Two syntaxes exist for saying which interfaces participate. The traditional one uses network statements with wildcard masks:

Router(config)# router ospf 1
Router(config-router)# router-id 1.1.1.1
Router(config-router)# network 10.1.1.0 0.0.0.255 area 0
Router(config-router)# network 10.255.0.0 0.0.0.3 area 0
Router(config-router)# passive-interface default
Router(config-router)# no passive-interface GigabitEthernet0/1

The newer per-interface syntax is clearer and increasingly preferred:

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

Four details are worth stating plainly.

The process ID is local. router ospf 1 on one router happily forms adjacencies with router ospf 47 on another. It has no protocol meaning at all — unlike BGP's autonomous system number, which must match.

The network statement selects interfaces, not networks. It means "any interface whose address falls in this range participates, in this area". The wildcard mask is the usual inverted mask, so 0.0.0.255 matches a /24. Getting this backwards is the most common OSPF configuration error there is.

The router ID matters and should be set. Chosen in order: an explicitly configured router-id, else the highest loopback address, else the highest active physical interface address. It is picked once at startup and does not change while the process runs. A loopback is the conventional source because it never goes down — but setting it explicitly is better still, because then it does not depend on addressing at all.

passive-interface default is a habit worth forming. It stops OSPF sending hellos out every interface while still advertising those interfaces' subnets, then you re-enable it only on the links that actually face another router. Without it, a router sends hellos onto user VLANs, which is wasted traffic at best and an invitation to a rogue neighbour at worst.

Advertising a default route

Router(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.1
Router(config)# router ospf 1
Router(config-router)# default-information originate

OSPF does not advertise a default route just because one exists. default-information originate tells the router that owns the internet connection to inject 0.0.0.0/0 into OSPF as an external route, so every other router learns where the exit is. Adding always makes it advertise even when it has no default route of its own, which is occasionally useful and usually a way to black-hole traffic.

Checking it

Router# show ip ospf neighbor          ! who am I adjacent to, and in what state
Router# show ip ospf interface brief   ! which interfaces run OSPF, in which area, at what cost
Router# show ip ospf database          ! the map itself
Router# show ip route ospf             ! what made it into the routing table
Router# show ip protocols              ! process ID, router ID, networks, passive interfaces

Those five in order answer nearly every OSPF question. Neighbours first — if the adjacency is not full, nothing else matters. Then interfaces, to check area and cost. Then the database, which is the ground truth. Then the routing table, to see what survived.

In the wild
  • Enterprise campuses run OSPF between distribution and core layers, with one area per building block and area 0 across the core.
  • Service providers more often run IS-IS, which is the same link-state idea with a different encoding, chosen partly because it is not tied to IP and carries IPv6 without a second protocol.
  • OSPFv3 is the IPv6 version, and it forms adjacencies over link-local addresses — so two routers can exchange routes before either has a global address configured.
LSA
Link-state advertisement: one router's description of part of the topology, flooded unchanged to every router in its scope.
LSDB
Link-state database: the collection of LSAs, identical on every router in an area.
Designated router
The router elected on a multi-access segment to be the flooding hub, so adjacencies scale linearly rather than quadratically.
ABR
Area border router: has interfaces in two or more areas including the backbone, and translates topology into summary prefixes between them.
Reference bandwidth
The numerator in the cost formula. Must be identical on every router, and must be raised above the 100 Mbps default on any modern network.

Recap

  • Link-state routers share descriptions of their own links, not conclusions, so every router builds the same map.
  • Each router runs Dijkstra against that map with itself as the root and installs the resulting best paths.
  • Hellos go to 224.0.0.5 every 10 seconds with a 40-second dead interval on Ethernet.
  • Area, timers, subnet and mask, authentication and stub flags must all match, or no adjacency forms.
  • An adjacency stuck in ExStart is almost always an MTU mismatch.
  • Two-way between routers that are neither DR nor BDR is normal, not a fault.
  • The designated router turns n-squared adjacencies into a hub and spoke; election is by priority then router ID, with no preemption.
  • Type 1 and 2 LSAs are the map, type 3 carries prefixes between areas, type 5 carries redistributed external routes.
  • Every area must touch area 0, which is what keeps inter-area routing loop-free.
  • Cost is reference bandwidth over interface bandwidth, so by default every link at 100 Mbps and above costs 1 — raise the reference bandwidth identically everywhere.
  • The process ID is local; the network statement selects interfaces using a wildcard mask; the router ID should be set explicitly.
  • passive-interface default then selective re-enabling keeps hellos off user-facing links.

Questions

Say the answer out loud before opening it.

What is the fundamental difference between link-state and distance-vector routing?

Distance-vector routers share their conclusions about reachability; link-state routers share raw descriptions of their own links and each compute the answer themselves.

  • Every router in a link-state area holds an identical database of the topology.
  • Dijkstra's algorithm is then run locally with the router as the root.
  • Because everyone sees the same map, loops are far less likely and convergence is much faster.

The trade is resource use: link-state needs memory for the database and CPU for SPF, which is exactly what areas were invented to bound.

What must match for two routers to become OSPF neighbours?

Area ID, hello and dead intervals, subnet and mask, authentication, and stub area flags. MTU must also agree or the exchange fails later.

  • The hello packet carries most of these, so a mismatch prevents the neighbour ever reaching init.
  • A subnet mask typo puts the two interfaces in different subnets and is a very common cause.
  • MTU is not in the hello, which is why an MTU mismatch produces a stuck ExStart rather than no neighbour at all.

The process ID is notably not on the list — it is locally significant and two routers with different process IDs form adjacencies happily.

Why would a neighbour be stuck in ExStart?

Almost always an MTU mismatch between the two interfaces.

  • ExStart is where database description packets are first exchanged, and those can be large.
  • One side sends a packet the other cannot accept, so the exchange restarts endlessly.
  • show ip ospf interface shows the MTU on each side for comparison.

It can be worked around with ip ospf mtu-ignore, but that hides a real inconsistency that will cause packet loss for ordinary traffic too.

Why does a designated router exist, and how is it elected?

To stop adjacencies growing quadratically on a multi-access segment; it is elected by highest interface priority, then highest router ID, with no preemption.

  • Every router forms a full adjacency with the DR and BDR and only two-way with the rest.
  • Updates go to the DR at 224.0.0.6 and are flooded by it to 224.0.0.5.
  • A priority of 0 excludes a router from the election entirely.

No preemption means the first router to come up keeps the role, so setting priority after the fact requires clearing the process or bouncing the interface to force a new election.

Is a neighbour in 2WAY/DROTHER a problem?

No. Two routers on a multi-access segment that are neither DR nor BDR deliberately stop at two-way.

  • They both synchronise their databases with the DR instead of with each other.
  • Full adjacency between them would duplicate flooding for no benefit.
  • On a point-to-point link there is no DR, so both neighbours should reach full.

Seeing every neighbour on a segment in two-way, with none in full, is different and does indicate a problem — usually that no DR was elected because every router has priority 0.

What do type 1, 2, 3 and 5 LSAs describe?

Type 1 is a router describing its own links, type 2 is the DR describing who is on a multi-access segment, type 3 is an area border router advertising a prefix from another area, and type 5 is an external route redistributed into OSPF.

  • Types 1 and 2 together are the topology map and never leave their area.
  • Type 3 carries prefixes across areas without the underlying topology.
  • Type 5 floods throughout the domain except into stub areas.

This is why inter-area routing behaves like distance-vector: outside its own area a router sees prefixes and costs rather than a map, which is the reason every area must attach to area 0.

Why must every OSPF area connect to area 0?

Because routing between areas is done with summaries rather than full topology, so a hub-and-spoke structure is what keeps it loop-free.

  • An area border router has a database per area and passes prefixes between them.
  • Traffic between two non-backbone areas always transits the backbone.
  • A physically separated area can be attached with a virtual link, which is a workaround rather than a design.

Without the rule, two areas could advertise summaries to each other in a cycle with no way to detect it, which is precisely the failure mode link-state routing was designed to avoid.

How is OSPF cost calculated, and what is wrong with the default?

Cost is reference bandwidth divided by interface bandwidth, with a default reference of 100 Mbps — so every interface at 100 Mbps or faster gets a cost of 1.

  • A gigabit link and a ten-gigabit link become indistinguishable.
  • The fix is auto-cost reference-bandwidth 100000, set identically on every router.
  • Individual interfaces can also be given an explicit cost with ip ospf cost.

A mismatched reference bandwidth is worse than the default, because routers then compute different costs for the same link and can produce asymmetric or looping paths.

How is the OSPF router ID chosen?

An explicitly configured router-id first, otherwise the highest loopback address, otherwise the highest active physical interface address — decided once at process start.

  • It does not change while the process runs, even if a better candidate appears.
  • Loopbacks are preferred because they never go down.
  • Changing it requires clearing the OSPF process, which drops all adjacencies.

Setting it explicitly is best practice because it makes the database readable — a router ID that matches the device's management address is far easier to trace than one that happens to be a transit link.

What does the network statement actually do?

It selects which interfaces participate in OSPF, and in which area, by matching their addresses against a wildcard mask.

  • It does not advertise a network directly; it enables OSPF on the matching interfaces, which then advertise their own subnets.
  • The mask is a wildcard, so 0.0.0.255 matches a /24.
  • network 0.0.0.0 255.255.255.255 area 0 enables OSPF everywhere, which is quick and rarely wise.

The per-interface form ip ospf 1 area 0 says the same thing without the indirection, and is clearer in any configuration somebody else has to read.

What does passive-interface do and why use it by default?

It stops OSPF sending hellos out an interface while still advertising that interface's subnet; setting it by default and re-enabling selectively keeps hellos off links that face no routers.

  • Hellos on user VLANs are wasted traffic and let anyone attempt to become a neighbour.
  • The subnet is still advertised, so hosts on it remain reachable.
  • no passive-interface on each router-facing link re-enables adjacency formation.

Forgetting to re-enable it on a real link is a common self-inflicted outage, and it presents as an adjacency that never forms despite matching configuration on both ends.

How do you advertise a default route into OSPF?

default-information originate on the router that has the default route, which injects 0.0.0.0/0 as an external LSA.

  • OSPF does not advertise a default route automatically just because one is configured.
  • The always keyword advertises it even when the router has no default of its own.
  • Other routers see it as an external route with the O*E2 code.

always is risky precisely because it keeps advertising after the upstream link fails, drawing traffic to a router that then discards it.

Two routers are adjacent but a prefix is missing from the routing table. Where do you look?

The link-state database, which is the ground truth — if the prefix is not there, it was never advertised; if it is there but not in the routing table, something is preventing installation.

  • show ip ospf database shows whether the LSA exists at all.
  • A route present in the database but absent from the table often means a better administrative distance elsewhere, such as a leftover static route.
  • A missing LSA points back at the originating router's network statement or a passive interface.

Comparing databases on two routers in the same area is also decisive: they must be identical, and any difference means the adjacency is not truly full.

Why configure an Ethernet link between two routers as point-to-point?

Because with only two routers there is no benefit to a designated router, and skipping the election speeds up convergence and simplifies the database.

  • ip ospf network point-to-point on both ends removes the DR and BDR roles.
  • No type 2 network LSA is generated for that segment.
  • The wait timer for the election, normally 40 seconds, is avoided entirely.

It must be configured on both ends, since network type is one of the things that has to match for an adjacency to form correctly.

When is one area enough, and when should you split?

A single area 0 is fine up to roughly fifty routers; split when SPF runtime, database size or the blast radius of a flapping link becomes a problem.

  • Every router in an area recomputes SPF when anything in that area changes.
  • Areas contain that recomputation and allow summarisation at their borders.
  • Summarisation only works if each area owns a contiguous address block, so the address plan has to come first.

Splitting into areas without an address plan that permits summarisation gains almost nothing, since the same number of prefixes still crosses every border as individual type 3 LSAs.