OSPF Router ID

I installed and configured a L3 switch with OSPF but the router id was not what I expected.

I have 4 ip addresses on the switch.
GigabitEthernet1/0/25  192.xxx.xxx.62
GigabitEthernet1/0/26  192.xxx.xxx.66
Loopback0              192.xxx.xxx.30
Vlan213                192.xxx.xxx.1

I expected the loopback interface to become the OSPF router id but it was 192.xxx.xxx.1

Looked at the config and noticed the the loopback 0 had a mask of 255.255.255.252 and changed that to 255.255.255.255 and did a "clear ip ospf process" but could not get the router id to change.

Reloaded the switch and now the router id is 192.xxx.xxx.30 which is the loopback address.

Why did loopback 0 not become the router id?

Could I have got the router id to change without reloading the switch?
Dragon0x40Asked:
Who is Participating?
 
Nayyar HH (CCIE RS)Connect With a Mentor Network ArchitectCommented:
I've just tested and what I found was

Without Router-id command:

- The subnet mask on the lo0 interface has no effect on selection process.

- If say lo1 and lo2 are active, lo1>lo2 and lo2 is the router-id. And Lo2 state is up/up then the router would need a reboot or OSPF reconfig for Lo1 to be selected as router-id (clear ip ospf process doesnt seem to do it)

- If say lo1 and lo2 are active, lo1>lo2 and lo2 is the router-id. And Lo2 state is down/down then the router would select a  new router-id after a "clear ip ospf process"

It holds true for Interfaces as well.

With Router-id command:

Change takes place immediately without a reboot or restart.
0
 
