Course contents

Module 1: Understanding OSPFLesson 1.3 (3 of 4 in this module)3 of 29 in the OSPF course

What is OSPF?

How do routers learn which path to use without an engineer entering every route? Let's follow the information from one router to its routing table.

Intermediate · 11 min read

What problem does OSPF solve?

A router needs a route before it can send a packet towards another network. A route tells it which neighbouring router to use next. You can enter routes by hand, but a growing network needs many entries and changes can make them out of date.

OSPF (Open Shortest Path First) lets routers share information about their connections. Each router uses that information to choose routes. If a connection fails and another usable path exists, OSPF can calculate a new path. It cannot create a path where there is no working connection.

In the example, a user on LAN A opens an internal website on LAN B. R1 is the router near the user. R4 connects to the server's LAN. R2 and R3 provide two possible paths between them. OSPF learns the paths; the routers then forward the user's packets.

Two paths, one destination
The task: an office user opens an internal websitehttp://192.168.4.10

PC-A sends a web request to the web server. The routers must find a working path between them.

Two paths, one destinationLAN A reaches LAN B through R2. The lower path through R3 is available but has a higher OSPF cost. PC-A at 192.168.1.10 connects through access switch SW1 to router R1 on LAN A, 192.168.1.0/24. The web server at 192.168.4.10 connects through access switch SW2 to router R4 on LAN B, 192.168.4.0/24. R1 can route through R2 or R3 to R4. Solid grey lines are physical connections; switches forward within each LAN. All physical links are up.cost 1cost 1cost 10cost 1R1R2R3R4SW1 · switchSW2 · switchPC-A · userWeb server192.168.1.10192.168.4.10LAN ALAN B192.168.1.0/24192.168.4.0/24Purple arrow: PC-A → SW1 → R1 → R2 → R4 → SW2 → server

R1–R4: routers join different networks. SW1/SW2: switches connect devices within each LAN; they do not add routed hops or extra OSPF costs.

Grey lines: Ethernet connections. SW1 and SW2 are access switches. Purple arrow: the web request's path. The response travels back; it is not drawn here.

Device IP: 192.168.4.10 identifies this server. Subnet: 192.168.4.0/24 identifies its network, not a device or website. URL: http://192.168.4.10 tells the browser to request a web page at that IP.

Example OSPF route
Destination subnet
192.168.4.0/24
Next hop · router interface IP
10.0.12.2 · R2
Forwarding path
R1 → R2 → R4
OSPF cost
3
Diagram details · example interface map
R1 · RID 1.1.1.1
Gi0/0: 192.168.1.1/24 → LAN A; Gi0/1: 10.0.12.1/30 → R2; Gi0/2: 10.0.13.1/30 → R3.
R2 · RID 2.2.2.2
Gi0/0: 10.0.12.2/30 → R1; Gi0/1: 10.0.24.1/30 → R4.
R3 · RID 3.3.3.3
Gi0/0: 10.0.13.2/30 → R1; Gi0/1: 10.0.34.1/30 → R4.
R4 · RID 4.4.4.4
Gi0/0: 192.168.4.1/24 → LAN B; Gi0/1: 10.0.24.2/30 → R2; Gi0/2: 10.0.34.2/30 → R3.
LAN gateways and switch ports
PC-A gateway: 192.168.1.1. Server gateway: 192.168.4.1. Each access switch uses Gi0/1 to its endpoint and Gi0/2 to its router; endpoints use Ethernet ports.
OSPF assumptions and costs
Area 0; broadcast Ethernet; Hello 10 / Dead 40 seconds; no authentication; LAN interfaces passive. R1–R3 cost 10 in both directions; other outgoing interfaces, including the LANs, cost 1. Switches do not run OSPF here.
LAN A reaches LAN B through R2. The lower path through R3 is available but has a higher OSPF cost.

The OSPF process on one router

On a Cisco router OSPF is off until you start it. Starting it creates an OSPF process: a program running on the router alongside everything else, with a number you choose.

router ospf 1

Global configuration mode. Starts OSPF process 1 (any number from 1 to 65535).

The process ID, 1 here, identifies this OSPF process on this router. R2 could use process 20 and still become R1's neighbour. Creating a process alone does not turn on OSPF on every interface. You must also select the interfaces that should take part.

