BGP · Topic 2 of 4

BGP Path Selection, IBGP and EBGP

Learn the Junos BGP path selection order, local preference, AS path, MED and tie breakers, and how IBGP and EBGP differ in TTL, next hop and advertising.

  • 5 min
  • Includes a diagram
In a nutshell
  • Next hop reachable first, then lowest route preference, highest local preference, shortest AS path, lowest origin, lowest MED.
  • After MED: EBGP over IBGP, then lowest IGP metric, then lowest router ID.
  • Default LOCAL_PREF is 100; MED compares within one neighbor AS unless always-compare-med is set.

What it is

When BGP receives several paths to the same prefix, it keeps all of them but chooses one active path. The choice follows a fixed list of rules, checked in order. The first rule that separates the paths decides.

EBGP runs between routers in different autonomous systems. IBGP runs between routers in the same AS. They behave differently, and the exam asks about the differences often.

Several pathssame prefixnext hop reachableLocal preferencehigher winsAS pathshorter winsOriginlower winsMEDlower winsEBGP over IBGPIGP metriclower winsRouter IDlower wins

How it works

Selection order on Junos

Before comparing attributes, the next hop must be reachable. A path with an unresolvable next hop is not usable and appears as a hidden route.

Then the main rules apply in this order.

StepRule
1Lowest route preference (170 for BGP unless a policy changes it)
2Highest LOCAL_PREF (default 100)
3Shortest AS_PATH
4Lowest ORIGIN: IGP, then EGP, then incomplete
5Lowest MED, compared only between paths from the same neighboring AS by default
6EBGP path over IBGP path
7Lowest IGP metric to the next hop
8Final tie breakers: lowest router ID, shorter cluster list, lowest peer address
Exam tip

Local preference is checked before AS path length. A longer AS path with LOCAL_PREF 200 beats a shorter path with the default 100.

MED rules

Junos compares MED only between routes learned from the same neighboring AS. A missing MED is treated as 0, the best value. To compare MED across different neighbor ASes, configure path-selection always-compare-med under [edit protocols bgp].

EBGP compared with IBGP

BehaviorEBGPIBGP
Peer ASDifferent from yoursSame as yours
Usual peering addressDirectly connected interfaceLoopback, reached over the IGP
Default TTL1 (directly connected only)64
AS_PATH on advertisementYour AS is addedNot changed
NEXT_HOP on advertisementChanged to your addressNot changed
LOCAL_PREFNot sentSent and honored
Re-advertising learned routesTo EBGP and IBGP peersNot to other IBGP peers
Route preference170170

The key IBGP rule is split horizon: a route learned from an IBGP peer is not passed to another IBGP peer. This prevents loops, because the AS path does not change inside the AS. As a result, IBGP needs a full mesh of peers, or a route reflector or confederation to scale. Routes learned from EBGP are passed to IBGP peers.

IBGP and the next hop

An EBGP peer at 192.0.2.2 in AS 65001 sends a route to the edge router in AS 65000. Over IBGP the core router receives next hop 192.0.2.2, which is hidden if the IGP cannot reach it; with a next-hop self export policy the next hop becomes the edge router. Because IBGP leaves the next hop unchanged, an internal router receives a route whose next hop is the external peer's address. If the IGP does not know that address, the route is hidden and unusable.

EBGP peer192 0 2 2route, next hop unchangedEdge routerIBGP, next hop unchangedCore routercannot reach 192 0 2 2

Two fixes are common. Advertise the external link into the IGP as a passive interface, or have the edge router rewrite the next hop with an export policy using next-hop self.

policy-options {
    policy-statement NEXT-HOP-SELF {
        term 1 {
            from protocol bgp;
            then {
                next-hop self;
            }
        }
    }
}
protocols {
    bgp {
        group IBGP {
            type internal;
            export NEXT-HOP-SELF;
        }
    }
}

IBGP peering on loopbacks

IBGP sessions normally use loopback addresses so that the session survives a single link failure. This needs an IGP that can reach each loopback, plus local-address on the group so that TCP uses the loopback as its source. Without it, the router sends packets from the exit interface address, and the neighbor does not accept them as coming from the configured peer.

EBGP between loopbacks

An EBGP session on loopbacks needs two more things: a route to the peer's loopback, and multihop so the TTL is raised above 1.

user@router# set protocols bgp group EXT type external
user@router# set protocols bgp group EXT multihop ttl 2
user@router# set protocols bgp group EXT local-address 10.255.0.1
Watch out

Without multihop, an EBGP packet to a peer that is not directly connected carries TTL 1 and is dropped on the way. The session never comes up.

Common mistakes

Forgetting the IGP. IBGP depends on an IGP for next hop and peer reachability. BGP does not replace it.

Missing IBGP routes in a partial mesh. If router A peers with B and B peers with C, routes from A do not reach C through B, because of split horizon.

Comparing MED across neighbor ASes. By default that comparison is skipped, so a lower MED from a different neighbor AS does not win.

Expecting local preference to cross an AS boundary. EBGP does not carry LOCAL_PREF.

What to remember for the exam

  • Next hop reachable first, then lowest route preference, highest local preference, shortest AS path, lowest origin, lowest MED.
  • After MED: EBGP over IBGP, then lowest IGP metric, then lowest router ID.
  • Default LOCAL_PREF is 100; MED compares within one neighbor AS unless always-compare-med is set.
  • EBGP changes the AS path and next hop; IBGP changes neither.
  • IBGP split horizon requires a full mesh, route reflection or confederation.
  • EBGP default TTL is 1; use multihop for peers that are not directly connected.
  • IBGP peers use loopbacks plus local-address and an IGP.
  • next-hop self fixes unreachable external next hops inside the AS.

Check yourself

  • Two paths to one prefix have LOCAL_PREF 100 and 200. The first has a shorter AS path. Which is chosen?

    The path with LOCAL_PREF 200, because local preference is checked before AS path length.

  • Why does router C not learn a prefix that its IBGP neighbor B learned from IBGP peer A?

    IBGP split horizon: a route learned from an IBGP peer is not advertised to other IBGP peers.

  • What does multihop change for an EBGP session?

    It raises the TTL of BGP packets so a session can form with a peer that is not directly connected, such as one on a loopback.

Topic 2 of 4 in BGP

Test yourself on BGP

The full Juniper JNCIS-ENT JN0-352 question bank has 846 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.