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
In a nutshell
  • 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.

Next hop resolvableyesLowest Junos preferencetieHighest local preferencetieShortest AS pathShortest AS pathtieLowest origintieLowest MEDtieEBGP over IBGPtieLowest IGP cost

How it works

Attribute categories

CategoryMeaningExamples
Well-known mandatoryEvery router supports it and every UPDATE must carry itORIGIN, AS_PATH, NEXT_HOP
Well-known discretionaryEvery router supports it, but it may be left outLOCAL_PREF, ATOMIC_AGGREGATE
Optional transitiveNot every router supports it; passed on even if not understoodCOMMUNITY, AGGREGATOR
Optional non-transitiveNot passed on by a router that does not understand itMULTI_EXIT_DISC (MED), ORIGINATOR_ID, CLUSTER_LIST

The attributes you use most

AttributeScopePreferred valueJunos notes
Local preferenceInside your AS only (IBGP)HigherDefault 100; set with then local-preference in a policy or local-preference in a group
AS pathEverywhereShorterEach EBGP hop prepends its AS; a router rejects a route that contains its own AS (loop prevention)
OriginEverywhereIGP (I) before EGP (E) before incomplete (?)Static and IGP routes exported into BGP get origin IGP
MEDSent to a neighboring ASLowerSet with metric-out or then metric; a missing MED is treated as 0
Next hopEverywhereMust be resolvableEBGP sets it to itself; IBGP leaves it unchanged by default
CommunityEverywhere (transitive)Not comparedA 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.

  1. The next hop must be resolvable; otherwise the route is hidden and never used.
  2. Lowest Junos route preference (BGP default 170 for both IBGP and EBGP).
  3. Highest local preference.
  4. If AIGP is enabled, lowest AIGP value.
  5. Shortest AS path (skipped with path-selection as-path-ignore).
  6. Lowest origin code: IGP, then EGP, then incomplete.
  7. Lowest MED, by default compared only between paths from the same neighboring AS.
  8. Strictly internal paths (IGP and local routes), then EBGP paths before IBGP paths.
  9. Lowest IGP metric to the BGP next hop.
  10. If both paths are external, keep the currently active one (unless path-selection external-router-id is set).
  11. Lowest router ID of the advertising peer (originator ID is used instead when present).
  12. Shortest cluster list.
  13. Lowest peer IP address.
  14. A primary route before a secondary route.
Exam tip

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.

Watch out

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 detail shows 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-med is 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.