Configuring OSPF on a Cisco Router
Understanding OSPF
OSPF (Open Shortest Path First) is a link-state routing protocol that uses the Dijkstra algorithm to calculate the shortest path to each destination network. Unlike distance-vector protocols like RIP, OSPF maintains a complete topology database of the network, allowing for faster convergence and loop-free routing.
Basic OSPF Configuration
To configure OSPF on a Cisco router, you need to enable the OSPF process and specify which networks will participate in OSPF routing. Here's the basic configuration process:
Step 1: Enable OSPF Process
First, enter global configuration mode and enable the OSPF routing process with a process ID:
Router(config)# router ospf 1The process ID is locally significant and can be any number from 1 to 65535. Different routers can use different process IDs and still form neighborships.
Step 2: Configure Network Statements
Next, specify which networks will participate in OSPF using the network command:
Router(config-router)# network 192.168.1.0 0.0.0.255 area 0
Router(config-router)# network 10.0.0.0 0.255.255.255 area 0The syntax is: network [network-address] [wildcard-mask] area [area-id]
The wildcard mask is the inverse of the subnet mask. For example, if your subnet mask is 255.255.255.0, the wildcard mask would be 0.0.0.255.
OSPF Areas
OSPF uses areas to create a hierarchical network design. Area 0 is the backbone area, and all other areas must connect to it either directly or through virtual links.
Single Area Configuration
For a single area design, all networks are typically placed in area 0:
Router(config)# router ospf 1
Router(config-router)# network 0.0.0.0 255.255.255.255 area 0This command advertises all connected networks in area 0.
OSPF Router ID
Each OSPF router must have a unique router ID (RID). The router ID is determined in the following order:
- Manually configured router ID
- Highest IP address on a loopback interface
- Highest IP address on an active physical interface
To manually configure a router ID:
Router(config)# router ospf 1
Router(config-router)# router-id 1.1.1.1Interface-Specific OSPF Configuration
You can also enable OSPF directly on interfaces instead of using network statements:
Router(config)# interface GigabitEthernet0/1
Router(config-if)# ip ospf 1 area 0This method provides more granular control over which interfaces participate in OSPF.
OSPF Hello and Dead Timers
OSPF routers send Hello packets to discover and maintain neighbor relationships. You can modify the Hello and Dead timer intervals:
Router(config-if)# ip ospf hello-interval 10
Router(config-if)# ip ospf dead-interval 40The Dead interval should be 4 times the Hello interval. Default values are 10 seconds for Hello and 40 seconds for Dead on broadcast networks.
OSPF Cost Modification
OSPF uses cost to determine the best path. The default cost calculation is: reference bandwidth / interface bandwidth. You can manually set the cost on an interface:
Router(config-if)# ip ospf cost 100Or modify the reference bandwidth globally:
Router(config-router)# auto-cost reference-bandwidth 10000Verification Commands
After configuring OSPF, use these commands to verify the configuration:
Router# show ip ospf
Router# show ip ospf interface
Router# show ip ospf neighbor
Router# show ip ospf database
Router# show ip route ospfThese commands will help you verify that OSPF is running correctly, neighbors are established, and routes are being learned.
Basic Troubleshooting
Common OSPF issues include:
- Area mismatches between neighbors
- Hello/Dead timer mismatches
- Authentication configuration errors
- Network type mismatches
Always verify neighbor relationships first using show ip ospf neighbor when troubleshooting OSPF connectivity issues.