What is OSPF Router ID? What is the format of the router ID on an OSPF-enabled router? In this tutorial, I answer these questions and more. You will learn a lot of stuff about OSPF Router ID (RID), including its definition, purpose, selection process, configuration, and more. Also, you will learn how to change a router ID in OSPF, and I will discuss the case when two OSPF-enabled routers have the same router ID.

Before continuing, note that OSPF is part of the CCNA, CCNP ENCOR, and CCNP ENARSI exams.

What is OSPF Router ID?

OSPF router ID is a 32-bit binary number, written in a dotted-decimal format similar to an IPv4 address, that must be uniquely assigned to distinguish each router within an OSPF Autonomous System.

As a side note, an autonomous system is a group of routers managed by the same administrative authority. As OSPF areas’ network data are separated from one another, router IDs should be unique only within each area, and not across the entire autonomous system. However, you shouldn’t give the same router ID to two routers regardless of whether they are in separate OSPF areas as that would make troubleshooting harder.

Most of the time, The OSPF RID is one of the IPv4 addresses present on the local router. Now let’s see how a router running OSPF selects the Router ID in Cisco IOS and IOS XR.

What is The Purpose of OSPF Router ID?

In OSPF, routers build a network map to calculate the shortest path to every network prefix. Each router labels the other routers before applying Dijkstra’s algorithm. Also, each router needs a way to recognize and track all routers on the map.

Here comes the concept of OSPF router ID, which helps identify all nodes in the OSPF autonomous system. An OSPF router ID consists of a number between 0.0.0.1 and 255.255.255.255 that should be uniquely assigned, and it is used to track every router in the OSPF domain. Additionally, OSPF router ID and priority are used in DR/BDR election on multi-access data links.

OSPF Router ID Selection Process on Cisco IOS and IOS XR

OSPF Router ID Selection Process on Cisco IOS

On Cisco routers, you can create many OSPF instances that work independently from one another. Each instance can have a distinct Router ID. It is not mandatory to give them identical Router IDs. Cisco IOS uses the following process to generate the Router ID of a particular OSPF instance:

Step 1. If the RID has been explicitly assigned to the current OSPF instance using the router-id command, Cisco IOS uses that Router ID.

Step 2. If no Router ID has been explicitly configured, Cisco IOS uses the highest IPv4 address on active loopback interfaces. Down loopback interfaces are not used in the selection process.

Step 3. If no IP-enabled loopback interfaces are eligible for use, the router selects the highest IPv4 address on active physical interfaces.

Finally, an interface whether it is loopback or physical does not have to be advertised in the OSPF autonomous system in order to be used in the Router ID selection process.

In the rest of this tutorial, we use the network topology in Figure 1.
ospf-router-idFigure 1 – Network topology of an OSPFv2 routing domain

Before continuing, here are the links to download the configurations of routers R1, R2, R3, R4, and R5. Additionally, the router-id command is issued on router R5 only.

Router R1 Router R2 Router R3
Router R4 Router R5

In Exhibit 1, the show ip ospf command output reveals that R4’s OSPF RID is 10.0.40.4, which represents the highest IP address on all active loopback interfaces (Exhibit 2).

R4# show ip ospf
 Routing Process "ospf 1" with ID 10.0.40.4
 Start time: 03:48:59.905, Time elapsed: 00:38:00.832
 Supports only single TOS(TOS0) routes
 Supports opaque LSA
 Supports Link-local Signaling (LLS)
 Supports area transit capability

omitted output

Exhibit 1 – OSPF settings of instance 1 on R4

R4# show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
GigabitEthernet0/0         10.0.234.4      YES manual up                    up      
GigabitEthernet0/1         unassigned      YES unset  administratively down down    
GigabitEthernet0/2         unassigned      YES unset  administratively down down    
GigabitEthernet0/3         unassigned      YES unset  administratively down down    
Loopback0                  10.0.40.4       YES manual up                    up      
Loopback1                  10.0.4.4        YES manual up                    up

Exhibit 2 – Listing router R4’s IP-enabled interfaces

