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
- 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-medis 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.
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.
| Step | Rule |
|---|---|
| 1 | Lowest route preference (170 for BGP unless a policy changes it) |
| 2 | Highest LOCAL_PREF (default 100) |
| 3 | Shortest AS_PATH |
| 4 | Lowest ORIGIN: IGP, then EGP, then incomplete |
| 5 | Lowest MED, compared only between paths from the same neighboring AS by default |
| 6 | EBGP path over IBGP path |
| 7 | Lowest IGP metric to the next hop |
| 8 | Final tie breakers: lowest router ID, shorter cluster list, lowest peer address |
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
| Behavior | EBGP | IBGP |
|---|---|---|
| Peer AS | Different from yours | Same as yours |
| Usual peering address | Directly connected interface | Loopback, reached over the IGP |
| Default TTL | 1 (directly connected only) | 64 |
| AS_PATH on advertisement | Your AS is added | Not changed |
| NEXT_HOP on advertisement | Changed to your address | Not changed |
| LOCAL_PREF | Not sent | Sent and honored |
| Re-advertising learned routes | To EBGP and IBGP peers | Not to other IBGP peers |
| Route preference | 170 | 170 |
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
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.
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
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-medis 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
multihopfor peers that are not directly connected. - IBGP peers use loopbacks plus
local-addressand an IGP. next-hop selffixes 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
multihopchange 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.