BGP · Topic 5 of 5
Configuring, Monitoring and BGP Routing Policy
JN0-650 study page on configuring, monitoring and troubleshooting BGP on Junos, plus BGP import and export policy, default policies and route filters.
- 5 min
- Default import accepts all; default export advertises only active BGP routes.
- To advertise local, static or IGP routes you need an export policy with
from protocolandaccept. - The most specific attach point wins: neighbor over group over global.
What it is
This page ties the chapter together. You build a BGP configuration, read the show commands that describe it, and use routing policy to decide what BGP accepts and announces.
BGP policy is where most of the real configuration work happens, because BGP does not choose routes by metric. It follows the policy you apply.
How it works
Default policies
BGP has built-in behavior when you configure no policy:
| Direction | Default |
|---|---|
| Import | Accept all received BGP routes |
| Export | Advertise active BGP routes; follow the IBGP and EBGP rules; do not advertise routes from other protocols |
So to advertise your own prefixes, such as a loopback, a static route or an OSPF route, you must write an export policy.
set policy-options policy-statement ANNOUNCE term 1 from protocol [ direct static ]
set policy-options policy-statement ANNOUNCE term 1 from route-filter 203.0.113.0/24 exact
set policy-options policy-statement ANNOUNCE term 1 then accept
set protocols bgp group EXT export ANNOUNCE
Where policy is attached
Policy can be attached at group level or at neighbor level. The most specific level applies.
set protocols bgp import GLOBAL-IN
set protocols bgp group EXT import GROUP-IN
set protocols bgp group EXT neighbor 192.0.2.2 import NEIGHBOR-IN
A chain such as import [ P1 P2 P3 ] evaluates policies left to right until one accepts or rejects. If none takes a final action, the default policy for that protocol applies. Use then next policy to move to the next policy in the chain, or then next term for the next term in the same policy.
Route filters
| Match type | Matches |
|---|---|
exact | Only that prefix and length |
orlonger | The prefix and any longer prefix inside it |
longer | Longer prefixes only, not the prefix itself |
upto /n | The prefix and prefixes up to length n |
prefix-length-range /a-/b | Prefixes between the two lengths |
set policy-options policy-statement NO-LONG term 1 from route-filter 0.0.0.0/0 prefix-length-range /25-/32
set policy-options policy-statement NO-LONG term 1 then reject
You can also match from neighbor, from as-path, from community, and from protocol. In an export policy, matching from protocol bgp selects routes learned by BGP.
Typical policy goals
| Goal | Tool |
|---|---|
| Choose an exit | Import: then local-preference |
| Influence inbound traffic | Export: as-path-prepend or metric |
| Block bogon or too long prefixes | Import: route-filter with reject |
| Advertise your prefixes | Export: from protocol plus accept |
| Mark routes for a customer | community add |
| Act as next hop for IBGP | then next-hop self |
Show commands
| Question | Command |
|---|---|
| State of every session and prefix counts | show bgp summary |
| Details, families and errors for one peer | show bgp neighbor 192.0.2.2 |
| What did the peer send, before policy | show route receive-protocol bgp 192.0.2.2 |
| What do we send the peer | show route advertising-protocol bgp 192.0.2.2 |
| All BGP routes in the table | show route protocol bgp |
| Routes that cannot be used | show route hidden |
| Why this path was chosen | show route 198.51.100.0/24 extensive |
In show bgp summary the last column for an Established peer shows counts of active, received, accepted and damped prefixes. A peer that is not Established shows its state name instead.
show route receive-protocol bgp shows what the peer sent. If the route is there but not in show route protocol bgp, a policy or hidden route is the cause. If it is not there, the peer never sent it.
Troubleshooting a session
| State or symptom | Check |
|---|---|
| Idle | No route to the peer, or the neighbor is administratively disabled or waiting after an error |
| Connect or Active | TCP is failing: no route, wrong neighbor address, wrong local-address, a filter blocking port 179, or multihop missing |
| OpenSent with NOTIFICATION | Look at the error in show bgp neighbor: bad peer AS, bad hold time or authentication |
| Established, route missing | Import policy, hidden next hop, or the peer's export policy |
| Established, route not advertised | Your export policy, or the IBGP re-advertisement rule |
When you change policy, use clear bgp neighbor 192.0.2.2 soft to reapply it without resetting the session.
Changing a policy does not automatically change what was already advertised. Soft clear refreshes it; a hard clear resets the session.
Common mistakes
Expecting direct or static routes to be advertised by default. BGP exports only BGP routes without an export policy.
Ending an import policy with no action. Routes fall through to the default and are accepted, which may not be your intention.
Using orlonger when exact was meant. It matches too much.
Applying policy at group level but a neighbor-level policy exists. The neighbor-level policy takes over for that neighbor.
Hard resetting a production session to test policy. Use a soft clear.
What to remember for the exam
- Default import accepts all; default export advertises only active BGP routes.
- To advertise local, static or IGP routes you need an export policy with
from protocolandaccept. - The most specific attach point wins: neighbor over group over global.
- Route filter match types:
exact,orlonger,longer,upto,prefix-length-range. show route receive-protocol bgpandadvertising-protocol bgpshow what comes in and goes out.show route hiddenfinds routes that exist but cannot be used.clear bgp neighbor ... softreapplies policy.
Check yourself
Why is a static route not advertised to an EBGP peer, with no export policy?
The default export policy advertises only BGP routes, so an export policy with
from protocol staticandacceptis needed.How do you see what a peer sent before your import policy?
show route receive-protocol bgp <peer>(withhiddenfor rejected or unusable routes).What does
route-filter 10.0.0.0/8 orlongermatch?The prefix 10.0.0.0/8 and every longer prefix inside it.
Topic 5 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.