Skip to main content
  1. Router and Switch Articles/
  2. IOS-XR/

IOS XR OSPF Basic Configuration

Table of Contents

How to Configure OSPF on Cisco IOS XR

This is the command for enabling OSPF on Cisco IOS XR. In router ospf configuration mode, you list the interfaces that run OSPF area by area. For how OSPF works (adjacencies, the LSDB, SPF), see What is OSPF?.

IOS XR OSPF Basic Configuration
router ospf [PROCESS_NAME]
 router-id [ROUTER_ID]
 area [AREA_ID]
  interface [INTERFACE_NAME]
  !
 !
!
FieldValue
[PROCESS_NAME]The name of the OSPF process. It can be a number or a string (e.g. 1, CORE)
[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)
[AREA_ID]A decimal number such as 0, or dotted-decimal notation such as 0.0.0.0
[INTERFACE_NAME]An interface that runs OSPF in that area (e.g. GigabitEthernet0/0/0/0, Loopback0)

IOS XR has no network command like IOS XE. You list the interfaces that run OSPF one by one as interface under area.

Passive Interfaces

For interfaces such as a Loopback, or a segment that only holds end hosts, which you advertise as a route but where there is no OSPF peer, add passive enable. It stops Hellos so no adjacency is formed, while the network on that interface is still advertised into OSPF. It corresponds to passive-interface on IOS XE.

IOS XR OSPF Passive Interface Configuration
router ospf [PROCESS_NAME]
 area [AREA_ID]
  interface [INTERFACE_NAME]
   passive enable
  !
 !
!

You can confirm that passive enable is in effect with show ospf interface. A physical interface shows the line No Hellos (Passive interface). A Loopback becomes Network Type LOOPBACK and never sends Hellos in the first place, so that line does not appear.

Inheritance of Settings

Settings that apply to interfaces, such as passive, cost, priority and hello-interval, can be written directly under router ospf, under area, or under interface. A value written at a higher level is inherited by the lower levels, and a value written at a lower level takes precedence. Writing passive enable directly under router ospf makes every interface passive, and you can then cancel it with passive disable only on the interfaces that send Hellos.

IOS XE enables OSPF with network <address> <wildcard-mask> area <area-id> under router ospf <process-number>, and interface-specific settings are made with ip ospf ... under interface. On IOS XR everything is collected in the process / area / interface hierarchy, so the whole OSPF configuration can be read from show running-config router ospf alone.

Cisco IOS XR OSPF Verification Commands

OSPF on IOS XR is checked with the show ospf family of commands (the equivalent of show ip ospf on IOS XE; there is no ip). [PROCESS_NAME] can be omitted when there is only one process.

CommandWhat it shows
show ospf [PROCESS_NAME]An overview of the process: router ID, the list of areas, the number of SPF runs, and the various timers
show ospf neighborThe list of neighbors: Neighbor ID, state (such as FULL/DR), dead timer, remote address, and interface
show ospf neighbor detailNeighbor details: the Options field, DR/BDR, and the count and time of state changes
show ospf interface briefOne line per OSPF-enabled interface: area, cost, state (DR/BDR/DROTHER/LOOP), and neighbor count
show ospf interface [INTERFACE_NAME]Interface details: network type, cost, priority, DR/BDR, Hello/Dead timers, and passive state
show ospf databaseThe LSDB summary by LSA type. Append router / network / summary / external for the contents of each LSA
show ospf routesThe result of the SPF calculation: cost, next hop, and advertising router per destination
show route ospfThe routes learned through OSPF in the routing table (O, O IA, O E2, and so on)
show ospf statisticsThe number of SPF runs and how long they took, plus LSA generation and reception counts
show ospf trace eventsThe internal event history of the OSPF process (router ID selection, neighbor state changes). It can be read out after the fact
show running-config router ospfThe entire OSPF configuration
show router-idThe device’s global router ID and the interface it comes from (the candidate used when router-id is omitted)

The operations that reset OSPF state are as follows.

CommandAction
clear ospf [PROCESS_NAME] processResets the OSPF process (clears adjacencies and the LSDB and rebuilds them). It prompts with Reset OSPF process? [no]:
clear ospf [PROCESS_NAME] statisticsClears the counters shown by show ospf statistics
process restart ospfRestarts the OSPF process itself. There is no prompt

Verification on Real Devices

We connected three routers, XR1 to XR3, in a line over GigabitEthernet, with a host attached to XR1 and XR3 at each end. Every link is in area 0. The Loopback0 address of each router (1.1.1.1 to 3.3.3.3) is used as the router ID.