Compare the OSPF tables and the three kinds of ID
Inside R1: neighbours → map → routes
Inside R1: neighbours → map → routesA processing flow, not three network cables. Neighbours supply link-state information; SPF uses the LSDB to calculate paths. The routing table selects routes from OSPF and other sources. R1 has neighbours R2 and R3. The area-0 LSDB contains link information from R1 through R4. The selected route to 192.168.4.0/24 goes via R2 at cost 3. Inspect with show ip ospf neighbor, show ip ospf database and show ip route ospf.R1 neighboursR2 · R3show ip ospf neighborLSDB · area 0R1 linksR2 linksR3 linksR4 linksshow ip ospf databaseRouting table192.168.4.0/24via R2 · cost 3Next hop selectedshow ip route ospfSPF**SPF calculates OSPF paths; route selection decides what is installed.
A processing flow, not three network cables. Neighbours supply link-state information; SPF uses the LSDB to calculate paths. The routing table selects routes from OSPF and other sources.
Three numbers, three different jobs
R1 · router
Local process ID
1
Router ID · OSPF identity
1.1.1.1
Gi0/1 · interface IPv4
10.0.12.1/30
R2 · router
Local process ID
10
Router ID · OSPF identity
2.2.2.2
Gi0/0 · interface IPv4
10.0.12.2/30
Ethernet connection · area 0
10.0.12.0/30 is the shared subnet. The routers exchange OSPF control packets here.
Read the labels: process IDs can differ. Router IDs must be unique; they identify OSPF speakers and need not be reachable addresses. Interface IPs address the actual link. None of these numbers is a website URL.

The router ID

The router ID (RID) identifies a router in OSPF. It is written like an IPv4 address, such as 1.1.1.1, but it does not have to be the address used to reach the router. Give each OSPF router a different ID.

On Cisco IOS, a configured router ID is used first. If none is set, IOS chooses the highest IPv4 address on an available loopback interface. A loopback is a software interface rather than a physical socket. If there is no usable loopback, IOS chooses the highest IPv4 address on an active physical interface.

See how IOS chooses a router ID
Router ID: stop at the first usable choice
Router ID: stop at the first usable choiceFollow the Yes/No branches when Cisco IOS starts OSPF. Set a unique router-id explicitly for a predictable identity. First use an explicit router-id. Otherwise use the highest IPv4 address on an up loopback. Otherwise use the highest IPv4 address on another up interface. If none is available, configure a router ID before continuing.OSPF startsrouter-id set?YesUse configured RIDUp loopback?YesHighest loopback IPv4Other up IPv4?YesHighest interface IPv4NoNoNoNo RID · configure router-id
Follow the Yes/No branches when Cisco IOS starts OSPF. Set a unique router-id explicitly for a predictable identity.
router ospf 1 router-id 1.1.1.1

Setting the RID by hand is normal practice: it is predictable and doesn't change when interfaces are added.

If none of the three gives an address (for example, a router with no IPv4 addresses yet), the process can't start, and IOS logs a message like this:

Illustrative IOS output · written for this lesson, not a lab capture
%OSPF-4-NORTRID: OSPF process 1 failed to allocate unique router-id and cannot start
The fix is to configure router-id or give the router a working IPv4 address.

Set the RID before forming adjacencies. Applying a changed RID may require an OSPF process restart, depending on the IOS release. Check the active ID with show ip ospf. Restarting with clear ip ospf process disrupts this process's adjacencies.

Neighbours: who to talk to

An OSPF neighbour is another OSPF router found on a connected link. R1 sends small Hello messages to discover R2 and R3 and check that they are still there. On Cisco broadcast and point-to-point interfaces, the default Hello interval is normally 10 seconds.

Routers that need to exchange their network records build a closer connection called an adjacency. When the required information has been exchanged, the connection is Full. A passive interface advertises its network without sending Hellos or building neighbours there.

On a shared Ethernet LAN, routers also choose a designated router (DR) to help share OSPF updates and a backup designated router (BDR) to take over if it fails. These are roles given to existing routers. The DR does not choose routes for everyone else.

Illustrative IOS output · written for this lesson, not a lab capture
R1#show ip ospf neighbor
Neighbor ID     Pri   State           Dead Time   Address         Interface
2.2.2.2           1   FULL/DR         00:00:36    10.0.12.2       GigabitEthernet0/1
3.3.3.3           1   FULL/DR         00:00:33    10.0.13.2       GigabitEthernet0/2
Neighbor ID is the neighbour's router ID; Address is its IP address on the shared link. FULL means their maps are in sync. DR is explained in the DR/BDR lesson.

Links, link state and LSAs

A link is a connection to another router or network. Its link state describes information such as which network it reaches and the cost of using it. A link-state advertisement (LSA) is an OSPF record carrying network information. It is not a user's web request.

For example, R4 reports that it connects to LAN B and to the other routers. Its router LSA describes its own links and their costs. Other LSA types describe shared LANs or networks reached through another area.

