Skip to content

CCNA course / Connect networks with routers · Step 2 of 14

Guide: OSPFSwitch

Guide

OSPF: how routers find neighbors, build the database and pick routes (CCNA and CCNP)

OSPF is a link-state routing protocol. Routers discover neighbors, synchronize link-state databases within areas, run the Shortest Path First calculation, then install the best eligible routes. This guide explains the commands and behaviors tested in the associated CCNA, OSPFv3 and ENCOR questions.

9 parts · video · 47 practice questions

OSPFv2 configuration and router identity (CCNA OSPFv2)

OSPFv2 carries IPv4 routes. The number in router ospf 1 is a locally significant process ID: it selects the process on that router and does not have to match a neighbor's process ID. A router-process network statement uses an IPv4 address and wildcard mask, which is the inverse of a subnet mask, to select local interfaces. The area value places each matching interface in an area. For example, 10.0.12.0/30 has mask 255.255.255.252 and wildcard 0.0.0.3. An all-ones wildcard, 255.255.255.255, matches every interface address.

OSPF code in show ip route
O
Default administrative distance
110

OSPF must be enabled on an interface for it to participate. Making an OSPF interface passive suppresses Hello packets and neighbor formation on that interface but continues advertising its connected prefix into OSPF. It does not turn off ordinary IP forwarding.

An OSPF router ID is a unique 32-bit identifier written in IPv4 dotted notation. An explicitly configured router-id takes precedence. Otherwise Cisco IOS chooses the highest IPv4 address on a loopback if one exists, or the highest IPv4 address on an active physical interface if not. If the process is already active with neighbors, a changed router ID takes effect after an OSPF process restart or reload; restarting OSPF resets its adjacencies. Duplicate IDs can produce syslog messages such as %OSPF-4-DUP_RTRID1 or %OSPF-4-DUP_RTRID2 on IOS releases that use those message codes. Configure unique IDs to avoid duplicate-ID problems.

A route learned through OSPF appears with code O in show ip route. OSPF's default administrative distance is 110. Administrative distance compares sources for the same prefix on one router; it is not the OSPF path metric and is not advertised to neighbors. show ip protocols summarizes the routing process, router ID, configured networks and areas, ASBR status, and administrative distance.

A router that injects routes from outside the OSPF domain, including an external default route, is an Autonomous System Boundary Router (ASBR). default-information originate advertises a default route when one is present in the local routing table. The always option removes that requirement, so use it only when advertising a default without a known local default is intentional.

IOS XE
router ospf 1
 network 10.0.12.0 0.0.0.3 area 0
 passive-interface GigabitEthernet0/1
 router-id 1.1.1.1
 default-information originate
show ip protocols
show ip route
Practice this part:CCNA: OSPF (20)
References (2)

Neighbor states and adjacency checks

OSPF neighbors progress through Down, Init, 2-Way, ExStart, Exchange, Loading and Full. Init means a Hello arrived, but it did not list this router's ID. In 2-Way, each router sees its own ID in the other's Hello, confirming two-way communication. On multiaccess networks, the DR and BDR election completes before routers move from 2-Way to ExStart. ExStart negotiates a primary/subordinate relationship and the initial Database Description (DBD) sequence number; the router with the higher router ID is primary. Exchange sends DBD summaries of the databases; Loading requests missing or newer LSAs; Full means the adjacency databases are synchronized.

The same walkthrough as a 28 second clip: the working adjacency, then a one-way Hello. Watch on its own page

On broadcast and NBMA multiaccess networks, two DROTHER routers normally remain 2-Way with each other. They form Full adjacencies with the DR and BDR. Therefore a stable 2-Way/DROTHER entry is expected, not a failed neighbor. A broadcast segment with only two routers that both have priority 0 has no eligible DR or BDR, so those routers can remain 2-Way.

For neighbors to form, their interfaces must agree on area and Hello and Dead intervals, and authentication settings must be compatible when used. A network-type mismatch is one possible adjacency problem, but the needed compatibility depends on the configured types. The process IDs and hostnames are local and do not need to match. A one-sided INIT indication with no neighbor entry on the other side points to one-way Hello delivery, such as a filter dropping packets in one direction. Check connectivity and multicast or protocol filtering.

Use show ip ospf neighbor for router IDs, states, dead timers and local interfaces. Use show ip ospf interface for area, network type, cost, timers, priority and DR/BDR information. show ip protocols is a process summary, while show ip ospf database displays LSAs rather than a concise neighbor list.

IOS XE
show ip ospf neighbor
show ip ospf interface GigabitEthernet0/0
show ip protocols
References (2)

DR/BDR elections and OSPF network types

Broadcast Ethernet and NBMA multiaccess networks elect a Designated Router (DR) and Backup Designated Router (BDR) to reduce the number of full adjacencies and coordinate network-LSA origination. The highest interface OSPF priority wins; the default priority is 1 and priority 0 makes a router ineligible. Router ID breaks a priority tie, with the higher ID winning. Elections are non-preemptive: a later, higher-priority router does not displace an existing DR. Routers that are neither DR nor BDR are DROTHERs.

