OSPF (Open Shortest Path First)
OSPF Basics & Operations
- Concept: OSPF is a Link-State dynamic routing protocol. Unlike distance-vector protocols (RIP, EIGRP) that use “routing by rumor”, OSPF routers create a complete connectivity map of the network.
- Details:
- Uses Dijkstra’s Shortest Path First (SPF) algorithm to calculate the best route.
- Routers share LSAs (Link State Advertisements) to build an identical LSDB (Link State Database) across the area.
- Flooding: The process of sending LSAs to all OSPF neighbors.
- Versions:
- OSPFv2: Used for IPv4 (CCNA focus).
- OSPFv3: Used for IPv6 (can also be used for IPv4).
- Administrative Distance (AD): Default is 110.
- IP Protocol Number: 89.
- Multicast Addresses: 224.0.0.5 (All OSPF Routers), 224.0.0.6 (DR/BDR only).
OSPF Areas
- Concept: Areas divide a large network into smaller sections to reduce SPF calculation time, memory usage, and LSA flooding overhead.
- Details:
- Area 0 (Backbone Area): The core area. All other areas must connect directly to Area 0.
- Single-Area OSPF: All routers in Area 0. Acceptable for small networks.
- Router Types:
- Internal Router: All interfaces in the same area.
- Backbone Router: At least one interface in Area 0.
- ABR (Area Border Router): Interfaces in multiple areas (e.g., Area 0 and Area 1). Maintains a separate LSDB for each area. (Recommend max 2 areas per ABR).
- ASBR (Autonomous System Boundary Router): Connects the OSPF domain to an external network (e.g., Internet, EIGRP).
- Route Types:
- Intra-area Route: Destination is in the same OSPF area.
- Interarea Route: Destination is in a different OSPF area.
- Area Rules:
- Areas must be contiguous (not split).
- All non-backbone areas must have an ABR connected to Area 0.
- Interfaces in the same subnet must be in the same OSPF area.
Basic OSPF Configuration
! Enable OSPF process (Process ID is locally significant, does NOT need to match)
Router(config)# router ospf 1
! Activate OSPF on interfaces matching the network/wildcard in a specific area
Router(config-router)# network 10.0.12.0 0.0.0.255 area 0
! Alternative: Enable OSPF directly on the interface (No network command needed)
Router(config-if)# ip ospf 1 area 0
! Configure Passive Interface (Stops Hello packets, still advertises the subnet)
Router(config-router)# passive-interface GigabitEthernet0/0
! OR make all passive by default, then enable specific ones
Router(config-router)# passive-interface default
Router(config-router)# no passive-interface GigabitEthernet0/0
! Advertise a default route into OSPF (Makes router an ASBR)
Router(config)# ip route 0.0.0.0 0.0.0.0 203.0.113.2
Router(config-router)# default-information originate
! Manually configure Router ID (Requires process reset to take effect)
Router(config-router)# router-id 1.1.1.1
Router# clear ip ospf process
! Change OSPF Administrative Distance
Router(config-router)# distance 85
Things to note:
- The
networkcommand only determines which interfaces to activate OSPF on; it does not dictate what networks are advertised. - OSPF Process ID is locally significant (R1 can use PID 1, R2 can use PID 2).
- Router ID (RID) Priority: 1. Manually configured
router-id-> 2. Highest Loopback IP -> 3. Highest Physical IP.
OSPF Metric (Cost)
- Concept: OSPF uses Cost as its metric, calculated based on interface bandwidth.
- Formula:
Cost = Reference Bandwidth / Interface Bandwidth - Details:
- Default Reference Bandwidth is 100 Mbps.
- Any calculated cost less than 1 is rounded up to 1 (FastEthernet, GigabitEthernet, 10GigE all have a default cost of 1).
- Loopback interfaces have a default cost of 1.
- Route cost is the sum of the outgoing interface costs along the path.
! Change Reference Bandwidth (Value in Mbps, must match on ALL routers)
Router(config-router)# auto-cost reference-bandwidth 100000
! Manually set interface cost (Overrides auto-calculation)
Router(config-if)# ip ospf cost 50
! Change interface bandwidth (Value in kbps, NOT recommended for OSPF cost tuning)
Router(config-if)# bandwidth 100000
Things to note: Always use auto-cost reference-bandwidth and ip ospf cost to tune metrics. Changing the bandwidth command affects EIGRP and QoS calculations as well.
OSPF Neighbor Adjacency Process
- Concept: Routers must form adjacencies to exchange LSDBs. Uses Hello packets sent to multicast 224.0.0.5 (All OSPF Routers). Encapsulated in IP Protocol 89.
- Timers (Broadcast & Point-to-Point):
- Hello: 10 seconds
- Dead: 40 seconds (4x Hello)
- Neighbor States:
- Down: No Hello received.
- Init: Hello received, but own RID not in the Hello packet.
- 2-Way: Hello received with own RID. (DR/BDR election happens here on Broadcast). DROthers stay in 2-Way with each other.
- Exstart: Master/Slave election based on highest RID. Exchange of empty DBD (Database Description) packets.
- Exchange: Routers exchange DBDs containing LSA headers (summaries of LSDB).
- Loading: Routers send LSR (Link State Request) for missing LSAs. Neighbor replies with LSU (Link State Update) containing the full LSAs.
- Full: Adjacency established, LSDBs are synchronized.
| Packet Type | Name | Purpose |
|---|---|---|
| 1 | Hello | Discover/maintain neighbors. Multicast 224.0.0.5. |
| 2 | DBD (Database Description) | Summarize LSDB contents. Master/Slave negotiation. |
| 3 | LSR (Link State Request) | Request specific missing LSAs. |
| 4 | LSU (Link State Update) | Send requested full LSAs. |
| 5 | LSAck (Link State Acknowledgment) | Acknowledge receipt of LSUs. |
OSPF Network Types
| Feature | Broadcast (Ethernet) | Point-to-Point (Serial PPP/HDLC) | Non-Broadcast (Frame Relay) |
|---|---|---|---|
| DR/BDR Elected? | Yes | No | Yes |
| Neighbor Discovery | Dynamic (Multicast) | Dynamic (Multicast) | Static (Manual) |
| Default Timers (Hello/Dead) | 10 / 40 | 10 / 40 | 30 / 120 |
| Multicast Addresses | 224.0.0.5 (All), 224.0.0.6 (DR/BDR) | 224.0.0.5 | 224.0.0.5 |
| Adjacencies | FULL with DR/BDR; 2-Way with DROther | FULL with the single neighbor | FULL with DR/BDR; 2-Way with DROther |
- DR/BDR Election Rules:
- Highest Interface Priority (Default 1, Range 0-255). Priority 0 = Never DR/BDR.
- Tie-breaker: Highest Router ID.
- Election is Non-Preemptive (A new router with higher priority won’t take over unless DR/BDR fails or OSPF is reset).
- Changing Network Type:
Router(config-if)# ip ospf network point-to-point
- Serial Interfaces (Point-to-Point):
- Default encapsulation: HDLC. Can change to PPP (
encapsulation ppp). - DCE side provides clocking:
clock rate 64000(in bps). - Identify DCE/DTE:
show controllers serial 0/0
- Default encapsulation: HDLC. Can change to PPP (
OSPF Neighbor Requirements
For two routers to become OSPF neighbors, the following must match/be configured:
- Area ID: Must match.
- Subnet: Interfaces must be in the same IP subnet.
- OSPF Process: Must not be administratively
shutdown. - Router ID: Must be unique across the OSPF domain.
- Hello & Dead Timers: Must match exactly.
- Authentication: Passwords and auth types must match.
- MTU: Must match. (Mismatch causes routers to get stuck in Exstart state).
- Network Type: Must match. (Mismatch causes routers to reach Full state but not exchange routes).
! Configure Hello/Dead Timers
Router(config-if)# ip ospf hello-interval 5
Router(config-if)# ip ospf dead-interval 20
! Configure Authentication
Router(config-if)# ip ospf authentication-key jeremy
Router(config-if)# ip ospf authentication
! Configure IP MTU
Router(config-if)# ip mtu 1400
LSA (Link State Advertisement) Types
- Concept: LSAs are the building blocks of the LSDB. All routers in an area have identical LSDBs.
- Key Types for CCNA:
- Type 1 (Router LSA): Generated by every OSPF router. Identifies the router (RID) and lists its directly connected OSPF links. Stays within the originating area.
- Type 2 (Network LSA): Generated by the DR on multi-access networks (Broadcast). Lists all routers connected to the multi-access network. Stays within the area.
- Type 5 (AS-External LSA): Generated by the ASBR. Advertises routes external to the OSPF domain (e.g., default route, redistributed routes). Flooded to all areas (except stub areas).
! View the LSDB
Router# show ip ospf database
Loopback Interfaces
- Concept: Virtual interfaces that are always Up/Up (unless manually shut down).
- Usage:
- Provides a stable IP address for router management (Telnet/SSH).
- Used to determine the Router ID (Highest Loopback IP is preferred over physical IPs).
- Ensures the RID doesn’t change if a physical interface fails.
Command Summary
Basic Configuration & Verification
Router(config)# router ospf 1
Router(config-router)# network 10.0.0.0 0.0.255.255 area 0
Router(config-router)# passive-interface default
Router(config-router)# no passive-interface Gi0/0
Router(config-router)# default-information originate
Router(config-router)# router-id 1.1.1.1
Router(config-router)# auto-cost reference-bandwidth 100000
Router(config-router)# distance 90
Router(config-router)# shutdown / no shutdown
Router# clear ip ospf process
Router# show ip protocols
Router# show ip ospf neighbor
Router# show ip ospf interface [brief]
Router# show ip ospf database
Router# show ip route ospf
Interface Specific Configuration
Router(config-if)# ip ospf 1 area 0
Router(config-if)# ip ospf cost 50
Router(config-if)# bandwidth 100000
Router(config-if)# ip ospf hello-interval 10
Router(config-if)# ip ospf dead-interval 40
Router(config-if)# ip ospf priority 255
Router(config-if)# ip ospf network point-to-point
Router(config-if)# ip ospf authentication-key PASSWORD
Router(config-if)# ip ospf authentication
Router(config-if)# ip mtu 1500
Router(config-if)# encapsulation ppp
Router(config-if)# clock rate 64000
Router# show controllers serial 0/0