Read an example of R4's link information
R4 describes its connections
R4 describes its connectionsSolid lines are network links. This is a teaching view of R4’s area-0 link information, not the wire encoding of a router LSA. All outgoing interface costs shown here are 1; the user LAN has no OSPF neighbour. R4, RID 4.4.4.4, connects through Gi0/1 to R2, RID 2.2.2.2, on subnet 10.0.24.0/30; through Gi0/2 to R3, RID 3.3.3.3, on 10.0.34.0/30; and through Gi0/0 to a LAN B switch on 192.168.4.0/24.R4 · routerR2 · routerR3 · routerLAN B switchGi0/1 · cost 110.0.24.0/30Gi0/2 · cost 110.0.34.0/30Gi0/0 · cost 1192.168.4.0/24RID2.2.2.2RID3.3.3.3User LANNo neighbourRID 4.4.4.4
Solid lines are network links. This is a teaching view of R4’s area-0 link information, not the wire encoding of a router LSA. All outgoing interface costs shown here are 1; the user LAN has no OSPF neighbour.

An LSA describes the network; SPF calculates the route.

Flooding: pass the information to other routers

R4 creates an LSA and sends it to the routers with which it has an adjacency. They pass it on where OSPF requires. This controlled sharing is called flooding. It gives the routers in the area the information they need about R4's links, even if they do not connect directly to R4.

OSPF uses a sequence number to tell newer versions of a record from older ones. Routers confirm receipt and send records again when needed. This is how OSPF keeps its information up to date without treating every received copy as a new change.

Follow an update across the example network
Learn the network before choosing a path
Learn the network before choosing a pathR4 describes its LAN in link-state information. Routers flood LSAs through the area, build their databases and calculate paths locally. PC-A at 192.168.1.10 connects through access switch SW1 to router R1 on LAN A, 192.168.1.0/24. The web server at 192.168.4.10 connects through access switch SW2 to router R4 on LAN B, 192.168.4.0/24. R1 can route through R2 or R3 to R4. Solid grey lines are physical connections; switches forward within each LAN. All physical links are up.cost 1cost 1cost 10cost 1LSAs describeLAN BR1R2R3R4SW1 · switchSW2 · switchPC-A · userWeb server192.168.1.10192.168.4.10LAN ALAN B192.168.1.0/24192.168.4.0/24Dashed arrows: OSPF link-state information
After SPF on R1
Destination subnet
192.168.4.0/24
Next hop · router interface IP
10.0.12.2 · R2
Forwarding path
R1 → R2 → R4
OSPF cost
3
Diagram details · example interface map
R4’s link information · interface IPv4
R4 Gi0/1: 10.0.24.2/30 → R2; Gi0/2: 10.0.34.2/30 → R3; Gi0/0: 192.168.4.1/24 → LAN B.
R1’s possible next hops
Gi0/1: 10.0.12.1/30 → R2 at 10.0.12.2; Gi0/2: 10.0.13.1/30 → R3 at 10.0.13.2. RIDs in the OSPF views: R1 1.1.1.1, R2 2.2.2.2, R3 3.3.3.3, R4 4.4.4.4.
LAN gateways
PC-A uses R1 Gi0/0 at 192.168.1.1; the server uses R4 Gi0/0 at 192.168.4.1. Both endpoint masks are /24 (255.255.255.0). Transit links are /30 (255.255.255.252).
Routing example
OSPF area 0; link costs are configured metrics, not measured speed. Dashed arrows carry link-state information; a solid coloured path carries the user’s request.
R4 describes its LAN in link-state information. Routers flood LSAs through the area, build their databases and calculate paths locally.

The LSDB and SPF: same map, different starting points

Each router stores OSPF records in its link-state database (LSDB). Think of it as the network information used to build a map. Once information has finished spreading, routers in the same area agree on that area's topology records.

Shortest path first (SPF) is the calculation that finds the lowest-cost paths from that map. Each router starts the calculation from its own position. R1 and R4 can have the same map but choose different next hops because they start in different places.

The routing table is the list used to choose where packets go. OSPF offers its calculated routes to this table. A route from another source can be preferred, so an LSA in the database does not automatically mean an OSPF route is installed.

Compare the database with the routes each router chooses
Same topology records, different route calculations
Same topology records, different route calculationsAfter convergence in this single area, R1 and R3 hold the same area topology records. Each runs SPF from itself. The paths below go to LAN B, 192.168.4.0/24; they include R4’s LAN interface cost of 1. Both databases contain area-0 records from R1 through R4. R1 selects R1 to R2 to R4, cost 1 plus 1 plus 1 equals 3. R3 selects R3 to R4, cost 1 plus 1 equals 2.R1 · SPF rootLSDB: R1, R2, R3, R4Area-0 topology recordsR1 → R2 → R4Cost 1 + 1 + 1 = 3R3 · SPF rootLSDB: R1, R2, R3, R4Area-0 topology recordsR3 → R4Cost 1 + 1 = 2=
After convergence in this single area, R1 and R3 hold the same area topology records. Each runs SPF from itself. The paths below go to LAN B, 192.168.4.0/24; they include R4’s LAN interface cost of 1.