Point-to-point networks do not elect a DR or BDR because there are only two endpoints, so they avoid the broadcast DR/BDR wait period and can reach Full sooner. Point-to-multipoint treats a shared medium as separate point-to-point relationships and also has no DR/BDR election. Its normal multicast form discovers neighbors automatically. Point-to-multipoint non-broadcast suppresses multicast, so configure neighbors explicitly. NBMA also uses explicit neighbor statements but does elect a DR and BDR. These properties apply to the OSPF network type, not merely the physical cable label.

IOS XE
interface GigabitEthernet0/0
 ip ospf priority 0
 ip ospf network point-to-point
 ip ospf network point-to-multipoint
 ip ospf network point-to-multipoint non-broadcast
router ospf 1
 neighbor 10.0.0.2
References (3)

Cost, equal paths and route preference

OSPF's interface cost is normally the reference bandwidth divided by the interface bandwidth, using Mbps. Cisco IOS defaults the reference bandwidth to 100 Mbps. Consequently, faster links can receive the same minimum cost unless the reference bandwidth is raised consistently across the OSPF domain. An explicit ip ospf cost overrides the calculated value. A route's path cost is the sum of interface costs along the path; OSPF can install multiple equal-cost paths, bounded by the platform and maximum-paths setting. Forwarding may load-share flows across paths; equal-cost routes do not imply alternating packets.

Interface cost
reference bandwidth / interface bandwidth (Mbps)
Default reference bandwidth
100 Mbps
Route class preference
O, then O IA, then O E1, then O E2

For competing OSPF paths to the same prefix, route class preference is intra-area O, then inter-area O IA, then external type 1 O E1, then external type 2 O E2. Cost is compared within the relevant class. E1 includes the internal OSPF cost to the ASBR plus the external metric; E2 compares the external metric, using internal cost as a tie-breaker. This OSPF path-class selection is separate from administrative distance, which compares OSPF with other routing sources for the same prefix.

IOS XE
router ospf 1
 auto-cost reference-bandwidth 10000
interface GigabitEthernet0/0
 ip ospf cost 20
 maximum-paths 4
References (4)

Areas, backbone and OSPFv2 LSA types

An area limits link-state flooding and SPF calculation scope. Area 0 is the backbone. OSPF's hierarchical inter-area routing expects every non-backbone area to connect to area 0, directly or through a virtual link over a standard non-backbone transit area. Stub areas and NSSAs cannot be transit areas for a virtual link. An ABR connects areas and advertises inter-area reachability; an ASBR injects routes from outside the OSPF domain.

OSPFv2 Type 1 Router LSAs are originated by each router and describe its area links and costs. Type 2 Network LSAs are originated by the DR for a multiaccess segment and list the attached routers. Type 3 Summary LSAs are originated by ABRs to advertise network reachability between areas. Type 4 ASBR Summary LSAs are originated by ABRs to tell routers in another area how to reach an ASBR. Type 5 AS External LSAs carry redistributed external routes through the OSPF domain.

A standard stub area blocks Type 4 and Type 5 LSAs and its ABR supplies a default route as a Type 3 LSA. An NSSA also blocks incoming Type 5 LSAs, but allows a local ASBR to redistribute external routes as Type 7 LSAs. An NSSA ABR translates Type 7 LSAs whose P-bit requests propagation into Type 5 LSAs for the rest of the OSPF domain. With multiple NSSA ABRs, Cisco IOS selects the highest-router-ID ABR from the translator candidates; an ABR configured as a forced translator overrides the election. The DR does not perform translation.

IOS XE
router ospf 1
 area 1 stub
 area 2 nssa
 area 2 virtual-link 2.2.2.2
show ip ospf database
References (2)

OSPFv3 for IPv6

OSPFv3 was designed for IPv6, and Catalyst IOS XE also supports carrying IPv4 routing information with address families. This does not mean OSPFv3 is limited to IPv6 routes. Cisco IOS traditional configuration enables it per interface instead of selecting interfaces with IPv4-style router-process network statements. Enable IPv6 unicast routing globally, provide an IPv6-enabled interface, assign a 32-bit router ID, and apply ipv6 ospf <process> area <area> to the interface. IOS XE also supports the address-family style: under router ospfv3 1, enter address-family ipv6 unicast. On Cisco IOS XE 17.x routing platforms, the interface command is ospfv3 1 ipv6 area 0. Check the target platform and release command reference because this syntax varies. OSPFv3 still uses a 32-bit router ID in IPv4 dotted notation. If the router has no IPv4 address from which to select one, configure it manually.

On ordinary links, OSPFv3 packets use the interface's IPv6 link-local address as their source, so a link-local address is required even when no global IPv6 address is configured. FF02::5 is AllSPFRouters; the 02 denotes link scope. FF02::6 is AllDRouters. OSPFv3 uses FF02::5 to communicate with neighbors and FF02::6 to send LSA updates to the DR and BDR.

