Lesson 5 of 9 · 24m
BGP Attributes and the Best-Path Decision
BGP path selection is deterministic but unintuitive; knowing the ordered effect of local preference, AS path, origin, MED, eBGP-over-iBGP, and IGP cost prevents accidental traffic engineering.
BGP is not shortest-path routing. It is policy-driven path selection. Each router compares the routes it has received and picks one best path per prefix according to a mostly deterministic decision process. Operators who memorize one acronym but not the operational meaning create weird traffic shifts and then blame BGP for being random.
The decision order that matters
Vendor details vary, but the practical sequence is close to:
1. highest weight/local administrative preference (vendor-local)
2. highest local preference
3. locally originated
4. shortest AS path
5. lowest origin type (IGP < EGP < incomplete)
6. lowest MED, under constrained comparison rules
7. prefer eBGP over iBGP
8. lowest IGP cost to next hop
9. tie-breakers such as oldest route or lowest router IDThe important part is not reciting it. The important part is recognizing which attributes survive import and export and which ones influence only one box.
LOCAL_PREF is your big steering wheel
Local preference is not transitive across AS boundaries. It is powerful inside your AS:
route-map PREFER-PRIMARY permit 10
match community 64500:100
set local-preference 200A route with local-preference 200 beats a shorter AS path at 100. That surprises newcomers constantly. If traffic insists on using the backup provider despite the primary having a shorter path, check import policy before touching AS-path prepending.
AS path is distance plus safety
AS path length is a coarse distance signal, but it is also loop prevention. A router rejects a route containing its own AS. Prepending adds your AS multiple times to make a path less attractive:
set as-path prepend 64500 64500Prepending is imprecise. Some networks ignore path length because local policy or peering economics dominate it. Excessive prepends can also make routes look suspicious and can interact badly with strict filtering.
MED is a hint, not a command
MED can tell a neighboring AS which entrance you prefer when multiple connections exist. Many providers overwrite or ignore it. Also, MED comparison rules depend on whether paths came from the same neighboring AS unless always-compare-med is enabled — often a bad idea.
Communities are policy metadata
BGP communities carry meaning: customer versus peer, region received, do-not-export, prepend instructions. Standard communities look like 64500:120; large communities use three 32-bit fields such as 64500:1:120. Maintain a written registry. A community is worthless if nobody knows what action it triggers.
Field notes
- BGP chooses one best path by default; multipath must be explicitly configured and is constrained.
- The best path on a route reflector may not be the best path for every client in a non-uniform topology.
show bgp 203.0.113.0/24usually reveals why a route won — read the attribute comparison rather than guessing.- Deterministic MED and consistent policy matter; non-deterministic comparison can produce route oscillation.
- Attribute changes are traffic engineering. Treat even a one-line
set local-preferenceas a production change.
Was this lesson helpful?