Skip to main content

Cisco IOS OSPF Router ID

Network Topology

image.png

What is the OSPF Router ID (RID)?

The OSPF Router ID (RID) is a 32-bit value used to uniquely identify an OSPF router in a network. The Router ID takes the form of an IPv4 network address (i.e.; 1.1.1.1)  It is used by OSPF routers to identify themselves to each other, and is also used as a key for certain OSPF data structures. The RID is typically chosen as the highest IP address of a router's interfaces that are configured for OSPF. If there are multiple interfaces with the same IP address, the RID will be chosen based on the interface's MAC address or on the order in which the interfaces were configured. The RID is used in the OSPF header of OSPF packets, and is also used in the LSA (Link State Advertisement) packets that OSPF routers exchange to form and maintain their routing tables.

How is the OSPF Router ID Selected?

A router chooses its OSPF Router ID (RID) based on the following priority:

  1. The highest IP address of a loopback interface that is configured for OSPF. A loopback interface is a virtual interface that is always up, and is typically used for management purposes.
  2. If there is no loopback interface configured, the highest IP address of a physical interface that is configured for OSPF.
  3. If there are multiple interfaces with the same IP address, the RID will be chosen based on the interface's MAC address.
  4. If all above methods fails to get a unique RID, the router will choose the RID based on the order in which the interfaces were configured.

It is important to note that, once chosen, the RID cannot be changed without restarting the OSPF process on the router. It is also important that all OSPF routers in a single OSPF domain must have unique RIDs.

Router ID in Action with Network Topology Above

The topology above has two physical interfaces and two Loopback interfaces.

Router0# show ip interface brief

image.png

We can start the OSPF router process with the following command:

Router0(config)#router ospf 1
Router0(config-router)end

Now let's check the OSPF Router ID by issuing the command:

Router0#show ip protocols

image.png

As can be seen above the ospf 1 process has chosen the Loopback interface with the highest IP address as its Router ID as we expected from #1 in the explanation above. Now let's remove the Loopback interfaces and see how that effects the OSPF Router ID.

Router0#configure terminal
Router0(config)#no interface loopback 0
Router0(config)#no interface loopback 1
Router0(config)#do show ip interface brief

image.png

Confirmed that the Loopback interfaces have been removed. Let's check the OSPF Router ID now.

Router0(config)#end
Router0#show ip protocols

image.png

The Router ID has not changed! Just like the note above states the OSPF Router ID once chosen cannot be changed without a restart of the OSPF process.  How can we restart the OSPF process?  With this command:

Router0#clear ip ospf process

image.png

Now we can check the Router ID again.

Router0#show ip protocols

image.png

After the reset of the OSPF process the Router ID has been selected from the physical interface with the highest IP address.  Again, just like we would expect from #2 from the explanation above.

Now, what if we did not want the OSPF process to choose it's own Router ID?  What if we wanted to manually set the Router ID, can we do that? Yes! As long as we make sure to set it in the correct format of the 32-btbit value with a 4 octet IPv4 decimal notation address.

Router0#configure terminal
Router0(config)#router ospf 1
Router0(config-fouter)#router-id 10.10.10.10
Router0(config-router#end
Router0#show ip protocols

image.png

As you can see the Router ID is now set to what we manually entered 10.10.10.10.