Previous section   Next section

Recipe 8.8 Setting the OSPF RID

8.8.1 Problem

You want to set the OSPF Router ID (RID) of a particular router.

8.8.2 Solution

There are several ways to set the OSPF RID. The easiest is to create and configure a loopback interface:

Router5#configure terminal 
Enter configuration commands, one per line.  End with CNTL/Z.
Router5(config)#interface Loopback0
Router5(config-if)#ip address 172.25.25.6 255.255.255.255
Router5(config-if)#end
Router5#

If you don't want to use a Loopback interface, you can still force the router ID to use a particular IP address with the router-id configuration command:

Router5#configure terminal 
Enter configuration commands, one per line.  End with CNTL/Z.
Router5(config)#router ospf 87
Router5(config-router)#router-id 172.25.1.7
Router5(config-router)#end
Router5#

8.8.3 Discussion

If you don't use either of these methods, the router will select the highest IP address from its interfaces and use this as the OSPF RID. The trouble with doing this is that you might add a new IP address to the router at some point. If this new address is higher than the previous RID, the router will change its RID the next time OSPF restarts. This could have strange consequences because, if the interface priorities are the same, OSPF uses the highest RID to select the DR. Please refer to Recipe 8.7 for more information on DR selection.

We recommend using the loopback interface method. Loopback interfaces also ensure that there is a single unique IP address for every router in the network, which is extremely useful for network management. Further, it is common to configure your loopback addresses in DNS, but not to necessarily include all of your interfaces. This is useful if you enable domain name lookups on your router, as discussed in Recipe 8.16.

In IOS Version 12.0, Cisco introduced a new way to select the RID using the router-id command. This command allows you to set the RID to any IP address. You can even set the RID to be an address that is not configured on any of the router's interfaces or even in any routing tables. However, this is not a very wise thing to do because it makes troubleshooting much more difficult.

In some cases, you might have both a router-id and a loopback address set. The rule is that OSPF will use the router-id command first, if one exists. If there is no router-id command, then it uses the highest IP address on any of the loopback interfaces. Bear in mind that you can configure as many loopback interfaces as you like (although this is somewhat unusual in production networks, there are special situations where additional loopback interfaces can be useful). Finally, if there is no router-id command and no loopback interface, the OSPF process will use the highest IP address on the router for the RID.

You can see what the RID for your router is with the following command:

Router5#show ip ospf 
 Routing Process "ospf 87" with ID 172.25.1.7
 Supports only single TOS(TOS0) routes
 SPF schedule delay 5 secs, Hold time between two SPFs 10 secs
 Minimum LSA interval 5 secs. Minimum LSA arrival 1 secs
 Number of external LSA 5. Checksum Sum 0x28868 
 Number of DCbitless external LSA 0
 Number of DoNotAge external LSA 0
 Number of areas in this router is 1. 1 normal 0 stub 0 nssa
    Area BACKBONE(0)
        Number of interfaces in this area is 2
        Area has no authentication
        SPF algorithm executed 47 times
        Area ranges are
        Number of LSA 36. Checksum Sum 0xEEAA1 
        Number of DCbitless LSA 9
        Number of indication LSA 0
        Number of DoNotAge LSA 0
Router5#

The router will continue to use the same RID address, even if you subsequently add a router-id command or a loopback interface. To force OSPF to update the RID, you can either reload the router or restart the OSPF process using the clear ip ospf process command:

Router5#clear ip ospf process
Reset ALL OSPF processes? [no]: yes
Router5#

8.8.4 See Also

Recipe 8.7; Recipe 8.16


  Previous section   Next section
Top