Basic OSPF Configuration on Cisco Routers
Detailed guide to configuring OSPF on Cisco IOS routers, covering single-area setup, interface modes, router IDs, network statements, and verification commands for network engineers.
Open Shortest Path First (OSPF) is a widely used link-state routing protocol, standardized as RFC 2328 for IPv4, that calculates the shortest path to a destination based on cumulative costs. It offers fast convergence, hierarchical design capabilities, and efficient routing table management, making it a cornerstone for many enterprise and service provider networks.
This article provides a foundational guide to configuring OSPF on Cisco IOS routers, focusing on a single-area implementation. We will cover essential commands, verification steps, and common considerations for establishing OSPF adjacency and exchanging routing information.
OSPF Fundamentals and Components
Before diving into configuration, understanding key OSPF concepts is crucial:
- Router ID (RID): A 32-bit value uniquely identifying an OSPF router within an Autonomous System (AS). It's typically chosen as the highest loopback IP address or highest active physical interface IP address at boot time if not explicitly configured.
- Areas: OSPF allows for hierarchical network design by dividing an AS into areas. Area 0 (the backbone area) is central, and all other areas must connect to it. This design reduces routing table size and limits the impact of link-state changes.
- Neighbors and Adjacencies: OSPF routers on a common segment discover each other via Hello packets. They form a neighbor relationship and then exchange Link-State Advertisements (LSAs) to build a synchronized Link-State Database (LSDB).
- Link-State Advertisements (LSAs): Packets containing information about a router's directly connected links and their states (e.g., interface IP address, subnet mask, cost, neighbor status).
- Cost: An arbitrary value assigned to an interface, inversely proportional to its bandwidth. OSPF prefers paths with lower cumulative costs. Default cost calculation for Cisco IOS is
10^8 / bandwidth (bps). For example, FastEthernet (100 Mbps) has a cost of 1, GigabitEthernet (1 Gbps) has a cost of 1.
Basic Single-Area OSPF Configuration
Let's consider a simple scenario with two Cisco IOS routers, R1 and R2, connected via a point-to-point link (e.g., FastEthernet 0/0) and each having a local LAN segment. We will configure them for OSPF Area 0.
Interface IP Addressing
First, ensure all interfaces participating in OSPF have IP addresses configured and are in an 'up/up' state.
R1(config)# interface FastEthernet0/0
R1(config-if)# ip address 10.0.0.1 255.255.255.0
R1(config-if)# no shutdown
R1(config-if)# exit
R1(config)# interface FastEthernet0/1
R1(config-if)# ip address 192.168.1.1 255.255.255.0
R1(config-if)# no shutdown
R1(config-if)# exit
R2(config)# interface FastEthernet0/0
R2(config-if)# ip address 10.0.0.2 255.255.255.0
R2(config-if)# no shutdown
R2(config-if)# exit
R2(config)# interface FastEthernet0/1
R2(config-if)# ip address 192.168.2.1 255.255.255.0
R2(config-if)# no shutdown
R2(config-if)# exit
Enabling OSPF Process and Router ID
The router ospf <process-id> command starts the OSPF routing process. The process ID is a locally significant value (1 to 65535) and doesn't need to match across routers.
Explicitly configuring the router-id is best practice, as it provides a stable identifier even if interface IP addresses change or go down. If not set, IOS selects the highest IP of a loopback interface, then the highest IP of an active physical interface.
R1(config)# router ospf 1
R1(config-router)# router-id 1.1.1.1
R2(config)# router ospf 1
R2(config-router)# router-id 2.2.2.2
Defining OSPF Network Statements
The network <network-address> <wildcard-mask> area <area-id> command tells OSPF which interfaces to enable for the protocol and which networks to advertise. The wildcard mask is the inverse of the subnet mask.
- A
networkstatement with0.0.0.0as the wildcard mask (e.g.,network 192.168.1.1 0.0.0.0 area 0) enables OSPF on the interface with that exact IP address. - Using a broader wildcard mask (e.g.,
network 10.0.0.0 0.0.0.255 area 0) enables OSPF on all interfaces within that subnet range.
R1(config-router)# network 10.0.0.0 0.0.0.255 area 0
R1(config-router)# network 192.168.1.0 0.0.0.255 area 0
R2(config-router)# network 10.0.0.0 0.0.0.255 area 0
R2(config-router)# network 192.168.2.0 0.0.0.255 area 0
Upon entering these commands, if the interfaces are up and configured correctly, OSPF Hello packets will be exchanged, and adjacency should form. You'll often see console messages indicating state changes (e.g., "adjacency change from LOADING to FULL").
Interface-Specific OSPF Configuration (Preferred)
While network commands are functional, configuring OSPF directly on interfaces using ip ospf <process-id> area <area-id> is generally preferred for clarity and precision. This approach makes it explicit which interfaces are participating and avoids accidental inclusion of interfaces.
R1(config)# interface FastEthernet0/0
R1(config-if)# ip ospf 1 area 0
R1(config-if)# exit
R1(config)# interface FastEthernet0/1
R1(config-if)# ip ospf 1 area 0
R1(config-if)# exit
R2(config)# interface FastEthernet0/0
R2(config-if)# ip ospf 1 area 0
R2(config-if)# exit
R2(config)# interface FastEthernet0/1
R2(config-if)# ip ospf 1 area 0
R2(config-if)# exit
This method accomplishes the same goal as the network statements but is often considered cleaner. Note that the OSPF process still needs to be enabled with router ospf <process-id> and a router-id assigned.
Verifying OSPF Operations
After configuration, several show commands are essential to verify OSPF's proper functioning:
show ip ospf neighbor
This command displays information about OSPF neighbors. Look for the 'FULL' state, indicating a successful adjacency. If it's stuck in 'INIT', 'EXSTART', or 'EXCHANGE', there's a problem.
R1# show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
2.2.2.2 1 FULL/DR 00:00:33 10.0.0.2 FastEthernet0/0
Key fields:
- Neighbor ID: The Router ID of the neighboring router.
- Pri: Priority, used in DR/BDR election (default 1).
- State: Adjacency state (FULL is desired). DR/BDR indicates the role on a multi-access segment.
- Dead Time: Time remaining before the neighbor is declared down.
- Address: IP address of the neighbor's interface on the shared segment.
- Interface: Local interface connected to the neighbor.
show ip ospf interface <type> <number>
Provides detailed OSPF information for a specific interface.
R1# show ip ospf interface FastEthernet0/0
FastEthernet0/0 is up, line protocol is up
Internet Address 10.0.0.1/24, Area 0, Process ID 1, Router ID 1.1.1.1
Network Type BROADCAST, Cost: 1
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 1.1.1.1, Interface address 10.0.0.1
Backup Designated Router (ID) 2.2.2.2, Interface address 10.0.0.2
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
Hello due in 00:00:03
OSPF hello due in 00:00:03
Neighbor Count is 1, Adjacent neighbor count is 1
Adjacent with neighbor 2.2.2.2 (Backup Designated Router)
show ip ospf
Displays a summary of all OSPF processes on the router.
show ip protocols
Provides a concise overview of all active routing protocols, including OSPF process ID, router ID, and interfaces participating.
show ip route ospf
Filters the routing table to show only routes learned via OSPF. Look for the "O" flag.
R1# show ip route ospf
192.168.2.0/24 is subnetted, 1 subnets
O 192.168.2.0 [110/2] via 10.0.0.2, 00:00:15, FastEthernet0/0
The [110/2] indicates an administrative distance of 110 (default for OSPF) and a metric (cost) of 2 to reach the 192.168.2.0/24 network.
Common Pitfalls and Troubleshooting
- Mismatching OSPF Area IDs: All interfaces on a segment forming an adjacency must belong to the same OSPF area.
- Incorrect Wildcard Masks: Ensure the
networkcommand's wildcard mask correctly encompasses the intended interfaces. The interface-specific command (ip ospf <process-id> area <area-id>) avoids this. - Interface Down/Down: OSPF cannot form adjacencies or advertise routes over interfaces that are administratively down or have no link. Use
show ip interface brief. - Mismatching Hello/Dead Timers: On broadcast and point-to-point networks, OSPF Hello and Dead interval timers must match between neighbors to form an adjacency. Defaults are 10 seconds (Hello) and 40 seconds (Dead). If they differ, adjacencies won't form.
- IP Address Mismatch/Subnetting Errors: Ensure IP addresses and subnet masks are correctly configured on interfaces, allowing routers to communicate on the shared segment.
- Missing
router-id: While OSPF will choose one, an unstable router ID (e.g., if a physical interface goes down) can cause issues. Always configure it explicitly. - Access List Blocking OSPF: If ACLs are applied to interfaces, ensure they permit OSPF protocol traffic (protocol 89).
- Passive Interfaces: If an interface is configured as passive (
passive-interface <interface-type> <number>underrouter ospfconfiguration), it will advertise its subnet but will not send or receive OSPF Hellos, preventing adjacency formation. This is useful for LAN segments where no other OSPF router exists.