How to Configure OSPF on Cisco IOS XE
This is the command for enabling OSPF on Cisco IOS XE. In router ospf configuration mode, interfaces that match a network command run OSPF in the specified area. For how OSPF works (adjacencies, the LSDB, SPF), see What is OSPF?.
router ospf [PROCESS_ID]
router-id [ROUTER_ID]
network [ADDRESS] [WILDCARD_MASK] area [AREA_ID]| Field | Value |
|---|---|
| [PROCESS_ID] | The OSPF process number (1-65535). It only distinguishes processes within the device and does not have to match the neighboring router |
| [ROUTER_ID] | A 32-bit value in IPv4 address format (e.g. 1.1.1.1). It is chosen automatically when omitted, but configuring it explicitly is recommended (OSPF Router ID) |
| [ADDRESS] | The address range of the interfaces that run OSPF |
| [WILDCARD_MASK] | A mask where 0 means match and 1 means any (0.0.0.255 for a /24). Use 0.0.0.0 to specify a single interface |
| [AREA_ID] | A decimal number such as 0, or dotted-decimal notation such as 0.0.0.0 |
network is a command that is matched against the IP address configured on an interface. OSPF is enabled on the interfaces that match, and their networks are advertised as routes in the specified area.
Enabling OSPF Under the Interface
Instead of network, you can specify the area directly in interface configuration mode. Because you can tell which interface belongs to which area just by reading the interface configuration, this form is easier to follow when the address ranges are complex.
interface [INTERFACE_NAME]
ip ospf [PROCESS_ID] area [AREA_ID]When both a network command and ip ospf ... area apply to the same interface, the ip ospf ... area under the interface takes precedence.
Passive Interfaces
For interfaces that should be advertised as routes but have no OSPF peer, such as loopbacks and segments that host end devices, specify passive-interface. It stops sending Hellos so no adjacency is formed, but the network of that interface is still advertised into OSPF.
router ospf [PROCESS_ID]
passive-interface [INTERFACE_NAME]You can also make every interface passive by default and bring back only the ones that send Hellos. This is useful when there are more interfaces to make passive than interfaces that run OSPF.
router ospf [PROCESS_ID]
passive-interface default
no passive-interface [INTERFACE_NAME]network command; it lists interfaces one by one as interface under area in router ospf. Passive is also specified as passive enable under area or interface rather than directly under router ospf. Configuration is applied immediately on IOS XE, while IOS XR requires a commit (IOS XR OSPF Basic Configuration).Cisco IOS XE OSPF Verification Commands
OSPF on IOS XE is verified with the show ip ospf family of commands. [PROCESS_ID] can be omitted when there is only one process.
| Command | What it shows |
|---|---|
show ip ospf [PROCESS_ID] | A summary of the process: router ID, the list of areas, the number of SPF runs, and the timers |
show ip ospf neighbor | The list of neighbors: neighbor ID, priority, state (such as FULL/DR), dead time, address, and interface |
show ip ospf neighbor detail | Neighbor details: the Options field, DR/BDR, the number of state changes, and how long the adjacency has been up |
show ip ospf interface brief | One line per interface running OSPF: process, area, cost, state, and neighbor count |
show ip ospf interface [INTERFACE_NAME] | Interface details: network type, cost, priority, DR/BDR, Hello/Dead timers, and whether it is passive |
show ip ospf database | A summary of the LSDB by LSA type. Append router / network / summary / external for the contents of each LSA |
show ip route ospf | The routes in the routing table that were learned by OSPF (O, O IA, O E2, and so on) |
show ip protocols | A summary of the running routing protocols: the OSPF router ID, the network statements, the passive interfaces, and the information sources |
show ip ospf statistics | The number of SPF runs, how long they took, and the LSA that triggered them |
show running-config | section router ospf | The entire OSPF configuration |
The operations that reset the OSPF state are as follows.
| Command | Action |
|---|---|
clear ip ospf [PROCESS_ID] process | Resets the OSPF process (clears adjacencies and the LSDB and rebuilds them). It asks Reset ALL OSPF processes? [no]: |
clear ip ospf [PROCESS_ID] counters | Clears the per-neighbor state change counters |
clear ip ospf [PROCESS_ID] redistribution | Rebuilds the redistributed routes |
When you change router-id afterwards, the new router ID does not take effect until you run clear ip ospf process.
Verification on Real Devices
Three routers, XE1 to XE3, are connected in a line with GigabitEthernet, with a host attached to XE1 and XE3 at each end, and OSPF is configured as a single-area topology. Every link is in area 0. The Loopback0 address of each router (1.1.1.1 to 3.3.3.3) is used as its router ID.
Loopback0 and GigabitEthernet2 on XE1 and XE3, which host the end devices, are configured as passive interfaces. There is no OSPF router on the host side, so there is no need to send Hellos.
| Router | Router ID | Interfaces running OSPF |
|---|---|---|
| XE1 | 1.1.1.1 | Loopback0 (passive), Gi1 (10.1.2.1/24), Gi2 (10.1.10.1/24, passive) |
| XE2 | 2.2.2.2 | Loopback0 (passive), Gi1 (10.1.2.2/24), Gi2 (10.2.3.2/24) |
| XE3 | 3.3.3.3 | Loopback0 (passive), Gi1 (10.2.3.3/24), Gi2 (10.3.10.1/24, passive) |
The hosts run Ubuntu 26.04, with 10.1.10.10/24 on HOST1 and 10.3.10.10/24 on HOST2, and their default gateway pointing at the router that hosts them. The devices are Catalyst 8000V (IOS XE 17.18.02).
OSPF Configuration
OSPF is configured on XE1. On IOS XE the configuration takes effect as soon as end is entered. Loopback0 and GigabitEthernet2 on the host side are configured as passive-interface.
XE1#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
XE1(config)#router ospf 1
XE1(config-router)# router-id 1.1.1.1
XE1(config-router)# network 1.1.1.1 0.0.0.0 area 0
XE1(config-router)# network 10.1.2.0 0.0.0.255 area 0
XE1(config-router)# network 10.1.10.0 0.0.0.255 area 0
XE1(config-router)# passive-interface Loopback0
XE1(config-router)# passive-interface GigabitEthernet2
XE1(config-router)#end
XE1#show running-config | section router ospf
router ospf 1
router-id 1.1.1.1
passive-interface GigabitEthernet2
passive-interface Loopback0
network 1.1.1.1 0.0.0.0 area 0
network 10.1.2.0 0.0.0.255 area 0
network 10.1.10.0 0.0.0.255 area 0Loopback0 is specified with a wildcard mask of 0.0.0.0, as in network 1.1.1.1 0.0.0.0 area 0, so that only that address matches. In show running-config the passive-interface lines are grouped before the network lines rather than in the order they were entered.
XE2 and XE3 are configured in the same way. XE2 hosts no end device, so only Loopback0 is made passive.
(XE2)
router ospf 1
router-id 2.2.2.2
passive-interface Loopback0
network 2.2.2.2 0.0.0.0 area 0
network 10.1.2.0 0.0.0.255 area 0
network 10.2.3.0 0.0.0.255 area 0
(XE3)
router ospf 1
router-id 3.3.3.3
passive-interface GigabitEthernet2
passive-interface Loopback0
network 3.3.3.3 0.0.0.0 area 0
network 10.2.3.0 0.0.0.255 area 0
network 10.3.10.0 0.0.0.255 area 0Verifying the Configuration
show ip ospf neighbor shows the neighbors. XE2 is in the middle, so it has an adjacency with both sides and prints two lines. FULL means the LSDB synchronization is complete.
XE2#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
3.3.3.3 1 FULL/DR 00:00:32 10.2.3.3 GigabitEthernet2
1.1.1.1 1 FULL/BDR 00:00:36 10.1.2.1 GigabitEthernet1What follows the / in State is the role on that segment. The network type on Ethernet is BROADCAST by default, so a DR and a BDR are elected even on a link with only two routers.
show ip ospf interface brief lists the interfaces on which OSPF is running. Nbrs F/C is the number of adjacencies (Full) and the number of detected neighbors.
XE1#show ip ospf interface brief
Interface PID Area IP Address/Mask Cost State Nbrs F/C
Lo0 1 0 1.1.1.1/32 1 LOOP 0/0
Gi2 1 0 10.1.10.1/24 1 DR 0/0
Gi1 1 0 10.1.2.1/24 1 BDR 1/1Gi2, which was made passive, shows 0/0 for Nbrs F/C. However State is still DR, so this list alone does not tell you whether an interface is passive. It sends no Hellos, so there is no peer and it simply becomes the DR itself.
Use the detailed output of show ip ospf interface to confirm that an interface is passive.
XE1#show ip ospf interface GigabitEthernet2
GigabitEthernet2 is up, line protocol is up
Internet Address 10.1.10.1/24, Interface ID 6, Area 0
Attached via Network Statement
Process ID 1, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 1
Topology-MTID Cost Disabled Shutdown Topology Name
0 1 no no Base
Transmit Delay is 1 sec, State DR, Priority 1
Designated Router (ID) 1.1.1.1, Interface address 10.1.10.1
No backup designated router on this network
Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
oob-resync timeout 40
No Hellos (Passive interface)
Supports Link-local Signaling (LLS)
Cisco NSF helper support enabled
IETF NSF helper support enabled
Index 1/3/3, flood queue length 0
Next 0x0(0)/0x0(0)/0x0(0)
Last flood scan length is 0, maximum is 0
Last flood scan time is 0 msec, maximum is 0 msec
Neighbor Count is 0, Adjacent neighbor count is 0
Suppress hello for 0 neighbor(s)No Hellos (Passive interface) appears where the Hello interval would normally be shown, and Neighbor Count is 0. Attached via Network Statement means the interface was enabled by a network command; when it is enabled with ip ospf 1 area 0 under the interface, it reads Attached via Interface Enable instead.
show ip route ospf shows the routes learned by OSPF (O). In addition to the Loopback0 addresses of the other two routers, XE1 also has 10.3.10.0/24, the host segment behind the passive interface on XE3. Stopping Hellos does not stop the network of that interface from being advertised into OSPF.
XE1#show ip route ospf | begin Gateway
Gateway of last resort is not set
2.0.0.0/32 is subnetted, 1 subnets
O 2.2.2.2 [110/2] via 10.1.2.2, 00:04:06, GigabitEthernet1
3.0.0.0/32 is subnetted, 1 subnets
O 3.3.3.3 [110/3] via 10.1.2.2, 00:04:02, GigabitEthernet1
10.0.0.0/8 is variably subnetted, 6 subnets, 2 masks
O 10.2.3.0/24 [110/2] via 10.1.2.2, 00:04:02, GigabitEthernet1
O 10.3.10.0/24 [110/3] via 10.1.2.2, 00:04:02, GigabitEthernet1The code legend is long, so | begin Gateway skips the beginning of the output.
A ping from HOST1 to HOST2 confirms that the end devices can reach each other over the routes learned by OSPF.
cisco@HOST1:~$ ping -c 5 10.3.10.10
PING 10.3.10.10 (10.3.10.10) 56(84) bytes of data.
64 bytes from 10.3.10.10: icmp_seq=1 ttl=61 time=6.67 ms
64 bytes from 10.3.10.10: icmp_seq=2 ttl=61 time=6.51 ms
64 bytes from 10.3.10.10: icmp_seq=3 ttl=61 time=5.86 ms
64 bytes from 10.3.10.10: icmp_seq=4 ttl=61 time=7.60 ms
64 bytes from 10.3.10.10: icmp_seq=5 ttl=61 time=5.76 ms
--- 10.3.10.10 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4007ms
rtt min/avg/max/mdev = 5.757/6.478/7.595/0.660 msttl=61 is the Linux initial value of 64 decremented by three as the packet passes through three routers.
Verification Configuration and show Output
The following three kinds of output were collected from all three routers, in separate files per router. The verification configuration is the ..._run.txt file.
| File | Contents |
|---|---|
..._show.txt | show version / show interfaces description / show ip interface brief / show ip route / show ip protocols / show ip ospf / show ip ospf interface / show ip ospf interface brief / show ip ospf neighbor / show ip ospf neighbor detail / show ip ospf database / show ip ospf database router / show ip ospf database network / show ip route ospf / show ip ospf statistics |
..._log.txt | show logging narrowed down from a send log marker that was inserted just before OSPF was configured. It contains the %OSPF-5-ADJCHG messages where the adjacencies reach FULL |
..._run.txt | show running-config (that is, the verification configuration) |
| Router | show output | syslog | running-config |
|---|---|---|---|
| XE1 | show | log | run |
| XE2 | show | log | run |
| XE3 | show | log | run |
Related Articles
For how OSPF works see What is OSPF?, and for how the router ID is chosen see OSPF Router ID. The configuration on IOS XR is covered in IOS XR OSPF Basic Configuration.