Configuring OSPF on Cisco Routers
Open Shortest Path First (OSPF) is a link-state routing protocol that builds a complete network topology map and calculates optimal paths using the Dijkstra algorithm. Unlike distance-vector protocols, OSPF provides faster convergence and better scalability for enterprise networks. This guide covers essential configuration steps, verification techniques, and best practices for implementing OSPF on Cisco routers.
Key OSPF Concepts
Process ID: A locally significant identifier (1–65535) for an OSPF instance on a router. This number does not need to match between neighboring routers.
Area: A logical subdivision of the OSPF domain. All routers must belong to at least one area, with Area 0 serving as the mandatory backbone area.
Router ID (RID): A unique 32-bit identifier (formatted like an IP address) that distinguishes each router in the OSPF domain.
Wildcard Mask: The inverse of a subnet mask, used in the network command to specify which interfaces participate in OSPF.
Neighbor Adjacency: The relationship formed between OSPF routers to exchange Link-State Advertisements (LSAs) and routing information.
Configuration Steps
Enable OSPF Process
Activate OSPF on your router by entering global configuration mode and specifying a process ID:
Router(config)# router ospf 1
Note: The process ID is locally significant only. Different routers can use different process IDs and still form adjacencies.
Advertise Networks
Specify which networks OSPF should advertise and assign them to an area:
Router(config-router)# network <network-address> <wildcard-mask> area <area-id>
Example:
Router(config-router)# network 192.168.10.0 0.0.0.3 area 0
Router(config-router)# network 172.16.16.0 0.0.0.255 area 0
Critical Requirements:
- Use the network address, not the interface IP address
- Correct:
192.168.10.0 0.0.0.3for interface192.168.10.1/30 - Incorrect:
192.168.10.1 0.0.0.3 - OSPF activates on all interfaces matching the specified network range
Understanding Wildcard Masks
Wildcard masks are the inverse of subnet masks. Use this reference table for common conversions:
| Subnet Mask | CIDR | Wildcard Mask |
|---|---|---|
| 255.255.255.0 | /24 | 0.0.0.255 |
| 255.255.255.252 | /30 | 0.0.0.3 |
| 255.255.255.248 | /29 | 0.0.0.7 |
| 255.255.255.240 | /28 | 0.0.0.15 |
Tip: To calculate a wildcard mask, subtract each octet of the subnet mask from 255.
Configure Router ID
The Router ID is selected automatically in this priority order:
- Manually configured RID using the
router-idcommand - Highest IP address on any active loopback interface
- Highest IP address on any active physical interface
Manual configuration (recommended):
Router(config-router)# router-id 1.1.1.1
Verify the Router ID:
Router# show ip protocols
Verification Commands
Check OSPF Neighbors
Verify that adjacencies have formed successfully:
Router# show ip ospf neighbor
Expected output:
Neighbor ID Pri State Dead Time Address Interface
192.168.10.2 1 FULL/DR 00:00:39 192.168.10.2 GigabitEthernet0/0
Adjacency states:
- FULL: Adjacency is fully established (normal state)
- 2WAY: Routers have exchanged hello packets (normal on broadcast networks)
- INIT/EXSTART/EXCHANGE/LOADING: Transitional states during adjacency formation
Verify OSPF Routes
Check the routing table for OSPF-learned routes (marked with O):
Router# show ip route
Example output:
O 10.8.0.0/24 [110/20] via 192.168.10.2, 00:05:23, GigabitEthernet0/0
Route notation:
O: OSPF-learned route110: Administrative distance (default for OSPF)20: OSPF cost (metric based on bandwidth)
Additional Verification Commands
Router# show ip ospf interface
Router# show ip ospf database
Router# show ip protocols
Practical Configuration Example
Scenario: Two-Router OSPF Network
Network topology:
R1 (192.168.10.1/30) ---- (192.168.10.2/30) R2
| |
172.16.16.0/24 10.8.0.0/24
R1 Configuration:
R1(config)# router ospf 1
R1(config-router)# router-id 1.1.1.1
R1(config-router)# network 192.168.10.0 0.0.0.3 area 0
R1(config-router)# network 172.16.16.0 0.0.0.255 area 0
R2 Configuration:
R2(config)# router ospf 1
R2(config-router)# router-id 2.2.2.2
R2(config-router)# network 192.168.10.0 0.0.0.3 area 0
R2(config-router)# network 10.8.0.0 0.0.0.255 area 0
Expected results:
- R1 learns route to
10.8.0.0/24via R2 - R2 learns route to
172.16.16.0/24via R1 show ip ospf neighbordisplays FULL adjacency state- Both routers have complete routing information
Common Configuration Mistakes
Using interface IP instead of network address:
- Incorrect:
network 192.168.10.1 0.0.0.3 area 0 - Correct:
network 192.168.10.0 0.0.0.3 area 0
Forgetting to specify the area:
- The
areaparameter is mandatory in thenetworkcommand
Advertising non-connected networks:
- Only advertise networks directly connected to the router's interfaces
Wildcard mask errors:
- Double-check wildcard mask calculations to avoid unintended interface activation
Area mismatches:
- Neighboring routers must share the same area on their connecting interfaces
Troubleshooting Adjacency Issues
If OSPF neighbors fail to form adjacencies, verify:
- Area configuration: Both routers must use the same area ID on the shared link
- Subnet configuration: Interface IP addresses must be in the same subnet
- Hello/Dead timers: Must match between neighbors (default: 10s/40s)
- Network types: Must be compatible (broadcast, point-to-point, etc.)
- Authentication: If configured, must match on both sides
- MTU size: Must match on both interfaces
- OSPF enabled: Verify with
show ip ospf interface
Best Practices
Manually configure Router IDs:
- Provides stability and predictability
- Use loopback interfaces or explicit
router-idcommands
Use Area 0 as the backbone:
- All multi-area OSPF designs require Area 0
- Other areas must connect to Area 0 (directly or via virtual links)
Document your wildcard masks:
- Keep a reference table for your network's common subnet sizes
**