Routing & OSPF MODULE 03
0 / 16 topics
How Routing Works
Routers forward packets between networks using a routing table

When a router receives a packet, it checks the destination IP against its routing table, finds the longest prefix match, and forwards the packet out the appropriate interface.

Longest Prefix Match: The most specific route (highest prefix length) always wins. /28 beats /24 beats /0.
Sample Routing Table (show ip route)
CodeNetworkAD/MetricNext Hop / Interface
C192.168.1.0/240/0directly connected, Gi0/0
L192.168.1.1/320/0local, Gi0/0
S10.0.0.0/81/0via 192.168.1.254
O172.16.0.0/16110/2via 10.1.1.2, Gi0/1
S*0.0.0.0/01/0via 209.165.200.2
C = Connected L = Local S = Static O = OSPF R = RIP S* = Default route
Administrative Distance
Router's preference when multiple protocols know the same route

Lower AD = more trustworthy. If a route is learned by two different protocols, the one with the lower AD is installed in the routing table.

SourceAD Value
Connected interface0
Static route1
EIGRP summary5
OSPF110
RIP120
Unknown / Unreachable255
Floating static route: Set AD higher than the dynamic protocol (e.g. AD 115 for a static backup to an OSPF route). It only activates if OSPF fails.
Static Routing
Manually configured routes — no routing protocol needed
When to use: Stub networks (one path only), small topologies, default routes to the internet, or as backup routes.
Static Route Syntax
R1(config)# ip route network mask {next-hop-IP | exit-interface} [AD] # Via next-hop IP (recommended) R1(config)# ip route 10.0.0.0 255.0.0.0 192.168.1.254 # Via exit interface (point-to-point only) R1(config)# ip route 10.0.0.0 255.0.0.0 GigabitEthernet0/1 # Default route (gateway of last resort) R1(config)# ip route 0.0.0.0 0.0.0.0 209.165.200.2 # Floating static (AD=115, backup to OSPF) R1(config)# ip route 10.0.0.0 255.0.0.0 192.168.1.254 115
OSPFv2 Concepts
Open Shortest Path First — link-state routing protocol

OSPF routers build a complete map of the network (LSDB) and use Dijkstra's SPF algorithm to calculate the shortest path. Metric = cost (reference BW ÷ interface BW).

OSPF Neighbor Adjacency States
1
Down
2
Init
3
2-Way
4
ExStart
5
Exchange
6
Loading
7
Full ✓
Hello interval10s (broadcast) / 30s (NBMA)
Dead interval4× Hello (40s / 120s)
Reference BW100 Mbps (default)
Cost = 100,000,000 ÷ BW (bps)
DR/BDR electionHighest priority, then highest Router ID
Router ID priorityManual → Loopback → Highest active IP
OSPFv2 Configuration
Single-area OSPF setup on a Cisco router
Basic OSPF Configuration
R1(config)# router ospf 1 R1(config-router)# router-id 1.1.1.1 # Advertise networks (wildcard mask) R1(config-router)# network 192.168.1.0 0.0.0.255 area 0 R1(config-router)# network 10.1.1.0 0.0.0.3 area 0 # Passive interface (don't send Hellos) R1(config-router)# passive-interface GigabitEthernet0/0 # Advertise default route into OSPF R1(config-router)# default-information originate # Adjust reference bandwidth (match network) R1(config-router)# auto-cost reference-bandwidth 1000
OSPF Verification Commands
# View OSPF neighbor table R1# show ip ospf neighbor Neighbor ID Pri State Dead Time Interface 2.2.2.2 1 Full/DR 00:00:34 Gi0/1 3.3.3.3 1 Full/BDR 00:00:38 Gi0/1 # View OSPF-learned routes R1# show ip route ospf # Check OSPF process details R1# show ip ospf R1# show ip ospf interface brief # View link-state database R1# show ip ospf database
Routing Table Lookup — Longest Prefix Match
How a router selects the best path for every packet

The router compares the destination IP against all entries and selects the most specific match (longest prefix). If no match exists the packet is dropped unless a default route (0.0.0.0/0) exists as the gateway of last resort.

Lookup order: Host route (/32) → Subnet route (/24) → Summary (/16) → Default (/0) → Drop
DestinationTable EntryResultReason
10.1.1.510.1.1.0/24Best match24-bit match — most specific
10.1.1.510.0.0.0/8Less specificUsed only if /24 absent
192.168.5.10.0.0.0/0Default routeGateway of last resort
172.16.0.1(none)DroppedNo match, no default
Reading a Routing Table
R1# show ip route Codes: C - connected, S - static, O - OSPF [AD/metric] via next-hop, age, interface O 10.1.2.0/24 [110/2] via 10.0.0.2, Gi0/1 S 0.0.0.0/0 [1/0] via 203.0.113.1 C 192.168.1.0/24 is directly connected, Gi0/0
Floating Static Routes
Backup routes that activate only when primary fails

A floating static route uses a higher AD than the primary so it stays hidden while the primary route exists. When the primary disappears the floating static automatically becomes active.

Primary (OSPF)AD 110 — active while OSPF neighbour is up
Floating staticAD 210 — hidden while OSPF route present
FailoverOSPF route drops → static becomes active immediately
Floating Static Config
! AD of 210 keeps this hidden behind OSPF (AD 110) R1(config)# ip route 10.2.0.0 255.255.0.0 10.0.0.2 210 R1# show ip route 10.2.0.0
Route Summarisation
Aggregating multiple subnets into one advertisement