HodepineConnect With a Mentor Commented:
Hmm, I expected the clear ip ospf process would do it. I teach the routing course from Cisco, and as far as I remember this course says it will do so (I haven't looked it up, though), but I tried it on a router here, just to see for my self:

Router(config)#int fa 0/1
Router(config-if)#no shut
Router(config-if)#ip add 10.1.1.1 255.255.255.0
Router(config-if)#
Router(config-if)#
Router(config-if)#router ospf 1
Router(config-router)#network 10.1.1.0 0.0.0.255 area 0
Router(config-router)#end
Router#show ip ospf
 Routing Process "ospf 1" with ID 10.1.1.1
...

Router(config)#int loo 0
Router(config-if)#ip add 10.255.255.1 255.255.255.255
Router(config-if)#end

Router#clear ip ospf 1 process
Reset OSPF process? [no]: yes
Router#show ip ospf
 Routing Process "ospf 1" with ID 10.1.1.1
....

So, no change here either. The rule is the OSPF ID is the highest numbered interface (or highest numbered loopback if present) when the process starts, and my understanding was the process would be restarted with the clear ip ospf command. I'll have to get to the bottom of this before I teach the next course... But, anyway, an alternative to reloading the router is removing and replacing the ospf config:

Router(config)#no router ospf 1
Router(config)#router ospf 1
Router(config-router)#network 10.1.1.0 0.0.0.255 area 0
Router(config-router)#end
Router#show ip ospf
 Routing Process "ospf 1" with ID 10.255.255.1

Don't do this if you're dependent on the OSPF routes to reach the router, obviously. It'll give you an network outage if it's a router in production, but much less than a complete reload.
With cut and paste the config is replaced in >1 second.
0
 
Nayyar HH (CCIE RS)Network ArchitectCommented:
This is an Interesting scenario ... Hodepine please can you try your test again but explicitly specifying the router id with the router-id command?

I'm guessing the behavior of IOS might be that it only considers loopbacks as candidates for router-id selection when router is starting up AND no router-id command is used ... The Cisco OSPF Design Guide says ".......The router-id is only calculated at boot time or anytime the OSPF process is restarted ....." Which leads me to believe there more to this story.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
HodepineCommented:
Router(config)#no int loo 0
% Not all config may be removed and may reappear after reactivating the logical-interface/sub-interfaces
Router(config)#
Router(config)#
Router(config)#end
Router#clear ip ospf 1 proc
Reset OSPF process? [no]: y
Router#
Router#show ip ospf
 Routing Process "ospf 1" with ID 10.1.1.1

This is from the same router, so it had the 10.255.255.1 Router-ID. It changes back when the process is cleared when the loopback address isn't available anymore, so works as predicted that way.

Router(config)#router ospf 1
Router(config-router)#router-id 10.255.255.1
Router(config-router)#end
Router#clear ip ospf 1 proc
Reset OSPF process? [no]: yes
Router#show ip ospf
 Routing Process "ospf 1" with ID 10.255.255.1

It changes as predicted here as well, so this is obviously an issue with getting the router-ID from the loopback interface.
0
 
Nayyar HH (CCIE RS)Network ArchitectCommented:
So I guess we can safely say it does so dynamically only with the router-id command. Otherwise the router would need to be rebooted.
0
 
Dragon0x40Author Commented:
thanks Hodepine and nazsky,

This is an access switch that was just installed so reloading was not a problem and I was connected via console cable.

I have used the router-id command to force the id before but just decided to reload this time.

If I had used the correct host mask of 255.255.255.255 for loopback0 I guess that loopback0 would have become the ospf id at boot time.
0
 
Dragon0x40Author Commented:
Very good information!

How did you get lo2 to be the router-id if lo1>lo2?

What is the correct subnet mask for a loopback interface?

Does the router-id command get stored in the config and take effect on a reload?
0
 
HodepineCommented:
Yes, the router-id command is stored in the config like any other command.

Since the loopback is just a single "host", it's natural to use a /32. Using anything else is in effect a waste of addresses, but technically it's possible to do.

And selection process is interface that is up with highest ip, unless loopback interface is present, then it's loopback interface with highest ip that is up, unless the router-id command is present. And so it's mentioned, loopback interfaces are always up, unless they're administratively down, which is why we use them as router IDs. As long as the router is up, the interface is up.

So why not just use the router-id command instead of using loopbacks? Well, you'll get your router-id set with no fuss, but it won't be a reachable address in your network. In a large OSPF network it's nice to be able to connect to the router-id address of a router without having to know any of it's interface IP addresses.

0
 
Nayyar HH (CCIE RS)Network ArchitectCommented:
How did you get lo2 to be the router-id if lo1>lo2?
By creating lo2 after OSPF has started

What is the correct subnet mask for a loopback interface?
As Hopepine mentioned its usually /32, but can be anything depending on the network design.

Does the router-id command get stored in the config and take effect on a reload?
Again as mentioned above, it is stored in router config. As I mentioned in the previous post it takes effect immediately.


0
 
Dragon0x40Author Commented:
>>How did you get lo2 to be the router-id if lo1>lo2?
>>By creating lo2 after OSPF has started

If lo1 has a higher ip address than the newly created lo2 then how does lo2 take over as the router-id? Wouldn't you have to shut lo1 and then do a "clear ip ospf process" and then no shut lo1? To have the scenario where lo1>lo2 and lo2 is ther router-id and both loopbacks are up/up?

Not arguing with your test and write up.  I am just making sure I understand how this works?
0
 
Nayyar HH (CCIE RS)Network ArchitectCommented:
Sorry should have read "By creating lo1 after OSPF has started"
0
 
Dragon0x40Author Commented:
OK to recap:

3 ways to change router-id:

1. Use the "router-id" command and no reboot is necessary. Takes effect immediately. Saved on reboot.

2. If the interface that is currently the router-id is up/active but you create or activate another interface that by rule should become the router-id then you still have to reboot the router or remove the ospf configuration and re-apply.

3. If you can shut down the interface that is the current router-id then you can use the "clear ip ospf process" command so the loopback with highest ip address is the router-id or if no loopbacks then the interface with highest ip address becomes router-id.
0
 
Nayyar HH (CCIE RS)Network ArchitectCommented:
Yep!

Its good to know just in case you in a situation were you cannot afford a reload.
0
 
Dragon0x40Author Commented:
Can you use the "no router-id" to remove the statement from the config?

Will this leave the current router-id as is?

Just thinking that if you really don't want the "router-id" command in your config and want to let OSPF calculate it at boot time then you could use "router-id" command and then delete it from the config using "no router-id"?
0
 
Nayyar HH (CCIE RS)Network ArchitectCommented:
Yes you can remove with no router-id

Best way to lab know the behavior is to lab it up

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.