Give me the full BGP best path selection order on a Cisco router.
Show the answer
Say this first
First the next hop must be reachable. Then: 1 highest weight, 2 highest LOCAL_PREF, 3 locally originated, 4 shortest AS_PATH, 5 lowest origin (IGP before EGP before incomplete), 6 lowest MED, 7 eBGP over iBGP, 8 lowest IGP metric to the next hop, 9 multipath check, 10 oldest eBGP path, 11 lowest router ID, 12 shortest cluster list, 13 lowest neighbor address. The first step where paths differ decides. A common memory aid for the first part is "N WLLA OMNI": Next hop, Weight, Local pref, Locally originated, AS path, Origin, MED, Neighbor type, IGP metric.
Go deeper
| Step | Compare | Prefer | Notes |
|---|---|---|---|
| 0 | Next hop reachable | Reachable | Also: not looped, passed inbound policy |
| 1 | Weight | Highest | Cisco only, local to the router; 0 learned, 32768 local |
| 2 | LOCAL_PREF | Highest | Default 100; shared across the AS |
| 3 | Locally originated | Local | network or redistribution, then aggregates |
| 4 | AS_PATH length | Shortest | An AS_SET counts as 1; confederation segments do not count |
| 5 | ORIGIN | i, then e, then ? | |
| 6 | MED | Lowest | Only between paths from the same neighbor AS by default |
| 7 | Peer type | eBGP | Then confederation eBGP, then iBGP |
| 8 | IGP metric to NEXT_HOP | Lowest | Hot potato routing |
| 9 | Multipath | With maximum-paths, equal paths are installed; one is still marked best | |
| 10 | Path age | Oldest eBGP | Stability; skipped with bgp bestpath compare-routerid |
| 11 | Router ID | Lowest | ORIGINATOR_ID for reflected routes |
| 12 | CLUSTER_LIST length | Shortest | |
| 13 | Neighbor address | Lowest | The peer's IP address |
How I explain it in an interview
Group the steps. Weight and local preference are the knobs you control. Locally originated, AS path, origin and MED describe the route itself. eBGP versus iBGP and IGP metric describe where it enters your network. The rest are tie breakers chosen for stability and determinism.
Proving it on a device
show ip bgp <prefix> lists every path and says best #2. IOS-XR goes further with
show bgp <prefix> bestpath-compare, which explains why each path lost.
Junos
No weight. Junos first compares protocol preference (BGP is 170), then follows broadly the same order: local preference, AS path length, origin, MED, eBGP over iBGP, IGP cost, then tie breakers.
They will ask next
Why prefer the oldest eBGP path over the lowest router ID?
To avoid churn. A new path that ties on everything else does not replace a working best path, which keeps traffic and downstream updates stable.
When does deterministic-med matter?
When paths for one prefix come from several neighbor ASes. Without it, IOS compares paths pairwise in the order received, so the winner can depend on arrival order.
bgp deterministic-medgroups paths by neighbor AS first.
Traps
- Saying lowest local preference wins, or placing MED before AS path length.
- Forgetting that weight only affects the router it is set on.