BGP · Topic 2 of 4
BGP Attributes and Route Selection
Learn BGP path attributes and the Junos route selection order for JNCIS-SP JN0-364: local preference, AS path, origin, MED, EBGP over IBGP and ties.
- 5 min
- Well-known mandatory: ORIGIN, AS_PATH, NEXT_HOP.
- Local preference default 100; higher wins; stays inside the AS.
- MED: lower wins; missing MED counts as 0; compared only from the same neighboring AS unless
always-compare-med.
What it is
Every BGP route carries path attributes, pieces of information about the path such as the AS path, the next hop and the local preference. When a router learns the same prefix from more than one peer, it compares these attributes in a fixed order and installs one active route.
Knowing the attribute categories and the exact Junos OS selection order is the core of this topic. Exam questions often show two routes in show route detail and ask which one wins and why.
How it works
Attribute categories
| Category | Meaning | Examples |
|---|---|---|
| Well-known mandatory | Every router supports it and every UPDATE must carry it | ORIGIN, AS_PATH, NEXT_HOP |
| Well-known discretionary | Every router supports it, but it may be left out | LOCAL_PREF, ATOMIC_AGGREGATE |
| Optional transitive | Not every router supports it; passed on even if not understood | COMMUNITY, AGGREGATOR |
| Optional non-transitive | Not passed on by a router that does not understand it | MULTI_EXIT_DISC (MED), ORIGINATOR_ID, CLUSTER_LIST |
The attributes you use most
| Attribute | Scope | Preferred value | Junos notes |
|---|---|---|---|
| Local preference | Inside your AS only (IBGP) | Higher | Default 100; set with then local-preference in a policy or local-preference in a group |
| AS path | Everywhere | Shorter | Each EBGP hop prepends its AS; a router rejects a route that contains its own AS (loop prevention) |
| Origin | Everywhere | IGP (I) before EGP (E) before incomplete (?) | Static and IGP routes exported into BGP get origin IGP |
| MED | Sent to a neighboring AS | Lower | Set with metric-out or then metric; a missing MED is treated as 0 |
| Next hop | Everywhere | Must be resolvable | EBGP sets it to itself; IBGP leaves it unchanged by default |
| Community | Everywhere (transitive) | Not compared | A tag that policies match on, for example 65000:100 |
Local preference steers traffic leaving your AS: give the preferred exit a higher value. MED is a hint to a neighbor AS about which of your entry points it should use, and it is the weaker tool because the neighbor decides.
The Junos OS route selection order
For each prefix, Junos OS compares candidate paths in this order and stops at the first difference.
- The next hop must be resolvable; otherwise the route is hidden and never used.
- Lowest Junos route preference (BGP default 170 for both IBGP and EBGP).
- Highest local preference.
- If AIGP is enabled, lowest AIGP value.
- Shortest AS path (skipped with
path-selection as-path-ignore). - Lowest origin code: IGP, then EGP, then incomplete.
- Lowest MED, by default compared only between paths from the same neighboring AS.
- Strictly internal paths (IGP and local routes), then EBGP paths before IBGP paths.
- Lowest IGP metric to the BGP next hop.
- If both paths are external, keep the currently active one (unless
path-selection external-router-idis set). - Lowest router ID of the advertising peer (originator ID is used instead when present).
- Shortest cluster list.
- Lowest peer IP address.
- A primary route before a secondary route.
Learn the first half by heart in the order "next hop, preference, local pref, AS path, origin, MED, EBGP, IGP cost". Most exam questions are decided in those steps.
Changing MED behavior
user@router# set protocols bgp path-selection always-compare-med
always-compare-med compares MED between paths from different neighboring ASs. cisco-non-deterministic evaluates paths in the order received, as Cisco IOS does by default. external-router-id makes the router ID decide between two external paths instead of keeping the current active one.
Seeing why a route lost
user@router> show route 203.0.113.0/24 detail
The detail output marks the active path with an asterisk and shows each inactive path with an Inactive reason line naming the step that beat it, for example local preference, AS path length or router ID. Read that line first when a question asks why a path is not active.
Common mistakes
Thinking a lower local preference wins. Higher local preference wins. Lower wins for MED, AS path length, origin, IGP cost and Junos preference.
Comparing MED across different ASs. By default Junos compares MED only between paths whose first AS in the path is the same. Two paths from different provider ASs skip straight past MED unless always-compare-med is configured.
Forgetting the next-hop check. A path whose next hop cannot be resolved is not a candidate at all. It appears with show route hidden, not as an inactive path.
Assuming IBGP and EBGP have different preferences. In Junos both use preference 170. EBGP is preferred later, at the EBGP over IBGP step.
Local preference is sent only to IBGP peers. A value you set in an export policy toward an EBGP peer is not carried into the neighbor AS.
What to remember for the exam
- Well-known mandatory: ORIGIN, AS_PATH, NEXT_HOP.
- Local preference default 100; higher wins; stays inside the AS.
- MED: lower wins; missing MED counts as 0; compared only from the same neighboring AS unless
always-compare-med. - Origin order: IGP, EGP, incomplete; static and IGP routes exported into BGP get origin IGP.
- BGP route preference 170 for IBGP and EBGP.
- Order: next hop, preference, local preference, AS path, origin, MED, EBGP over IBGP, IGP cost, router ID, cluster list, peer address.
show route detailshows the Inactive reason for each losing path.
Check yourself
Route A has local preference 100 and an AS path of two ASs. Route B has local preference 200 and an AS path of four ASs. Which is active?
Route B, because higher local preference is compared before AS path length.
Two paths from different neighboring ASs differ only in MED. Is MED used to choose between them by default?
No, Junos compares MED only between paths from the same neighboring AS unless
always-compare-medis configured.Which attribute category does MED belong to?
Optional non-transitive, so it is not passed beyond the neighboring AS.
Topic 2 of 4 in BGP
Test yourself on BGP
The full Juniper JNCIS-SP JN0-364 question bank has 860 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Juniper. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.