BGP · Topic 2 of 5

Route Selection and Next Hop Resolution

JN0-650 study page on how Junos picks the best BGP path, why routes become hidden, and how next hops behave for EBGP, IBGP, next-hop self and multihop.

  • 5 min
In a nutshell
  • Order: resolvable next hop, local preference, AS path length, origin, MED, EBGP over IBGP, IGP metric to next hop, then router ID tie-breakers.
  • Local preference default is 100, higher wins; MED lower wins; origin IGP is best, then EGP, then incomplete.
  • MED is compared only between paths from the same neighboring AS unless always-compare-med is set.

What it is

A router may hear the same prefix from several peers. BGP picks one active path per prefix, using a fixed sequence of tie-breakers. Knowing that sequence lets you predict traffic and explain why a particular path lost.

Before any tie-breaker applies, the route must be usable. A BGP route whose next hop cannot be resolved is marked hidden and does not take part in selection at all.

Routes receivednext hop resolvable?Candidate pathsselection stepsOne active pathinstallForwarding table

How it works

The selection steps

Junos evaluates the candidates in this order, stopping when only one remains. The first matching step wins.

StepPrefer
1Resolvable next hop (unresolved routes are hidden)
2Highest local preference (default 100)
3Shortest AS path
4Lowest origin: IGP, then EGP, then incomplete
5Lowest MED, compared between paths from the same neighboring AS
6EBGP-learned over IBGP-learned
7Lowest IGP metric to the BGP next hop
8Lowest router ID, then shortest cluster list, then lowest peer address

Remember that the route preference of the protocol (BGP is 170) only matters when comparing BGP against other protocols, such as OSPF. The steps above only compare BGP paths with each other.

Exam tip

Read the steps as "local choices first, then path quality, then closeness". Local preference is an inside the AS decision, so it beats AS path length.

MED behavior

By default, Junos compares MED only between paths received from the same neighboring AS. Two paths from different neighbor ASs skip the MED step. The knob path-selection always-compare-med compares MED across all paths.

set protocols bgp path-selection always-compare-med

Other selection knobs live under the same hierarchy, such as external-router-id (use the lowest router ID rather than the oldest path for EBGP ties), as-path-ignore and cisco-non-deterministic.

Next hop behavior

Learned fromNext hop on the received routeWhen advertised on
EBGPThe peer's addressTo IBGP: unchanged unless policy sets next-hop self
IBGPThe original next hopTo IBGP: unchanged; to EBGP: changed to the router's own address

The most common failure follows from this. A router learns an external prefix by EBGP. It sends it by IBGP to a neighbor and the next hop is still the external peer's address. The IBGP neighbor has no route to that address in its IGP and so the route is hidden.

Two fixes exist. Put the external link into the IGP as a passive interface, or have the border router rewrite the next hop:

set policy-options policy-statement NHS term 1 then next-hop self
set protocols bgp group INT export NHS
Watch out

Do not apply a bare next-hop self policy to an EBGP group by accident. Apply it to the IBGP export where it is needed.

On a shared segment, Junos sends EBGP routes with the original third-party next hop when that next hop is on the same subnet as the peer. If both peers are not on that subnet, the sender uses its own address.

Resolving the next hop

The BGP next hop is a recursive address. The router looks it up and resolves it to a directly connected next hop and interface. The router looks in inet.3 first, which holds MPLS LSP routes to egress routers, and then in the unicast table inet.0. This is why BGP traffic follows an LSP when one exists to the next hop.

show route 192.0.2.0/24 detail
show route hidden
show route resolution unresolved

show route hidden lists routes that exist but are not usable. The reason shown, for example an unusable or unresolved protocol next hop, tells you the next hop lookup failed.

BGP routeProtocol next hop 10.255.0.9recursive lookupIGP routeNext hop 10.1.1.2 via interfaceinstallForwarding next hop

Multihop EBGP

EBGP normally requires a peer one hop away. To peer between loopbacks or across a router, configure multihop:

set protocols bgp group EXT multihop ttl 2
set protocols bgp group EXT local-address 10.255.0.1

The routers also need a route to each other's loopback. With multihop, the BGP next hop would normally still be the peer's address; add no-nexthop-change inside multihop when you must preserve the original next hop.

Common mistakes

Putting AS path before local preference. Local preference is evaluated first.

Assuming MED is always compared. By default only among paths from the same neighboring AS.

Ignoring hidden routes. A hidden route never takes part in selection, no matter how good its attributes.

Forgetting to reach the EBGP next hop inside the AS. IBGP does not change it for you.

Using EBGP between loopbacks without multihop. The TTL expires and the session never forms.

What to remember for the exam

  • Order: resolvable next hop, local preference, AS path length, origin, MED, EBGP over IBGP, IGP metric to next hop, then router ID tie-breakers.
  • Local preference default is 100, higher wins; MED lower wins; origin IGP is best, then EGP, then incomplete.
  • MED is compared only between paths from the same neighboring AS unless always-compare-med is set.
  • IBGP does not change the next hop; use next-hop self on the border router or put the link in the IGP.
  • Unresolved next hop means a hidden route; check with show route hidden.
  • multihop raises the EBGP TTL; the peers must reach each other's loopbacks.

Check yourself

  • Which is evaluated first, AS path length or local preference?

    Local preference; a higher value wins before AS path length is compared.

  • An IBGP route is hidden with an unresolved next hop. What is the likely cause?

    The EBGP next hop was passed unchanged and the IGP has no route to it; fix with next-hop self or an IGP route.

  • When does Junos compare MED between two paths?

    By default only when both come from the same neighboring AS, or always if always-compare-med is set.

Topic 2 of 5 in BGP

Test yourself on BGP

The full Juniper JNCIP-ENT JN0-650 question bank has 858 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.