Sub topic 3
The Router ID and How It Is Chosen
Prerequisites and scope
This chapter assumes you know IPv4 addressing, basic router interface configuration, and the idea that OSPF routers exchange link-state information (covered in the previous two chapters). It covers what the router ID is, the order in which a router picks one, how to set one, and the errors that come from getting it wrong.
What the router ID is
The router ID (RID) is a 32-bit number that identifies one OSPF router within an OSPF domain. It is written in dotted-decimal notation like an IPv4 address, such as 1.1.1.1, but it is only an identifier. It does not have to be a reachable address, and it does not have to exist on any interface.
OSPF uses the RID in several places:
- Every Hello packet carries the sender's RID, so neighbors know who they are talking to.
- Each router's own Router LSA (Type 1) is identified by its RID as the advertising router.
- The neighbor table lists neighbors by RID, not by interface address.
- The DR/BDR election uses the RID as a tiebreaker (covered in a later chapter).
- The link-state database keys every LSA by its type, link-state ID, and advertising router, so two routers with the same RID corrupt each other's entries.
Because the whole domain depends on RIDs being unique, choosing them deliberately is one of the first design decisions in an OSPF network.
How a router chooses its RID
A router selects its RID when the OSPF process starts, using this order:
- A RID configured explicitly with a command such as
router-id 1.1.1.1. - If none is configured, the highest IPv4 address on any active loopback interface.
- If there is no usable loopback, the highest IPv4 address on any other active interface.
"Active" means the interface is up and has an IPv4 address. If none of the three sources produces a value, the OSPF process cannot start and logs an error.
Why the automatic methods are fragile
Loopback interfaces are preferred over physical ones because they do not go down when a cable fails. Even so, relying on automatic selection causes problems:
- The RID is derived from an address, so a later change in addressing can change which RID the router would pick. People then mistake the RID for an interface address and get confused when it differs.
- Adding a loopback with a higher address does not change a running RID, but it will change the RID after the next process restart or reload. The network then changes behavior at an unexpected time.
- Two routers cloned from the same template can pick the same RID.
For these reasons, set the RID explicitly on every router.
Setting the router ID
The configuration below uses Cisco IOS-style syntax. It is a fragment of the full configuration shown in a later chapter.
router ospf 1
router-id 1.1.1.1FRRouting uses a slightly different command for the same idea:
router ospf
ospf router-id 1.1.1.1A common convention is to use a value that identifies the router, such as 1.1.1.1 for R1, 2.2.2.2 for R2, or the address of the router's loopback. Using the loopback address has a practical benefit: the RID then matches an address you can ping and see in logs and in show ip ospf neighbor output.
Changing the router ID on a running router
The process picks its RID only at startup. If you change the configured router-id while OSPF is running, IOS accepts the command but keeps using the old RID until the process restarts. It prints a message telling you so.
To apply the new value, restart the OSPF process:
clear ip ospf processRestarting the process drops every adjacency, clears the link-state database, and rebuilds everything, so you should do it in a maintenance window on production routers. Other implementations behave differently, and some apply the change immediately and reset adjacencies. Check the behavior of your platform before changing a RID on a live network.
Verifying the router ID
Use these commands to see the RID in use:
show ip ospf
show ip protocols
show ip ospf neighborThe first two show the local router's RID near the top of the output. The third shows each neighbor's RID in the Neighbor ID column. Note that the Address column shows the neighbor's interface IP, which is a different value. Mixing up the two columns is a common mistake when reading the neighbor table.
Duplicate router IDs
If two routers in the same OSPF domain use the same RID, the symptoms are subtle and sometimes confusing:
- Adjacency may never form between the two routers, or it may form and then flap, because a router that sees its own RID in a neighbor's Hello rejects it.
- If the duplicates are not directly connected, they may both form adjacencies with the routers between them. Each flooded Router LSA appears to come from one router, so the two overwrite each other. Routes disappear and reappear, and the database shows the wrong topology.
- The router logs may report a duplicate router ID message.
The fix is to give each router a unique RID and restart the OSPF process on the one you changed. The duplicate is easy to find if you keep a simple table of routers and RIDs.
Design guidance
- Always configure the RID explicitly, before enabling OSPF on interfaces.
- Keep a list of every RID in the domain, and check new routers against it.
- Use a numbering scheme that is easy to read, such as the loopback address.
- Do not tie the RID to a physical interface address, because renumbering that link should not change the router's identity.
- Remember that the RID needs to be unique across the whole OSPF domain, not just within one area.
Summary table
| Method | Source of RID | Stability | Recommended |
|---|---|---|---|
| Explicit `router-id` | Configured value | Stable until changed | Yes |
| Highest loopback IP | Loopback interface | Stable unless loopbacks change | Only as a fallback |
| Highest active interface IP | Physical interface | Changes with link or address changes | No |
Exercise
R1 has no router-id command. It has loopback0 with 10.255.0.1, loopback1 with 10.255.0.9, GigabitEthernet0/0 with 192.168.50.1 (up), and GigabitEthernet0/1 with 172.16.0.1 (up). Which RID does R1 choose when OSPF starts? Then you add router-id 1.1.1.1 while OSPF is running. What RID is in use immediately afterward, and what must you do to apply the new one?
Show answer
R1 chooses 10.255.0.9, the highest address on an active loopback. Loopbacks are preferred over physical interfaces even though 192.168.50.1 is numerically higher. After you add router-id 1.1.1.1 on a running process, R1 keeps using 10.255.0.9. To apply the new RID you must restart the OSPF process with clear ip ospf process, which resets all adjacencies.
Exercise
Two routers, R2 and R5, are not directly connected, but both use RID 2.2.2.2. Users report that some routes appear and disappear. Explain why this happens and how you would fix it.
Show answer
Each router floods a Router LSA identified by its RID as the advertising router. With the same RID, the two LSAs look like updates to one LSA, so each router's version overwrites the other's and the database flips between two topologies. Routes therefore flap. Fix it by assigning a unique RID to one of the routers with router-id, then restarting its OSPF process so the new RID takes effect.