In Exhibit 3, the show ip protocols command output indicates that 1.1.1.1 is the router ID of router R1. Although the highest IP address on loopback interfaces is 10.0.10.1, R1 chooses to use 1.1.1.1 because it matches the highest IP on up loopback interfaces (Exhibit 4). In fact, interface loopback1 having IP address 10.0.10.1 is down (Exhibit 4).

R1# show ip protocols
*** IP Routing is NSF aware ***

Routing Protocol is "application"
  Sending updates every 0 seconds
  Invalid after 0 seconds, hold down 0, flushed after 0
  Outgoing update filter list for all interfaces is not set
  Incoming update filter list for all interfaces is not set
  Maximum path: 32
  Routing for Networks:
  Routing Information Sources:
    Gateway         Distance      Last Update
  Distance: (default is 4)

Routing Protocol is "ospf 1"
  Outgoing update filter list for all interfaces is not set
  Incoming update filter list for all interfaces is not set
  Router ID 1.1.1.1


  omitted output

Exhibit 3 – Dynamic routing settings on R1

R1# show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
GigabitEthernet0/0         unassigned      YES unset  administratively down down    
GigabitEthernet0/1         unassigned      YES unset  administratively down down    
GigabitEthernet0/2         10.0.12.1       YES manual up                    up      
GigabitEthernet0/3         10.0.13.1       YES manual up                    up      
Loopback0                  1.1.1.1         YES manual up                    up      
Loopback1                  10.0.10.1       YES manual administratively down down

Exhibit 4 – Listing router R1’s IP-enabled interfaces

Exhibit 5 shows that R2 set the router ID to interface G0/0’s IP address even though the router has a couple of loopback interfaces. This is due to the fact that those virtual interfaces are down (Exhibit 6).

R2# show ip ospf interface gigabitEthernet 0/0
GigabitEthernet0/0 is up, line protocol is up 
  Internet Address 10.0.234.2/24, Area 0, Attached via Network Statement
  Process ID 1, Router ID 10.0.234.2, Network Type BROADCAST, Cost: 1
  Topology-MTID    Cost    Disabled    Shutdown      Topology Name
        0           1         no          no            Base


  omitted output

Exhibit 5 – OSPF settings on R2’s GigabitEthernet0/0 interface

R2# show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
GigabitEthernet0/0         10.0.234.2      YES manual up                    up      
GigabitEthernet0/1         10.0.12.2       YES manual up                    up      
GigabitEthernet0/2         unassigned      YES unset  administratively down down    
GigabitEthernet0/3         unassigned      YES unset  administratively down down    
Loopback0                  10.0.20.2       YES manual administratively down down    
Loopback1                  10.0.21.2       YES manual administratively down down    
Loopback2                  10.0.22.2       YES manual administratively down down      

Exhibit 6 – Listing router R2’s IP-enabled interfaces

R5’s OSPF router ID is 5.5.5.5, which does not match any interface IP address (Exhibit 8). In this case, the RID is configured with the router-id command (Exhibit 7), letting the router not rely on IP-enabled interfaces to define the OSPF RID.

R2# show running-config | section ospf
router ospf 1
 router-id 5.5.5.5
 log-adjacency-changes
 network 0.0.0.0 255.255.255.255 area 0

Exhibit 7 – OSPF configuration on R5

R5# show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
GigabitEthernet0/0         10.0.234.5      YES manual up                    up      
GigabitEthernet0/1         unassigned      YES unset  administratively down down    
GigabitEthernet0/2         unassigned      YES unset  administratively down down    
GigabitEthernet0/3         unassigned      YES unset  administratively down down    
Loopback0                  10.0.50.5       YES manual up                    up      
Loopback1                  10.0.51.5       YES manual up                    up   

Exhibit 8 – Listing router R5’s IP-enabled interfaces

Finally, the OSPF router ID selection process, in Cisco IOS, does not take into account inactive interfaces whether they are physical, or loopback.

OSPF Router ID Selection Process on Cisco IOS-XR

