← Common fixesTroubleshooting

BGP not choosing the preferred path

When BGP keeps preferring the 'wrong' path, it isn't broken; it's following the best-path algorithm, and you haven't given it the attribute that decides things your way. The fix is to set the right knob: local-preference for the path your router chooses outbound, AS-path prepending to shape what the outside world chooses inbound.

What it means

BGP best-path is an ordered list of tiebreakers: weight (Cisco, local), then local-preference (AS-wide), then locally originated, then shortest AS-path, origin, MED, eBGP over iBGP, lowest IGP metric, and finally oldest route / lowest router-id. If you don't set an earlier attribute, selection falls through to a tiebreaker you don't control, which is why the choice looks arbitrary.

Most common causes

  • No local-preference set. Without local-pref, outbound selection falls through to AS-path length and beyond. Set a higher local-pref inbound from the upstream you want as primary.
  • Trying to control inbound with a local knob. Local-preference and weight only affect your own outbound decision. They can't make the outside world prefer a path to you. That needs AS-path prepending or MED.
  • Equal AS-path lengths. If both upstreams advertise the destination with the same AS-path length and nothing earlier breaks the tie, selection drops to MED / router-id and looks random.

How to fix it

  1. Decide your primary upstream for the destination.
  2. Outbound: set a higher local-preference on routes learned from the primary (route-map inbound).
  3. Inbound: prepend your AS on advertisements toward the backup upstream so your prefix looks longer that way.
  4. Confirm with `show ip bgp <prefix>` that the chosen next-hop is the primary, and the prepend appears on the backup advertisement.