Examine BGP Routes and Route Selection
Purpose
You can examine the BGP path selection process to determine the single, active path when BGP receives multiple routes to the same destination prefix.
Figure 1: BGP Network Topology

The network in Figure 1 shows that R1 and R5 announce the same aggregate routes to R2 and R4, which results in R2 and R4 receiving two routes to the same destination prefix. The route selection process on R2 and R4 determines which of the two BGP routes received is active and advertised to the other internal routers (R3 and R6).
Before the router installs a BGP route, it must make sure that the BGP next-hop attribute is reachable. If the BGP next hop cannot be resolved, the route is not installed. When a BGP route is installed in the routing table, it must go through a path selection process if multiple routes exist to the same destination prefix. The BGP path selection process proceeds in the following order:
- Route preference in the routing table is compared. For example, if an OSPF and a BGP route exist for a particular destination, the OSPF route is selected as the active route because the OSPF route has a default preference of 110, while the BGP route has a default preference of 170.
- Routes are compared for local preference. The route with the highest local preference is preferred. For example, see Examine the Local Preference Selection.
- The AS path attribute is evaluated. The shorter AS path is preferred.
- The origin code is evaluated. The lowest origin code is preferred ( I (IGP) < E (EGP) < ? (Incomplete)).
- The MED value is evaluated. By default, if any of the routes are advertised from the same neighboring AS, the lowest MED value is preferred. The absence of a MED value is interpreted as a MED of 0. For an example, see Examine the Multiple Exit Discriminator Route Selection.
- The route is evaluated as to whether it is learned through EBGP or IBGP. EBGP learned routes are preferred to IBGP learned routes. For an example, see Examine the EBGP over IBGP Selection
- If the route is learned from IBGP, the route with the
lowest IGP cost is preferred. For an example, see Examine the IGP Cost Selection. The physical next hop to the IBGP peer is installed according to
the following three rules:
- After BGP examines the inet.0 and inet.3 routing tables, the physical next hop of the route with the lowest preference is used.
- If the preference values in the inet.0 and the inet.3 routing tables are a tie, the physical next hop of the route in the inet.3 routing table is used.
- When a preference tie exists in the same routing table, the physical next hop of the route with more paths is installed.
- The route reflection cluster list attribute is evaluated. The shortest length cluster list is preferred. Routes without a cluster list are considered to have a cluster list length of 0.
- The router ID is evaluated. The route from the peer with the lowest router ID is preferred (usually the loopback address).
- The peer address value is examined. The peer with the lowest peer IP address is preferred.
To determine the single, active path when BGP receives multiple routes to the same destination prefix, enter the following Junos OS CLI operational mode command:
The following steps illustrate the inactive reason displayed when BGP receives multiple routes to the same destination prefix and one route is selected as the single, active path:
- Examine the Local Preference Selection
- Examine the Multiple Exit Discriminator Route Selection
- Examine the EBGP over IBGP Selection
- Examine the IGP Cost Selection
Examine the Local Preference Selection
Purpose
To examine a route to determine if local preference is the selection criteria for the single, active path.
Action
To examine a route to determine if local preference is the selection criteria for the single, active path, enter the following Junos OS CLI operational mode command:
Sample Output
user@R4> show route 100.100.1.0 detail
inet.0: 20 destinations, 24 routes (20 active, 0 holddown, 0 hidden) 100.100.1.0/24 (2 entries, 1 announced) *BGP Preference: 170/-201 Source: 10.0.0.2 Next hop: 10.1.24.1 via so-0/0/3.0, selected Protocol next hop: 10.0.0.2 Indirect next hop: 8644000 277 State: <Active Int Ext> Local AS: 65002 Peer AS: 65002 Age: 2:22:34 Metric: 5 Metric2: 10 Task: BGP_65002.10.0.0.2+179 Announcement bits (3): 0-KRT 3-BGP.0.0.0.0+179 4-Resolve inet.0 AS path: 65001 I Localpref: 200 Router ID: 10.0.0.2 BGP Preference: 170/-101 Source: 10.1.45.2 Next hop: 10.1.45.2 via so-0/0/2.0, selected State: <Ext> Inactive reason: Local Preference Local AS: 65002 Peer AS: 65001 Age: 2w0d 1:28:31 Metric: 10 Task: BGP_65001.10.1.45.2+179 AS path: 65001 I Localpref: 100 Router ID: 10.0.0.5
Meaning
The sample output shows that R4 received two instances of the 100.100.1.0 route: one from 10.0.0.2 (R2) and one from 10.1.45.2 (R5). R4 selected the path from R2 as its active path, as indicated by the asterisk (*). The selection is based on the local preference value contained in the Localpref field. The path with the highest local preference is preferred. In the example, the path with the higher local preference value is the path from R2, 200.
The reason that the route from R5 is not selected is in the Inactive reason field, in this case, Local Preference.
Note that the two paths are from the same neighboring network: AS 65001.
Examine the Multiple Exit Discriminator Route Selection
Purpose
To examine a route to determine if the MED is the selection criteria for the single, active path.
Action
To examine a route to determine if the MED is the selection criteria for the single, active path, enter the following Junos OS CLI operational mode command:
Sample Output
user@R4> show route 100.100.2.0 detail
inet.0: 20 destinations, 24 routes (20 active, 0 holddown, 0 hidden) 100.100.2.0/24 (2 entries, 1 announced) *BGP Preference: 170/-101 Source: 10.0.0.2 Next hop: 10.1.24.1 via so-0/0/3.0, selected Protocol next hop: 10.0.0.2 Indirect next hop: 8644000 277 State: <Active Int Ext> Local AS: 65002 Peer AS: 65002 Age: 2:32:01 Metric: 5 Metric2: 10 Task: BGP_65002.10.0.0.2+179 Announcement bits (3): 0-KRT 3-BGP.0.0.0.0+179 4-Resolve inet.0 AS path: 65001 I Localpref: 100 Router ID: 10.0.0.2 BGP Preference: 170/-101 Source: 10.1.45.2 Next hop: 10.1.45.2 via so-0/0/2.0, selected State: <NotBest Ext> Inactive reason: Not Best in its group Local AS: 65002 Peer AS: 65001 Age: 2w0d 1:37:58 Metric: 10 Task: BGP_65001.10.1.45.2+179 AS path: 65001 I Localpref: 100 Router ID: 10.0.0.5
Meaning
The sample output shows that R4 received two instances of the 100.100.2.0 route: one from 10.0.0.2 (R2), and one from 10.1.45.2 (R5). R4 selected the path from R2 as its active route, as indicated by the asterisk (*). The selection is based on the MED value contained in the Metric: field. The path with the lowest MED value is preferred. In the example, the path with the lowest MED value (5) is the path from R2. Note that the two paths are from the same neighboring network: AS 65001.
The reason that the inactive path is not selected is displayed in the Inactive reason: field, in this case, Not Best in its group. The wording is used because the Junos OS uses the process of deterministic MED selection, by default.
Examine the EBGP over IBGP Selection
Purpose
To examine a route to determine if EBGP is selected over IBGP as the selection criteria for the single, active path.
Action
To examine a route to determine if EBGP is selected over IBGP as the selection criteria for the single, active path, enter the following Junos OS CLI operational mode command:
Sample Output
user@R4> show route 100.100.3.0 detail
inet.0: 20 destinations, 24 routes (20 active, 0 holddown, 0 hidden) 100.100.3.0/24 (2 entries, 1 announced) *BGP Preference: 170/-101 Source: 10.1.45.2 Next hop: 10.1.45.2 via so-0/0/2.0, selected State: <Active Ext> Local AS: 65002 Peer AS: 65001 Age: 5d 0:31:25 Task: BGP_65001.10.1.45.2+179 Announcement bits (3): 0-KRT 3-BGP.0.0.0.0+179 4-Resolve inet.0 AS path: 65001 I Localpref: 100 Router ID: 10.0.0.5 BGP Preference: 170/-101 Source: 10.0.0.2 Next hop: 10.1.24.1 via so-0/0/3.0, selected Protocol next hop: 10.0.0.2 Indirect next hop: 8644000 277 State: <NotBest Int Ext> Inactive reason: Interior > Exterior > Exterior via Interior Local AS: 65002 Peer AS: 65002 Age: 2:48:18 Metric2: 10 Task: BGP_65002.10.0.0.2+179 AS path: 65001 I Localpref: 100 Router ID: 10.0.0.2
Meaning
The sample output shows that R4 received two instances of the 100.100.3.0 route: one from 10.1.45.2 (R5) and one from 10.0.0.2 (R2). R4 selected the path from R5 as its active path, as indicated by the asterisk (*). The selection is based on a preference for routes learned from an EBGP peer over routes learned from an IBGP. R5 is an EBGP peer.
You can determine if a path is received from an EBGP or IBGP peer by examining the Local As and Peer As fields. For example, the route from R5 shows the local AS is 65002 and the peer AS is 65001, indicating that the route is received from an EBGP peer. The route from R2 shows that both the local and peer AS is 65002, indicating that it is received from an IBGP peer.
The reason that the inactive path is not selected is displayed in the Inactive reason field, in this case, Interior > Exterior > Exterior via Interior. The wording of this reason shows the order of preferences applied when the same route is received from two routers. The route received from a strictly internal source (IGP) is preferred first, the route received from an external source (EBGP) is preferred next, and any route which comes from an external source and is received internally (IBGP) is preferred last.
Examine the IGP Cost Selection
Purpose
To examine a route to determine if EBGP is selected over IBGP as the selection criteria for the single, active path.
Action
To examine a route to determine if EBGP is selected over IBGP as the selection criteria for the single, active path, enter the following Junos OS CLI operational mode command:
Sample Output
user@R6> show route 100.100.4.0 detail
inet.0: 18 destinations, 20 routes (18 active, 0 holddown, 0 hidden) 100.100.4.0/24 (2 entries, 1 announced) *BGP Preference: 170/-101 Source: 10.0.0.4 Next hop: 10.1.46.1 via so-0/0/1.0, selected Protocol next hop: 10.0.0.4 Indirect next hop: 864c000 276 State: <Active Int Ext> Local AS: 65002 Peer AS: 65002 Age: 2:16:11 Metric2: 10 Task: BGP_65002.10.0.0.4+4120 Announcement bits (2): 0-KRT 4-Resolve inet.0 AS path: 65001 I Localpref: 100 Router ID: 10.0.0.4 BGP Preference: 170/-101 Source: 10.0.0.2 Next hop: 10.1.46.1 via so-0/0/1.0, selected Next hop: 10.1.36.1 via so-0/0/3.0 Protocol next hop: 10.0.0.2 Indirect next hop: 864c0b0 278 State: <NotBest Int Ext> Inactive reason: IGP metric Local AS: 65002 Peer AS: 65002 Age: 2:16:03 Metric2: 20 Task: BGP_65002.10.0.0.2+179 AS path: 65001 I Localpref: 100 Router ID: 10.0.0.2
Meaning
The sample output shows that R6 received two instances of the 100.100.4.0 route: one from 10.0.0.4 (R4) and one from 10.0.0.2 (R2). R6 selected the path from R4 as its active route, as indicated by the asterisk (*). The selection is based on the IGP metric, displayed in the Metric2 field. The route with the lowest IGP metric is preferred. In the example, the path with the lowest IGP metric value is the path from R4, with an IGP metric value of 10, while the path from R2 has an IGP metric of 20. Note that the two paths are from the same neighboring network: AS 65001.
The reason that the inactive path was not selected is displayed in the Inactive reason field, in this case, IGP metric.