Loopback0 and the host-facing GigabitEthernet0/0/0/1 on XR1 and XR3 are passive interfaces. There is no OSPF router on the host side, so there is no need to send Hellos.

RouterRouter IDInterfaces running OSPF
XR11.1.1.1Loopback0 (passive), Gi0/0/0/0 (10.1.2.1/24), Gi0/0/0/1 (10.1.10.1/24, passive)
XR22.2.2.2Loopback0 (passive), Gi0/0/0/0 (10.1.2.2/24), Gi0/0/0/1 (10.2.3.2/24)
XR33.3.3.3Loopback0 (passive), Gi0/0/0/0 (10.2.3.3/24), Gi0/0/0/1 (10.3.10.1/24, passive)

The hosts run Ubuntu 26.04. HOST1 is configured with 10.1.10.10/24 and HOST2 with 10.3.10.10/24, each with its default gateway pointing at the router it is attached to.

OSPF Configuration

XR1 OSPF Configuration
router ospf 1
 router-id 1.1.1.1
 area 0
  interface Loopback0
   passive enable
  !
  interface GigabitEthernet0/0/0/0
  !
  interface GigabitEthernet0/0/0/1
   passive enable
  !
 !
!
XR2 OSPF Configuration
router ospf 1
 router-id 2.2.2.2
 area 0
  interface Loopback0
   passive enable
  !
  interface GigabitEthernet0/0/0/0
  !
  interface GigabitEthernet0/0/0/1
  !
 !
!
XR3 OSPF Configuration
router ospf 1
 router-id 3.3.3.3
 area 0
  interface Loopback0
   passive enable
  !
  interface GigabitEthernet0/0/0/0
  !
  interface GigabitEthernet0/0/0/1
   passive enable
  !
 !
!

Here is the configuration being entered on XR1. It takes effect on commit.

XR1 OSPF Configuration Example
RP/0/RP0/CPU0:XR1#configure
Thu Sep 10 04:38:23.855 UTC
RP/0/RP0/CPU0:XR1(config)#router ospf 1
RP/0/RP0/CPU0:XR1(config-ospf)#router-id 1.1.1.1
RP/0/RP0/CPU0:XR1(config-ospf)#area 0
RP/0/RP0/CPU0:XR1(config-ospf-ar)#interface Loopback0
RP/0/RP0/CPU0:XR1(config-ospf-ar-if)#passive enable
RP/0/RP0/CPU0:XR1(config-ospf-ar-if)#exit
RP/0/RP0/CPU0:XR1(config-ospf-ar)#interface GigabitEthernet0/0/0/0
RP/0/RP0/CPU0:XR1(config-ospf-ar-if)#exit
RP/0/RP0/CPU0:XR1(config-ospf-ar)#interface GigabitEthernet0/0/0/1
RP/0/RP0/CPU0:XR1(config-ospf-ar-if)#passive enable
RP/0/RP0/CPU0:XR1(config-ospf-ar-if)#exit
RP/0/RP0/CPU0:XR1(config-ospf-ar)#commit
Thu Sep 10 04:38:25.172 UTC
RP/0/RP0/CPU0:XR1(config-ospf-ar)#end
RP/0/RP0/CPU0:XR1#show running-config router ospf
Thu Sep 10 04:38:28.041 UTC
router ospf 1
 router-id 1.1.1.1
 area 0
  interface Loopback0
   passive enable
  !
  interface GigabitEthernet0/0/0/0
  !
  interface GigabitEthernet0/0/0/1
   passive enable
  !
 !
!

Verifying the Configuration

show ospf neighbor shows the neighbors. XR2 in the middle reaches Full with both of its neighbors.

XR2 show ospf neighbor
RP/0/RP0/CPU0:XR2#show ospf neighbor
Thu Sep 10 04:40:04.683 UTC

* Indicates MADJ interface
# Indicates Neighbor awaiting BFD session up

Neighbors for OSPF 1

Neighbor ID     Pri   State           Dead Time   Address         Interface
1.1.1.1         1     FULL/BDR        00:00:36    10.1.2.1        GigabitEthernet0/0/0/0
    Neighbor is up for 00:01:19
3.3.3.3         1     FULL/DR         00:00:34    10.2.3.3        GigabitEthernet0/0/0/1
    Neighbor is up for 00:01:03

Total neighbor count: 2

show ospf interface brief shows which interface runs in which area, the DR/BDR role, and the neighbor count. On XR1, Gi0/0/0/0 facing XR2 has a neighbor count of 1/1, while the passive Gi0/0/0/1 has 0/0. Loopback0 appears as LOOP.

