Configuring OSPF on Cisco Routers
Open Shortest Path First (OSPF) is a robust link-state routing protocol designed for enterprise and service provider networks. Unlike distance-vector protocols, OSPF builds a complete topology map of the network and calculates the shortest path to each destination using the Dijkstra algorithm. This guide explains how to configure OSPF on Cisco routers, covering essential commands, concepts, and verification techniques.
Key Concepts
Core OSPF Terminology
- OSPF (Open Shortest Path First): A link-state routing protocol that dynamically exchanges topology information to compute optimal routes.
- Process ID: A locally significant number (1–65535) identifying an OSPF instance on a router. Does not need to match between neighbors.
- Area: A logical subdivision of an OSPF domain. All routers must belong to at least one area (typically Area 0 for the backbone).
- Router ID (RID): A 32-bit identifier (e.g.,
192.168.1.1) that uniquely identifies a router in the OSPF domain. - Neighbor Adjacency: A relationship formed between OSPF routers to exchange Link-State Advertisements (LSAs).
- Wildcard Mask: An inverse subnet mask used in the
networkcommand (e.g.,0.0.0.3for a/30subnet).
Step-by-Step Configuration
1. Enabling OSPF
Activate OSPF on a Cisco router using the router ospf command:
Router(config)# router ospf <process-id>
Example:
Router(config)# router ospf 1
Note:
- The process ID is locally significant and does not need to match between neighbors.
- Multiple OSPF processes can run on the same router (advanced use cases).
2. Advertising Networks with the network Command
Specify which networks to 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
Critical Rules:
- Declare the network address, not the interface IP.
- ✅ Correct:
192.168.10.0 0.0.0.3(for192.168.10.1/30) - ❌ Incorrect:
192.168.10.1 0.0.0.3
- ✅ Correct:
- The router activates OSPF on interfaces matching the declared network.
3. Wildcard Mask vs. Subnet Mask
Wildcard masks are the inverse of subnet masks. Use this table for quick reference:
| Subnet Mask | Wildcard Mask |
|---|---|
| 255.255.255.0 | 0.0.0.255 |
| 255.255.255.252 | 0.0.0.3 |
| 255.255.255.248 | 0.0.0.7 |
Tip: Modern Cisco IOS versions accept subnet masks, but wildcard masks remain the standard.
4. Router ID Selection
The Router ID (RID) is chosen in this priority order:
- Manually configured RID (
router-idcommand). - Highest IP address on a loopback interface.
- Highest IP address on an active physical interface.
Verification:
show ip protocols
Verification Commands
1. Check OSPF Neighbors
Verify adjacency status with:
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
Troubleshooting:
- If no neighbors appear, check:
- Area mismatches
- Subnet mismatches
- Hello/dead timer mismatches
- OSPF not enabled on the interface
2. Verify OSPF Routes
Check the routing table for OSPF-learned routes (marked with O):
show ip route
Example Output:
O 10.8.0.0/24 [110/20] via 192.168.10.2
O: OSPF route110: Administrative distance (default for OSPF)20: OSPF cost (metric)
Common Mistakes and Best Practices
Mistakes to Avoid
- Using the interface IP instead of the network address in the
networkcommand. - Forgetting to specify the area in the
networkcommand. - Declaring networks not directly connected to the router.
- Ignoring wildcard mask calculations.
Best Practices
- Use Area 0 for the backbone in multi-area designs.
- Manually configure the Router ID for stability:
Router(config-router)# router-id 1.1.1.1 - Verify configurations with
show ip ospf interfaceandshow ip protocols.
Practical Example
Scenario: Two Routers in Area 0
Topology:
R1 (192.168.10.1/30) ---- (192.168.10.2/30) R2
| |
172.16.16.0/24 10.8.0.0/24
Configuration:
! On R1
router ospf 1
network 192.168.10.0 0.0.0.3 area 0
network 172.16.16.0 0.0.0.255 area 0
! On R2
router ospf 1
network 192.168.10.0 0.0.0.3 area 0
network 10.8.0.0 0.0.0.255 area 0
Expected Results:
- R1 learns
10.8.0.0/24via R2. - R2 learns
172.16.16.0/24via R1. show ip ospf neighborshows FULL adjacency.
Key Takeaways
- OSPF is enabled with
router ospf <process-id>. - The process ID is locally significant and does not need to match between neighbors.
- The
networkcommand activates OSPF on matching interfaces using network addresses and wildcard masks. - The Router ID is critical for OSPF operation and can be manually configured.
- Use
show ip ospf neighborto verify adjacency andshow ip routeto check OSPF routes (marked withO).
Learn More
- RFC 2328: OSPFv2 Specification (IETF)
- Cisco Documentation: OSPF Configuration Guide
- Juniper Networks: OSPF in Junos OS