BGP Router-ID from Zero to CCIE: The Complete Guide

What the Router-ID Is and How Cisco Chooses It

Every BGP speaker needs an identity that its neighbours can recognise. An IP address on the link is not enough, because a router can have many links, many addresses and many sessions, and some of those sessions are built between loopbacks rather than physical interfaces. BGP solves this with a single 32-bit number called the BGP Identifier. Cisco calls it the Router-ID, and you will see both names used for the same thing.

The Router-ID is written in dotted-decimal notation, so it looks exactly like an IPv4 address, for example 1.1.1.1. That is only a display format. The value does not need to be reachable, it does not need to exist on any interface, and nothing ever sends a packet to it. It is a label. A Router-ID of 1.1.1.1 on a router that has no 1.1.1.1 address anywhere is perfectly valid.

The Router-ID travels in the OPEN message, the first BGP message each side sends after the TCP session on port 179 comes up. The OPEN carries the BGP version, the local AS number, the proposed hold time, the BGP Identifier and the optional capabilities. Each side reads the other's identifier, checks it, and remembers it for the lifetime of the session.

Because the identifier matters so much, the next question is where it comes from when nobody configures it. On Cisco IOS and IOS XE the selection follows a strict order, and the first rule that produces a value wins.

The first rule is manual configuration. If you enter "#bgp router-id" under the BGP process, that value is used regardless of what interfaces exist. The second rule applies when nothing is configured: the router takes the highest IPv4 address configured on a loopback interface that is up. The third rule applies when there is no usable loopback: the router takes the highest IPv4 address on an up physical interface.

"Highest" is a numeric comparison of the 32-bit values, so 192.168.1.1 beats 10.255.255.255, and 10.0.0.10 beats 10.0.0.9. Loopbacks always beat physical interfaces, even if the physical address is numerically higher. A router with Loopback0 at 1.1.1.1 and GigabitEthernet0/0 at 203.0.113.1 picks 1.1.1.1.

Here is a router with no manual Router-ID, two loopbacks and two physical interfaces.

R1(config)#interface Loopback0
R1(config-if)#ip address 1.1.1.1 255.255.255.255
R1(config-if)#interface Loopback1
R1(config-if)#ip address 11.11.11.11 255.255.255.255
R1(config-if)#interface GigabitEthernet0/0
R1(config-if)#ip address 10.1.12.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#interface GigabitEthernet0/1
R1(config-if)#ip address 172.16.13.1 255.255.255.0
R1(config-if)#no shutdown
R1(config-if)#router bgp 65001
R1(config-router)#neighbor 10.1.12.2 remote-as 65002

The highest loopback address is 11.11.11.11, so that becomes the Router-ID, even though Loopback0 is the one you might expect.

R1#show ip bgp summary
BGP router identifier 11.11.11.11, local AS number 65001
BGP table version is 1, main routing table version 1

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.1.12.2       4        65002       5       5        1    0    0 00:02:14        0

This is the first lesson most engineers learn the hard way. The automatic choice is predictable, but it is rarely the value you would have chosen yourself.

Configuring It and the Rules It Must Follow

The fix is to configure the value explicitly. Best practice is to use the address of the loopback you peer from, so the Router-ID, the update source and the address in your documentation are all the same number.

R1(config)#router bgp 65001
R1(config-router)#bgp router-id 1.1.1.1
R1#show ip bgp summary
BGP router identifier 1.1.1.1, local AS number 65001
BGP table version is 1, main routing table version 1

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.1.12.2       4        65002       3       3        1    0    0 00:00:09        0

Look at the Up/Down column. The session was up for over two minutes before the change and for nine seconds after it. Changing the Router-ID resets every BGP session on the router, because the identifier was agreed in the OPEN exchange and the only way to announce a new one is to open the session again. On a lab router this costs nothing. On a production edge router carrying a full table it means a full reconvergence, so the Router-ID belongs in the day-one configuration, not in a change made later.

The neighbour also learns the identifier. From the other side you can see it in the neighbour detail.

R2#show ip bgp neighbors 10.1.12.1 | include BGP neighbor|remote router ID
BGP neighbor is 10.1.12.1,  remote AS 65001, external link
  BGP version 4, remote router ID 1.1.1.1

Manual configuration is not only good practice. On some routers it is the only option. Because the Router-ID is a 32-bit value, the automatic selection only looks at IPv4 addresses. A router running pure IPv6 has nothing to choose from, and BGP cannot start.

R5(config)#router bgp 65005
R5(config-router)#neighbor 2001:DB8:56::6 remote-as 65006
%BGP-3-NORTRID: BGP could not pick a router-id. Please configure manually.

The solution is the same command. The value is still written in dotted-decimal, even in an IPv6-only network.

R5(config-router)#bgp router-id 5.5.5.5
R5#show bgp ipv6 unicast summary
BGP router identifier 5.5.5.5, local AS number 65005
BGP table version is 1, main routing table version 1

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
2001:DB8:56::6  4        65006       4       4        1    0    0 00:00:31        0