Like Cisco IOS, Cisco IOS XR uses a similar OSPF router ID selection procedure, except that it prefers the lowest IP address instead of the highest IP address.

Step 1. If the RID has been explicitly defined on the actual OSPF instance via the router-id command, Cisco IOS XR uses that Router ID.

Step 2. In case the Router ID is not administratively defined, the OSPF RID gets determined using the lowest IPv4 address on operational loopback interfaces. Disabled loopback interfaces are not considered in the election process.

Step 3. If no IP-enabled loopback interfaces are eligible for use, the router selects the lowest IPv4 address on active physical interfaces.

Exhibit 9 indicates that R3, running Cisco IOS XR software, chooses interface loopback 0’s IP address to be the router ID on OSPF process 1. Besides, the show ip interface brief command output (Exhibit 10) confirms that the router ID matches the lowest IP address on R3’s up loopback interfaces.

RP/0/0/CPU0:R3# show ip ospf
Mon Jun 13 01:41:36.850 UTC

 Routing Process "ospf 1" with ID 10.0.30.3
 Role: Primary Active
 NSR (Non-stop routing) is Enabled
 Supports only single TOS(TOS0) routes
 Supports opaque LSA
 Router is not originating router-LSAs with maximum metric
 Initial SPF schedule delay 50 msecs
 Minimum hold time between two consecutive SPFs 200 msecs
 Maximum wait time between two consecutive SPFs 5000 msecs
 Initial LSA throttle delay 50 msecs



 omitted output

Exhibit 9 – OSPF settings on R2

RP/0/0/CPU0:R3# show ip interface brief
Mon Jun 13 01:42:05.888 UTC

Interface                      IP-Address      Status          Protocol Vrf-Name
Loopback0                      10.0.30.3       Up              Up       default 
Loopback1                      10.0.31.3       Up              Up       default 
MgmtEth0/0/CPU0/0              unassigned      Up              Up       default 
GigabitEthernet0/0/0/0         10.0.234.3      Up              Up       default 
GigabitEthernet0/0/0/1         10.0.13.3       Up              Up       default 
GigabitEthernet0/0/0/2         unassigned      Up              Up       default                    up   

Exhibit 10 – Listing router R3’s IP-enabled interfaces

The OSPF Router ID Selection Process is Not Preemptive

The RID selection process in OSPF is not preemptive, meaning once the router defines the RID for the first time, it won’t re-calculate it again each time an IP address is configured (added or removed), an interface gets added, removed, or updated, or the router-id command is issued. Cisco IOS waits until you reboot the router or reset the OSPF process in order to run the OSPF RID selection procedure. In contrast, Cisco IOS XR updates the OSPF router ID once you issue the commit command.

OSPF Router ID Configuration on Cisco IOS and IOS-XR

Using The router-id Command in OSPF

The router-id command allows network engineers to define the router ID of a particular OSPF process on both Cisco IOS and IOS XR. All you need to do, as shown in Exhibit 11, is issue the router ospf command in global configuration mode, and then enter router-id rid, when rid is a value between 1 and 4,294,967,295. You can specify rid in the dotted-decimal format only, and in this case, the range is 0.0.0.1 to 255.255.255.255.

R5(config)# router ospf 1                         
R5(config-router)# router-id 5.5.5.5

Exhibit 11 – Configuring OSPF router ID manually

If a Cisco IOS router has already built neighbor relationships with one or many routers, you must reset the OSPF instance either by reloading the router or using the clear ip ospf command for the router-id command to take effect. Otherwise, you do not have to do it, the RID gets updated instantly.

On Cisco IOS XR, once you enter commit, the RID gets updated immediately if you tried to change it using the router-id command.

Configuring or removing an interface to adjust OSPFv2 RID

If the RID is not set manually, you can change IP addressing on the router, enable, disable, add or remove an interface in order to cause OSPFv2 to pick a new router ID. In Exhibit 12, we activate R1’s loopback1 interface, which has a greater IP address than interface loopback 0. After reloading the router, OSPF sets its OSPFv2 RID to 10.0.10.1 (Exhibit 13).