XR1 show ospf interface brief
RP/0/RP0/CPU0:XR1#show ospf interface brief
Thu Sep 10 04:39:44.874 UTC

* Indicates MADJ interface, (P) Indicates fast detect hold down state

Interfaces for OSPF 1

Interface          PID   Area            IP Address/Mask    Cost  State Nbrs F/C
Lo0                1     0               1.1.1.1/32         1     LOOP  0/0
Gi0/0/0/0          1     0               10.1.2.1/24        1     BDR   1/1
Gi0/0/0/1          1     0               10.1.10.1/24       1     DR    0/0

Looking at the details of the passive interface with show ospf interface, it reports No Hellos (Passive interface) and a neighbor count of 0.

XR1 show ospf interface GigabitEthernet0/0/0/1
RP/0/RP0/CPU0:XR1#show ospf interface GigabitEthernet0/0/0/1
Thu Sep 10 04:40:40.666 UTC

GigabitEthernet0/0/0/1 is up, line protocol is up 
  Internet Address 10.1.10.1/24, Area 0, SID 0, Strict-SPF SID 0
  Label stack Primary label 0 Backup label 0 SRTE label 0
  Process ID 1, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 1
  Transmit Delay is 1 sec, State DR, Priority 1, MTU 1500, MaxPktSz 1500
  Forward reference No, Unnumbered no,  Bandwidth 1000000 
  RIB LC sync Yes
  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
    No Hellos (Passive interface) 
  Index 3/3, flood queue length 0
  Next 0(0)/0(0)
  Last flood scan length is 0, maximum is 0
  Last flood scan time is 0 msec, maximum is 0 msec
  LS Ack List: current length 0, high water mark 0
  Neighbor Count is 0, Adjacent neighbor count is 0
  Suppress hello for 0 neighbor(s)
  Multi-area interface Count is 0
  Segment Routing Forwarding MPLS enabled: Yes
  Adjacency hold timer expired last : Never
  Exchange timer expired last : Never

show route ospf shows the routes learned through OSPF (O). Besides the Loopback0 addresses of the other two routers, XR1 also has 10.3.10.0/24, the host segment behind the passive interface on XR3. Stopping Hellos does not stop the network on that interface from being advertised into OSPF.

XR1 show route ospf
RP/0/RP0/CPU0:XR1#show route ospf
Thu Sep 10 04:39:43.518 UTC

O    2.2.2.2/32 [110/2] via 10.1.2.2, 00:00:21, GigabitEthernet0/0/0/0
O    3.3.3.3/32 [110/3] via 10.1.2.2, 00:00:06, GigabitEthernet0/0/0/0
O    10.2.3.0/24 [110/2] via 10.1.2.2, 00:00:11, GigabitEthernet0/0/0/0
O    10.3.10.0/24 [110/3] via 10.1.2.2, 00:00:06, GigabitEthernet0/0/0/0

We ran a ping from HOST1 to HOST2 to confirm that the two end hosts reach each other over the routes learned through OSPF.

HOST1 ping 10.3.10.10
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=16.7 ms
64 bytes from 10.3.10.10: icmp_seq=2 ttl=61 time=10.2 ms
64 bytes from 10.3.10.10: icmp_seq=3 ttl=61 time=10.3 ms
64 bytes from 10.3.10.10: icmp_seq=4 ttl=61 time=11.6 ms
64 bytes from 10.3.10.10: icmp_seq=5 ttl=61 time=11.4 ms

--- 10.3.10.10 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4007ms
rtt min/avg/max/mdev = 10.157/12.017/16.720/2.417 ms

Test Configuration and show Output

The following three kinds of output were collected from all three routers, split per router. The test configuration is these ..._run.txt files.

FileContents
..._show.txtshow version / show interface description / show route / show route ospf / show ospf / show ospf interface / show ospf interface brief / show ospf neighbor / show ospf neighbor detail / show ospf database / show ospf database router / show ospf database network / show ospf statistics interface / show ospf routes / show ospf statistics / show router-id / show ospf trace events
..._log.txtshow logging, taken by inserting a marker with logmsg just before configuring OSPF and passing its timestamp to show logging start
..._run.txtshow running-config (that is, the test configuration)
Routershow outputsyslogrunning-config
XR1showlogrun
XR2showlogrun
XR3showlogrun

Related Articles

For how OSPF works, see What is OSPF?; for how the router ID is chosen, see OSPF Router ID.