In IPv6-only designs, many operators generate the Router-ID from a site and router number, because there is no IPv4 loopback to copy it from.

Whatever value you choose, it has to respect one rule about uniqueness. The original BGP specification required the identifier to be unique across the whole Internet in practice, because it was derived from an IPv4 address the router owned. RFC 6286 relaxed this. It only has to be unique inside an AS, and an eBGP peer is allowed to have the same identifier as the local router. Whether your Cisco release accepts an eBGP peer with the same identifier depends on the release, so test it before relying on it.

Inside an AS there is no relaxation. Two iBGP neighbours with the same Router-ID cannot form a session, because each side sees its own identifier in the peer's OPEN and rejects it with a Bad BGP Identifier error. The more dangerous case is two routers in the same AS with the same Router-ID that do not peer directly, for example two route reflector clients. The sessions come up, but routes disappear. That case has its own post in this series.

Where the Router-ID Matters at CCIE Level

Most engineers think of the Router-ID only as a session label, but it is also a tie-breaker in the BGP best path algorithm. When two paths are equal in weight, local preference, local origination, AS_PATH length, origin code, MED, external versus internal, and IGP cost to the next hop, Cisco reaches the final steps.

For two eBGP paths, Cisco prefers the path that was received first, the oldest one, because changing the best path every time a new equal path arrives causes route flapping. The command "#bgp bestpath compare-routerid" disables that step, so the decision becomes deterministic.

The next step is the lowest Router-ID of the advertising router. After that comes the shortest CLUSTER_LIST, and finally the lowest neighbour address.

R1#show ip bgp 192.0.2.0
BGP routing table entry for 192.0.2.0/24, version 7
Paths: (2 available, best #2, table default)
  Advertised to update-groups:
     1
  Refresh Epoch 1
  65003 65100
    10.1.13.3 from 10.1.13.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 100, valid, external
  Refresh Epoch 1
  65002 65100
    10.1.12.2 from 10.1.12.2 (2.2.2.2)
      Origin IGP, metric 0, localpref 100, valid, external, best

The value in brackets after each "from" address is the Router-ID of the router that sent the path. With "#bgp bestpath compare-routerid" configured, 2.2.2.2 wins over 3.3.3.3 here.

The tie-breaker role becomes more interesting once route reflectors are involved. Route reflection breaks one of BGP's basic assumptions: that iBGP routes come straight from the router that learned them. A route reflector passes a client's route to other clients, so the receiving router no longer peers with the originator. BGP fixes this with two attributes. The CLUSTER_LIST records the cluster IDs the route passed through, and the ORIGINATOR_ID records the Router-ID of the router that first injected the route into the AS.

The ORIGINATOR_ID does two jobs. It is a loop check: a router that receives a route carrying its own Router-ID as the ORIGINATOR_ID drops it. It is also a best path input: on a reflected route, Cisco uses the ORIGINATOR_ID in place of the advertising router's Router-ID at the lowest Router-ID step.

R4#show ip bgp 198.51.100.0
BGP routing table entry for 198.51.100.0/24, version 9
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Refresh Epoch 1
  65100
    2.2.2.2 (metric 3) from 14.14.14.14 (14.14.14.14)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      Originator: 2.2.2.2, Cluster list: 14.14.14.14

Here the route reflector is 14.14.14.14, but the route originated at 2.2.2.2, and R4 uses 2.2.2.2 when it compares this path with others.

One more place the Router-ID appears is inside VRFs. On a PE router running MPLS L3VPN, each VRF can run its own BGP sessions to customer routers. By default, every VRF uses the global Router-ID. That causes a problem when two VRFs on the same router peer with each other, for example through a firewall or a back-to-back link between them. Both ends present the same identifier, and the session cannot come up. IOS XE lets you assign a Router-ID per VRF, either manually or automatically from an interface in that VRF.

PE1(config)#router bgp 65000
PE1(config-router)#bgp router-id vrf auto-assign
PE1(config-router)#address-family ipv4 vrf CUSTOMER_B
PE1(config-router-af)#bgp router-id 10.200.0.1

The global command lets each VRF pick its own Router-ID from its own interfaces. The command inside the address family overrides that for one VRF.

PE1#show ip bgp vpnv4 vrf CUSTOMER_B summary
BGP router identifier 10.200.0.1, local AS number 65000
BGP table version is 4, main routing table version 4

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.200.12.2     4        65200      15      14        4    0    0 00:10:02        2

Putting all of this together gives a short checklist. The BGP Router-ID is a 32-bit label exchanged in the OPEN message. Cisco IOS and IOS XE choose it in this order: the configured value, the highest up loopback address, then the highest up physical address. It must be unique inside an AS, and it must be configured by hand on routers without IPv4 addresses. It breaks ties in best path selection, it becomes the ORIGINATOR_ID on reflected routes, and it can be set per VRF on a PE.

The rule for every design is simple. Configure "#bgp router-id" explicitly on day one, match it to the loopback you peer from, keep it unique across the AS, and never change it during the day without a maintenance window.