BGP · Topic 4 of 4
BGP Options and Routing Policy
Learn common Junos BGP options and how to apply routing policy to BGP for the JNCIS-SP JN0-364: default policies, next-hop self and local preference.
- 6 min
- Default import: accept all BGP routes. Default export: advertise active BGP routes only.
- Most specific level wins for options and policies; neighbor overrides group overrides global.
- Policy chains run left to right; first
acceptorrejectends evaluation; then the default policy.
What it is
Beyond type, peer-as and neighbor, Junos OS BGP has basic options that change how sessions form and what is sent. They can be set globally, in a group or for one neighbor.
Routing policy is how you control which routes BGP accepts (import) and which routes it advertises (export), and how attributes are changed on the way. In a service provider network almost every BGP session has policy applied.
How it works
Common BGP options
| Option | What it does | Example |
|---|---|---|
local-address | Sources the TCP session from this address, usually lo0 | set protocols bgp group IBGP local-address 10.255.0.1 |
multihop | Allows EBGP to a peer that is not directly connected; TTL defaults to 64 when set | set protocols bgp group EXT multihop ttl 2 |
authentication-key | MD5 authentication of the TCP session; must match on both sides | set protocols bgp group EXT authentication-key "secret" |
hold-time | Proposed hold time (default 90 seconds) | set protocols bgp group EXT hold-time 30 |
passive | Do not open TCP; wait for the peer to connect | set protocols bgp group EXT passive |
local-as | Presents a different AS number to the peer, for example during an AS migration | set protocols bgp group EXT local-as 64999 |
remove-private | Strips private AS numbers from the AS path when advertising to EBGP peers | set protocols bgp group EXT remove-private |
as-override | Replaces the customer AS with your own AS in the path, so sites that share one AS accept each other's routes | set protocols bgp group CE as-override |
local-preference | Sets local preference on routes sent to IBGP peers | set protocols bgp group IBGP local-preference 150 |
metric-out | Sets MED on routes sent to this peer | set protocols bgp group EXT metric-out 50 |
damping | Enables route flap damping | set protocols bgp damping |
prefix-limit | Limits the routes accepted from a peer per family | set protocols bgp group EXT family inet unicast prefix-limit maximum 1000 teardown |
advertise-peer-as | Advertises routes to an EBGP peer even if they came from that peer's AS | set protocols bgp group EXT advertise-peer-as |
The most specific level wins: a neighbor setting overrides the group setting, which overrides the global setting.
Default BGP policies
| Direction | Junos default |
|---|---|
| Import | Accept all BGP routes received from peers (routes whose AS path contains your own AS are dropped by loop detection) |
| Export | Advertise all active BGP routes, subject to the IBGP rule that IBGP-learned routes are not sent to IBGP peers |
The export default sends only BGP routes. Static, direct, OSPF and IS-IS routes are never sent to BGP peers unless an export policy accepts them.
Applying policy
Policies are applied with import and export at the global, group or neighbor level. As with options, only the most specific level applies: if a neighbor has its own export, the group's export is ignored for that neighbor, not combined with it.
user@PE1# set protocols bgp group IBGP export NHS
user@PE1# set protocols bgp group EXT-ISP export [ CUSTOMER-AGG REJECT-ALL ]
user@PE1# set protocols bgp group EXT-ISP neighbor 192.0.2.1 import SET-LP
A list in brackets is a policy chain. Policies are checked left to right; the first terminating action (accept or reject) ends evaluation. If no policy in the chain makes a decision, the BGP default policy decides.
Typical BGP policies
policy-options {
policy-statement NHS {
term BGP {
from protocol bgp;
then next-hop self;
}
}
policy-statement CUSTOMER-AGG {
term AGG {
from {
protocol static;
route-filter 203.0.113.0/24 exact;
}
then {
community add CUST;
accept;
}
}
}
policy-statement REJECT-ALL {
then reject;
}
policy-statement SET-LP {
term ALL {
then {
local-preference 200;
accept;
}
}
}
community CUST members 65000:100;
}
NHS has no terminating action. BGP routes get next-hop self and then fall through to the default export policy, which advertises them. Non-BGP routes do not match and are also left to the default, which does not advertise them.
CUSTOMER-AGG sends a static aggregate to the ISP with a community attached, and REJECT-ALL stops every other route. SET-LP raises local preference on routes from that ISP so it becomes the preferred exit.
To change MED or communities toward one EBGP peer only, apply the export policy at the neighbor level. Remember that this replaces the group export for that neighbor, so repeat any group policies in the neighbor's chain.
Verifying policy results
user@PE1> show route advertising-protocol bgp 192.0.2.1
user@PE1> show route receive-protocol bgp 192.0.2.1 detail
user@PE1> show route 203.0.113.0/24 detail
user@PE1> test policy CUSTOMER-AGG 203.0.113.0/24
advertising-protocol shows what leaves after export; receive-protocol shows what arrived before import. test policy shows which routes in the table a policy accepts.
Common mistakes
Expecting static or IGP routes in BGP without policy. The default export sends only active BGP routes.
Assuming group and neighbor policies combine. The neighbor-level import or export replaces the group one.
Forgetting the final reject. A chain toward a customer or peer that only accepts your aggregate still sends every active BGP route through the default policy unless it ends with a reject.
next-hop self belongs in the export policy toward IBGP peers on the router that learned the EBGP route. Applied as an import policy, it does not change what other routers receive.
What to remember for the exam
- Default import: accept all BGP routes. Default export: advertise active BGP routes only.
- Most specific level wins for options and policies; neighbor overrides group overrides global.
- Policy chains run left to right; first
acceptorrejectends evaluation; then the default policy. then next-hop selfin an IBGP export policy fixes unresolvable external next hops.multihopis required for EBGP between non-adjacent addresses; TTL 64 when set withoutttl.remove-privatestrips private ASs;as-overridereplaces the customer AS;local-aspresents another AS.advertising-protocolshows after export;receive-protocolshows before import.
Check yourself
A static route is not reaching any BGP peer. What is the most likely reason?
The default BGP export policy advertises only active BGP routes, so an export policy must accept the static route.
A group has
export Aand one neighbor in it hasexport B. Which policy applies to that neighbor?Only B, because the most specific level replaces the group policy rather than adding to it.
An export policy term matches BGP routes and sets
next-hop selfwith no accept. Are the routes advertised?Yes, they fall through to the default BGP export policy, which advertises active BGP routes with the new next hop.
Topic 4 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.