Cost: how paths are compared

Lowest total outgoing cost wins. Cisco derives cost from configured interface bandwidth, or you can override it with ip ospf cost.

cost = reference bandwidth ÷ interface bandwidth, with a default reference bandwidth of 100 Mbps and a minimum cost of 1.
10 Mbps → 100 ÷ 10 = 10 · 100 Mbps → 1 · 1 Gbps → 0.1, rounded up to 1.

Cost is a number used to compare OSPF paths, not a measurement of the time a packet takes to arrive. Add the costs of the outgoing interfaces along a path, including the interface towards the destination network. Compare paths to the same network and of the same OSPF route type; the lower total is preferred.

Compare the two path costs
Count outgoing interfaces, including the destination LAN
Count outgoing interfaces, including the destination LANR1 calculates the route to LAN B (192.168.4.0/24). Add each outgoing interface cost, including R4’s LAN interface. R1–R3 costs 10 in both directions; all other interfaces cost 1. Selected: R1 to R2 to R4 to LAN B, cost 1 plus 1 plus 1 equals 3. Alternative: R1 to R3 to R4 to LAN B, cost 10 plus 1 plus 1 equals 12. The endpoint switch represents LAN B, not an extra routed hop.Selected through R2 · 1 + 1 + 1 = 3Alternative through R3 · 10 + 1 + 1 = 12R1R2R4LAN B111R1R3R4LAN B1011
R1 calculates the route to LAN B (192.168.4.0/24). Add each outgoing interface cost, including R4’s LAN interface. R1–R3 costs 10 in both directions; all other interfaces cost 1.
Illustrative IOS output · written for this lesson, not a lab capture
R1#show ip route ospf
O     192.168.4.0/24 [110/3] via 10.0.12.2, 00:02:11, GigabitEthernet0/1
O = learned by OSPF. [110/3] = administrative distance 110 (OSPF's trust level) / metric 3 (the total cost). Next hop 10.0.12.2 is R2.

You can set an explicit interface cost with ip ospf cost. Networks built on gigabit and faster links usually raise the reference bandwidth, and they do it on every router. Left at 100 Mbps, a 1 Gbps path and a 10 Gbps path look exactly the same to SPF.

Areas: keeping the map manageable

An area is a part of an OSPF network. Routers share detailed information about links inside that area. Splitting a large network into areas limits how far those details must spread.

Area 0 is the backbone used to connect other areas. A router connected to more than one area is an area border router (ABR). It shares reachability information between areas; it does not copy every internal link detail from one area into the other.

See a network split into areas
Areas contain the detailed topology map
Areas contain the detailed topology mapMulti-area illustration: ABR means area border router. It has interfaces in the backbone and another area. Detailed router/network LSAs stay in their own area; ABRs advertise inter-area reachability. The four-router course lab uses area 0 only. R5 in area 1 connects to ABR-A. ABR-A connects through R6 in area 0 to ABR-B. ABR-B connects to R7 in area 2. Each area has its own detailed topology records.Area 1Area 0 · backboneArea 2R5ABR-AR6ABR-BR7Area-1 topologyArea-0 topologyArea-2 topology
Multi-area illustration: ABR means area border router. It has interfaces in the backbone and another area. Detailed router/network LSAs stay in their own area; ABRs advertise inter-area reachability. The four-router course lab uses area 0 only.

Keep the distinction: same topology map, different starting router. Each router calculates its own next hops and costs. A cost describes the route; it does not measure actual download speed.

Try it: follow the information into a route

On R1 in the diagram's configured OSPF lab, use privileged EXEC mode, the # prompt. Check neighbours first, stored records next, then the installed path to the server:

show ip ospf neighbor show ip ospf database show ip route 192.168.4.10

R1 verification sequence. These inspect existing state; they do not create an OSPF configuration.

The neighbour output shows R1's direct OSPF peers. The database contains information received about the wider network. The route lookup should select R2 at 10.0.12.2 with cost 3 in the illustrated baseline. R4 can appear in the database without being R1's direct neighbour.

Test yourself on link-state basics

Predict · scenario 1

A router has no router-id command, a loopback 10.255.0.1 (up), and interfaces 192.168.1.1 and 10.0.12.1 (both up). What is its OSPF router ID?

Predict · scenario 2

What does a router normally do with a newer, valid area-scoped LSA received from an adjacent neighbour?

Predict · scenario 3

All routers in an area have identical LSDBs. Do they all have identical routing tables?

Predict · scenario 4

With the default reference bandwidth (100 Mbps), what is the OSPF cost of a 10 Mbps Ethernet interface?

Predict · scenario 5

R1's routing table shows O 192.168.4.0/24 [110/3] via 10.0.12.2. What is 3?

Further reading: Cisco: interpreting OSPF interface output and RFC 2328: OSPFv2.