OSPFv3 uses the same neighbor state logic and DR behavior described above. Catalyst IOS XE Ethernet interfaces use the broadcast network type by default, which elects a DR and BDR. The default Hello interval is 10 seconds, the Dead interval is four times the Hello interval, and the Wait interval is the Dead interval. show ipv6 ospf neighbor lists OSPFv3 neighbors; show ipv6 neighbors is the IPv6 Neighbor Discovery cache, not an OSPF command. OSPF route administrative distance defaults to 110 for both OSPFv2 and OSPFv3 on Cisco IOS. For comparison, Cisco's default distances are 90 for internal EIGRP, 120 for RIP, and 1 for a static route.

IOS XE
ipv6 unicast-routing
ipv6 router ospf 1
 router-id 1.1.1.1
interface GigabitEthernet0/0
 ipv6 enable
 ipv6 ospf 1 area 0
show ipv6 ospf neighbor
OSPFv3 Hello debug (Cisco example)
*Mar  8 17:47:01.324: OSPFv3-1-IPv6 PAK  : Gi0/0: OUT: FE80::5054:FF:FE00:3A->FF02::5: ver:3 type:1 len:36 rid:10.3.3.3 area:0.0.0.2 chksum:A0F9 inst:0
*Mar  8 17:47:03.307: OSPFv3-1-IPv6 PAK  : Gi0/0:  IN: FE80::5054:FF:FE00:15->FF02::5: ver:3 type:1 len:36 rid:10.1.1.1 area:0.0.0.2 chksum:A31C inst:0

Example output from Cisco documentation.

Practice this part:CCNA: OSPFv3 for IPv6 (11)
References (7)

OSPFv3 Link LSAs

OSPFv3 Type 8 Link LSAs have link-local flooding scope. They carry the originating router's link-local address, IPv6 prefixes associated with that link, and options bits associated with the network LSA, and are not flooded beyond that link. They are distinct from Type 9 Intra-Area-Prefix LSAs, which associate IPv6 prefixes with a router or network LSA within an area. OSPFv3 moved IPv6 prefix information out of the Router and Network LSAs used to describe topology.

IOS XE
show ipv6 ospf database link
References (2)

Troubleshooting neighbors and database exchange

If a neighbor does not appear, first verify interface state, OSPF enablement, area, network type, authentication, and matching Hello and Dead timers. The common broadcast defaults are Hello 10 seconds and Dead 40 seconds, with the dead interval normally four times the Hello interval; the values must match at both ends. A mismatched process ID alone does not prevent an adjacency. INIT on one router while the other sees no neighbor suggests Hello packets reach only one direction.

A neighbor stuck in ExStart or Exchange is attempting DBD exchange. An MTU mismatch is a common and characteristic cause because a router can reject a DBD whose advertised interface MTU is too large. Compare show interfaces MTU values and correct the mismatch at both ends; ip ospf mtu-ignore bypasses detection and is a rare workaround, not the normal repair. MTU is not the only possible cause: duplicate router IDs, network-type mismatch, DBD sequence problems, and packet filtering can also interfere. A duplicate router ID is more directly indicated by a duplicate-ID OSPF syslog message; message text and codes vary by software release, so verify against that release's system message guide rather than assuming a particular code.

Use evidence from the output before changing configuration. show ip ospf neighbor reveals state, show ip ospf interface reveals timers, network type and DR/BDR, show interfaces reveals MTU and link status, and show ip ospf database inspects learned LSAs. A stable 2-Way state between two DROTHERs on broadcast media is expected; restarting OSPF there interrupts service without fixing anything.

IOS XE
show ip ospf neighbor
show ip ospf interface
show interfaces GigabitEthernet0/0
show ip ospf database
References (1)

CCNP ENCOR OSPF depth

The preceding sections cover the ENCOR concepts as well as the CCNA basics: database description negotiation occurs in ExStart, where routers establish a primary/subordinate relationship and choose the initial DBD sequence number; the higher router ID becomes primary. Bidirectional Hello recognition is 2-Way, and on multiaccess networks the DR/BDR election completes before ExStart. Type 3 and Type 4 LSAs are ABR summaries, and Type 8 OSPFv3 Link LSAs carry link-local information. For quick recall, Type 1 is router topology, Type 2 is a DR's multiaccess network, Type 3 is inter-area network reachability, Type 4 is reachability to an ASBR, Type 5 is external reachability, and Type 7 is external reachability inside an NSSA.

The network-type choices matter on multiaccess links: point-to-point has no election, point-to-multipoint has no election and discovers neighbors with multicast, point-to-multipoint non-broadcast has no election but needs explicit neighbors, and NBMA needs explicit neighbors while still electing DR/BDR. On broadcast networks, only the DR and BDR have Full adjacencies with each DROTHER; two DROTHERs normally remain 2-Way.

Apply route preference in order: O, O IA, O E1, O E2. A higher OSPF metric does not make an external route beat an intra-area route. For interface costs above 100 Mbps, set a larger reference bandwidth consistently across routers, or explicitly set costs where the design requires it.

IOS XE
show ip ospf neighbor
show ip ospf database
show ipv6 ospf database
Practice this part:CCNP ENCOR: OSPF (CCNP) (16)
References (3)

Check your understanding

OSPF: how routers find neighbors, build the database and pick routes (CCNA and CCNP)

All 9 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.