This Post outlines the configuration of Open Shortest Path First (OSPF) in its simplest form between two routers, covering Cisco IOS, IOS XE, and IOS XR platforms. It includes configuration methods, requirements for neighbor establishment, passive interface concepts, maximum paths, administrative distance, and default route advertisement.
Configuring OSPF Between Two Routers
OSPF can be configured on Cisco IOS/IOS XE and IOS XR platforms using different approaches. Below are examples of the simplest OSPF configurations to establish adjacency between two routers connected via a common subnet.
Cisco IOS/IOS XE Configuration
OSPF can be enabled either under the OSPF process (classic method) or on a per-interface basis.
Classic Method (Under OSPF Process)
vIOS1(config)# router ospf 1
vIOS1(config-router)# network 10.0.0.0 0.0.0.255 area 0
The network command activates OSPF on interfaces whose IP addresses fall within the specified range (10.0.0.0/24) and assigns them to Area 0.
The wildcard mask (0.0.0.255) determines the range of addresses matched.
Per-Interface Method
vIOS2(config)# interface GigabitEthernet0/0
vIOS2(config-if)# ip ospf 1 area 0
OSPF is enabled directly on the interface, associating it with OSPF process ID 1 and Area 0.
This method offers granular control and avoids the need for wildcard masks.
Note: The process ID (e.g., 1 or 100) is locally significant and does not need to match between routers. However, the area ID must match for adjacency to form.
Cisco IOS XR Configuration
IOS XR uses a hierarchical configuration structure, with OSPF settings organized under the OSPF process and area.
XR(config)# router ospf 1
XR(config-ospf)# address-family ipv4 unicast
XR(config-ospf)# area 0
XR(config-ospf-ar)# interface GigabitEthernet0/0/0/0
XR(config-ospf-ar-if)# hello-interval 10
XR(config-ospf-ar-if)# commit
The address-family ipv4 unicast specifies the protocol family.
Interfaces are configured under a specific area, enabling OSPF on the interface.
Interface-level parameters, such as hello-interval, are set within the interface context.
The commit command is required to apply changes in IOS XR.
Key Difference: IOS XR consolidates OSPF configuration under the OSPF process hierarchy, unlike IOS/IOS XE, which allows configuration at both global and interface levels.
Clarification on Network Command
The network command in IOS/IOS XE does not advertise subnets directly. Instead, it activates OSPF on interfaces whose IP addresses match the specified range.
Subnets are advertised via OSPF Link-State Advertisements (LSAs) generated for the interfaces on which OSPF is enabled.
Router ID
The OSPF Router ID uniquely identifies a router in the OSPF domain.
It can be manually configured:
R1(config)# router ospf 1
R1(config-router)# router-id 1.1.1.1
If not hardcoded, the Router ID is automatically selected based on:
The highest IP address of a loopback interface.
If no loopback exists, the highest IP address of a physical interface.
The Router ID must be unique for each OSPF router.
Requirements for OSPF Neighbor Adjacency
For two routers to form an OSPF neighbor relationship and exchange routes, the following parameters must match on the shared interface:
Subnet and Mask: Both routers must be on the same subnet with identical subnet masks.
Area ID: The OSPF area assigned to the interface must match.
Hello and Dead Timers: The hello interval (default: 10 seconds) and dead interval (default: 40 seconds) must match.
Network Type: The OSPF network type (e.g., broadcast, point-to-point) must be compatible.
Authentication: If enabled, authentication type and credentials (e.g., MD5 key) must match.
Stub Flags: If the area is configured as a stub or NSSA, both routers must agree on the stub flag.
MTU: The Maximum Transmission Unit must match to ensure successful Database Description (DBD) packet exchange.
Process After OSPF Activation:
The router sends Hello packets out of the OSPF-enabled interface.
Upon receiving a Hello packet, the router verifies the above parameters. If they match, a neighbor relationship forms.
The routers synchronize their Link-State Databases (LSDBs) by exchanging LSAs.
The Shortest Path First (SPF) algorithm runs to compute the best paths, which are installed in the routing table.
The neighbor relationship is maintained by sending Hello packets at the hello interval (default: 10 seconds).
LSAs are reflooded every 30 minutes (LSA refresh interval) to ensure LSDB consistency.
Passive Interface Configuration
A passive interface in OSPF advertises its connected subnet but does not form neighbor relationships, nor processing any received OSPF routing update conserving resources and enhancing security.
Use Case
Applied to interfaces connected to LAN subnets with no OSPF neighbors (e.g., end-user networks).
The subnet is still advertised via OSPF through other active interfaces.
Effects of Passive Interface
The router does not send Hello packets out of the passive interface, reducing CPU and bandwidth usage.
Incoming Hello packets on the passive interface are discarded, preventing unauthorized neighbor formation.
The interface’s subnet is included in OSPF advertisements via other OSPF-enabled interfaces.
Configuration
IOS/IOS XE
R1(config)# router ospf 1
R1(config-router)# passive-interface GigabitEthernet0/1
Makes a specific interface passive.
R1(config)# router ospf 1
R1(config-router)# passive-interface default
R1(config-router)# no passive-interface GigabitEthernet0/0
Makes all interfaces passive by default, with selective enabling of active interfaces.
IOS XR
XR(config)# router ospf 1
XR(config-ospf)# area 0
XR(config-ospf-ar)# interface GigabitEthernet0/0/0/1
XR(config-ospf-ar-if)# passive enable
XR(config-ospf-ar-if)# commit
Enables passive mode on a specific interface.
Maximum Paths
The maximum-paths feature controls how many equal-cost paths OSPF installs in the routing table for load balancing.
OSPF calculates the cost to a destination based on interface bandwidth (default formula: reference bandwidth / interface bandwidth).
If multiple paths to a prefix have the same cost, OSPF can load balance across them.
The maximum-paths command specifies the maximum number of equal-cost paths (default varies by platform, typically 4 or 8).
Configuration
IOS/IOS XE
R1(config)# router ospf 1
R1(config-router)# maximum-paths 4
Allows up to 4 equal-cost paths (range: 1–32, depending on platform and IOS version).
Setting to 1 disables load balancing, forcing OSPF to select a single path.
IOS XR
XR(config)# router ospf 1
XR(config-ospf)# maximum paths 4
XR(config-ospf)# commit
Configured directly under the OSPF process.
Administrative Distance (AD)
Administrative Distance is a locally significant value that determines the preference of one routing protocol over another. OSPF has a default AD of 110, which can be modified.
Configuration
IOS/IOS XE
Change AD for all OSPF routes:
R1(config)# router ospf 1
R1(config-router)# distance 100
Change AD based on route type:
R1(config)# router ospf 1
R1(config-router)# distance ospf intra-area 100 inter-area 110 external 120
Intra-area: Routes within the same area (O routes).
Inter-area: Routes from another area (O IA routes).
External: Routes redistributed into OSPF (O E1, O E2, O N1, O N2).
Change AD for specific routes based on Router ID (RID) and/or ACL:
R1(config)# access-list 10 permit 192.168.1.0 0.0.0.255
R1(config)# router ospf 1
R1(config-router)# distance 90 1.1.1.1 0.0.0.0 10
Sets AD to 90 for routes from RID 1.1.1.1 matching ACL 10.
Wildcard mask allows matching multiple RIDs (e.g., 1.1.1.0 0.0.0.255 for a range).
If no ACL is specified, applies to all routes from the matched RID.
Caveat: The distance command with RID and ACL may not behave as expected for non-/32 prefixes. If the same prefix is advertised by multiple routers, OSPF applies the configured AD to all instances of the prefix, not just the matched RID. This is a known limitation in OSPF’s AD processing.
IOS XR
Change AD for all OSPF routes:
XR(config)# router ospf 1
XR(config-ospf)# distance 100
XR(config-ospf)# commit
Change AD for specific routes based on ACL and RID:
XR(config)# ipv4 access-list OSPF_AD
XR(config-ipv4-acl)# permit 192.168.1.0/24
XR(config)# router ospf 1
XR(config-ospf)# distance 90 1.1.1.1 0.0.0.0 OSPF_AD
XR(config-ospf)# commit
Change AD based on route type (not directly supported in IOS XR; use route policies for advanced configuration).
Note: OSPF prefers internal routes (intra-area, inter-area) over external routes due to its route selection hierarchy, regardless of AD.
Default Route Advertisement
A default route (0.0.0.0/0) directs traffic to a gateway (e.g., core router or ISP) when no specific route exists.
Use Cases
Direct remote site routers to the network core.
Provide internet access by pointing to an ISP-facing router.
Advantages
Reduces LSDB size, improving convergence speed.
Lowers CPU and memory usage by minimizing routing table entries.
Drawbacks
May lead to suboptimal routing or blackholing if not carefully designed.
Configuration
IOS/IOS XE
R1(config)# router ospf 1
R1(config-router)# default-information originate always
IOS XR
XR(config)# router ospf 1
XR(config-ospf)# default-information originate always
XR(config-ospf)# commit
Default Route Injection Options
Advertise to All Areas:
Use default-information originate [always].
The always keyword advertises the default route even if no default route exists in the routing table.
Without always, a default route (e.g., static route to Null0) must exist in routing table.
Advertise to Stub Areas:
Stub, Totally Stubby, and Totally NSSA areas automatically receive a default route from the ABR.
For NSSA areas, use:
R1(config)# router ospf 1
R1(config-router)# area 1 nssa default-information-originate
Additional Options for Default Route
Metric: Set the metric for the default route:
R1(config-router)# default-information originate metric 10
Metric-Type: Specify the external route type (E1 or E2):
R1(config-router)# default-information originate metric-type 1
E1: Metric increases as the route propagates.
E2 (default): Metric remains fixed.
Route-Map: Conditionally advertise the default route based on a route’s presence:
R1(config)# access-list 1 permit 5.5.5.0 0.0.0.3
R1(config)# route-map ISP_CHECK permit 10
R1(config-route-map)# match ip address 1
R1(config)# router ospf 1
R1(config-router)# default-information originate route-map ISP_CHECK
Advertises the default route only if 5.5.5.0/30 (e.g., ISP link) is in the routing table.
Note: A default route can be redistributed into OSPF (e.g., from a static route) using the redistribute command, but this generates an external LSA (Type 5).