R1(config)#  interface loopback1
R1(config-if)# no shutdown
R1(config-if)# end
R1#
R1# write
Building configuration...
[OK]
R1#
R1# reload
Proceed with reload? [confirm]

Exhibit 12 – Enabling interface loopback1 and restarting R1

R1# show ip ospf 
 Routing Process "ospf 1" with ID 10.0.10.1
 Start time: 00:00:44.467, Time elapsed: 00:00:53.263
 Supports only single TOS(TOS0) routes
 Supports opaque LSA
 Supports Link-local Signaling (LLS)
 Supports area transit capability
 Supports NSSA (compatible with RFC 3101)
 Supports Database Exchange Summary List Optimization (RFC 5243)
 Event-log enabled, Maximum number of events: 1000, Mode: cyclic
 Router is not originating router-LSAs with maximum metric
 Initial SPF schedule delay 5000 msecs
 Minimum hold time between two consecutive SPFs 10000 msecs
 Maximum wait time between two consecutive SPFs 10000 msecs
 Incremental-SPF disabled
 Minimum LSA interval 5 secs
 Minimum LSA arrival 1000 msecs
 LSA group pacing timer 240 secs
 Interface flood pacing timer 33 msecs
 Retransmission pacing timer 66 msecs
 EXCHANGE/LOADING adjacency limit: initial 300, process maximum 300
 Number of external LSA 0. Checksum Sum 0x000000
 Number of opaque AS LSA 0. Checksum Sum 0x000000
 Number of DCbitless external and opaque AS LSA 0


omitted output

Exhibit 13 – OSPF settings on R1

Using The clear ip ospf process Command to Force Updating OSPF Router ID

On Cisco IOS, you will need to reload the OSPF instance in order to force the router to re-calculate its RID. You can restart OSPF software using the clear IP ospf process command or by rebooting the local router. The clear ip ospf process command is dedicated to resetting one or all OSPF instances installed on the local router.

This Cisco IOS command follows this syntax:
clear ip ospf [process-id] process,

where process-id is an optional value that represents the ID of the OSPF instance you want to restart. Moreover, the command instructs the local router to flush its self-originated link state advertisements from the autonomous system before rebooting.

On Cisco IOS, if you want to set a new OSPF router ID by adding, modifying, or removing a loopback interface, resetting the OSPF using the clear ip ospf process command won’t force updating the RID, and reloading the router would be a must in this case.

On the contrary, the clear IP ospf process command is enough on Cisco IOS XR to instruct OSPF to generate a RID based on the updated settings without the need to reboot the local router.

How to Verify OSPF Router ID on Cisco IOS?

Cisco IOS offers several commands to display the OSPF router ID, including show ip protocols (Exhibit 3), show ip ospf (Exhibit 9), show ip ospf interface (Exhibit 5), and more. However, there is no way to determine whether the router RID has been configured manually or automatically, except by using the show running-config command.

How to Troubleshoot Duplicate OSPF Router IDs?

Routers with duplicate router IDs cannot build an OSPF neighbor relationship. In such case, Cisco IOS displays the following message.

*May  6 02:40:08.651: %OSPF-4-DUP_RTRID_NBR: OSPF detected duplicate router-id 1.1.1.1 from 10.0.16.1 on interface Serial1/1

To solve this issue, change the router ID of one of the routers, causing the issue, using the router-id command in router configuration mode, then clear the current OSPF process using the clear ip ospf ospf_id process command, where ospf_id is the ID of the OSPF instance to reload.

Related Lessons to OSPF Router ID

Conclusion

I hope this blog post helps you learn something.
Now I’d like to turn it over to you:
What did you like about this tutorial?
Or maybe you have an excellent idea that you think I need to add.
Either way, let me know by leaving a comment below right now.

Mohamed Ouamer
Mohamed Ouamer is a computer science teacher and a self-published author. He taught networking technologies and programming for more than fifteen years. While he loves to share knowledge and write, Mohamed's best passions include spending time with his family, visiting his parents, and learning new things.