Summarisation reduces routing table size and limits OSPF LSA flooding. Convert all networks to binary, find the common left-most bits — their count is the summary prefix length.

172.16.0.0/24...00010000.00000000
172.16.1.0/24...00010000.00000001
172.16.2.0/24...00010000.00000010
172.16.3.0/24...00010000.00000011
Summary172.16.0.0/22 — 22 common bits
OSPF Summary on ABR
R1(config)# router ospf 1 R1(config-router)# area 1 range 172.16.0.0 255.255.252.0
OSPF LSA Types, Area Types & DR/BDR Election
The mechanisms behind OSPF topology distribution

OSPF uses Link-State Advertisements to share topology info. All routers in an area maintain identical LSDBs and run Dijkstra's SPF independently to find the shortest path.

LSA Types
Type 1 — Router LSAEvery router; describes its own links within area
Type 2 — Network LSADR-generated; multi-access segment members
Type 3 — Summary LSAABR-generated; inter-area routes
Type 4 — ASBR SummaryPath to ASBR
Type 5 — AS ExternalRedistributed external routes from ASBR
OSPF Area Types
Backbone (Area 0)All areas must connect here
Standard areaAccepts all LSA types (1–5)
Stub areaBlocks Type 5; injects default route
Totally stubbyBlocks Type 3, 4, 5; only default (Cisco)
NSSAAllows external via Type 7 LSA
DR/BDR Election
PurposeReduces flooding on multi-access segments
ElectionHighest priority (default 1) wins; tie = highest RID
Router IDHighest loopback IP, else highest active interface
DR multicast224.0.0.6 (DR/BDR); 224.0.0.5 (all OSPF)
DROtherForms full adjacency only with DR and BDR
OSPF Cost, Default Route & Router ID
R1(config-if)# ip ospf cost 10 R1(config-router)# auto-cost reference-bandwidth 1000 R1(config-router)# default-information originate always R1(config-router)# router-id 1.1.1.1 R1# clear ip ospf process R1# show ip ospf neighbor R1# show ip ospf interface Gi0/0

Routing & OSPF Drills

Multiple choice questions on static routing, OSPF concepts, and verification.

0
Correct
0
Wrong
0
Streak 🔥
60s
QUESTION 1 · ROUTING

Packet Tracer Labs

Step-by-step routing configuration walkthroughs.

Routing Topology Diagrams

Routing Cheatsheet

Static Route Commands
# Standard static route R1(config)# ip route 192.168.2.0 255.255.255.0 10.0.0.2 # Default route (quad-zero) R1(config)# ip route 0.0.0.0 0.0.0.0 209.165.200.2 # Floating static (backup, higher AD) R1(config)# ip route 192.168.2.0 255.255.255.0 10.0.0.2 115 # Verify routing table R1# show ip route R1# show ip route static R1# ping 192.168.2.1 R1# traceroute 192.168.2.1
OSPF Configuration
# Enable OSPF process R1(config)# router ospf 1 R1(config-router)# router-id 1.1.1.1 # Advertise networks R1(config-router)# network 192.168.1.0 0.0.0.255 area 0 R1(config-router)# network 10.1.1.0 0.0.0.3 area 0 # Suppress Hellos on LAN-facing ports R1(config-router)# passive-interface Gi0/0 # Set interface cost manually R1(config-if)# ip ospf cost 10 # Set OSPF priority (DR election) R1(config-if)# ip ospf priority 100
OSPF Verification
# Neighbor table (must reach Full) R1# show ip ospf neighbor # OSPF-learned routes only R1# show ip route ospf # Process info (Router ID, Area, SPF) R1# show ip ospf # Per-interface OSPF info R1# show ip ospf interface brief R1# show ip ospf interface Gi0/1 # Full link-state database R1# show ip ospf database # Clear OSPF process (use carefully!) R1# clear ip ospf process
Key Concepts Quick Reference
OSPF AD110
Static AD1
OSPF metricCost (ref BW ÷ link BW)
Hello / Dead10s / 40s (broadcast)
Multicast Hello224.0.0.5 (all OSPF)
Multicast LSU224.0.0.6 (DR/BDR)
DR electionHighest priority → Router ID
Default priority1 (0 = never DR)
Backbone areaArea 0
SPF algorithmDijkstra's

Interactive Calculators

Tools to speed up exam calculations.

OSPF Cost Calculator
Cost = Reference BW ÷ Interface BW (min cost = 1)
1
OSPF Cost
Common interface costs (ref=100 Mbps)
Ethernet (10M)10
FastEthernet (100M)1
GigabitEthernet (1G)1 ⚠ same as FE!
With ref=1000M: GE1 · FE = 10 · 10M = 100
Fix: set auto-cost reference-bandwidth 1000 so GE costs 1 and FE costs 10.
AD / Route Type Reference
Administrative Distance cheat sheet
Route SourceAD
Connected0
Static route1
EIGRP summary5
External BGP20
EIGRP internal90
OSPF110
IS-IS115
RIP120
Unreachable255

Topic Checklist

Track your progress through routing concepts.

0%
Complete