BGP · Topic 4 of 4
BGP Routing Policy and Troubleshooting Tools
Apply Junos routing policy to BGP with import and export, local preference, MED and prepend, then troubleshoot with show commands and traceoptions.
- 6 min
- Import policy filters received routes; export policy controls advertisements.
- Default: import accepts all BGP routes; export sends only active BGP routes.
local-preferencefor outbound path choice,metricandas-path-prependfor inbound path choice.
What it is
BGP does what policy tells it. Import policy filters and modifies routes received from a peer before they enter the routing table. Export policy decides which routes are sent to a peer and with which attributes. Policies are written as policy-statement entries under [edit policy-options] and applied with import or export on a group or neighbor.
This page covers how policy changes BGP behavior, then the tools used when BGP does not behave as expected.
How it works
Defaults without policy
| Direction | Default |
|---|---|
| Import | Accept all BGP routes received from peers |
| Export | Advertise active BGP routes to peers; nothing from other protocols |
Both IBGP split horizon and EBGP rules still apply. When you configure an export policy, it is evaluated first. A route that matches no term with an accept or reject action falls through to the default BGP export behavior.
Matching BGP routes
from condition | Matches |
|---|---|
protocol bgp | Routes learned through BGP |
neighbor 192.0.2.2 | Routes learned from that peer |
as-path NAME | Routes whose AS path matches a regular expression defined in policy-options |
community NAME | Routes carrying a defined community |
route-filter 10.0.0.0/8 orlonger | Prefixes by match type |
prefix-list NAME | Prefixes from a named list |
policy-options {
as-path FROM-AS65002 "^65002 .*";
community GOLD members 65001:100;
}
Actions that shape the path
then action | Effect |
|---|---|
local-preference 200 | Sets LOCAL_PREF; higher is preferred, and it is sent to IBGP peers |
metric 50 | Sets MED (lower preferred) on an export policy toward a neighbor AS |
as-path-prepend "65001 65001" | Lengthens the AS path to make a route less attractive |
community add GOLD | Tags the route |
next-hop self | Rewrites NEXT_HOP to the local address |
accept or reject | Ends policy evaluation with a decision |
Two common uses:
- To make one provider the preferred exit, set a higher
local-preferenceon an import policy for that provider. - To influence which provider the outside world uses to enter your network, change what you send: set a lower MED, or prepend your AS on the advertisement to the backup provider.
policy-options {
policy-statement PREFER-ISP-A {
term ALL {
then {
local-preference 200;
accept;
}
}
}
policy-statement ADVERTISE-MINE {
term MY-NETS {
from {
route-filter 203.0.113.0/24 exact;
}
then accept;
}
term REST {
then reject;
}
}
}
protocols {
bgp {
group ISP-A {
import PREFER-ISP-A;
export ADVERTISE-MINE;
}
}
}
To advertise your own static or direct networks to BGP, the export policy must match them, for example from protocol static. The default export never includes them.
Applying policy changes
After you change a policy, the active routes do not change until the routes are reevaluated. Export policy changes apply to the next update. For import changes, clear bgp neighbor 192.0.2.2 soft-inbound asks the peer to resend routes so the policy is applied again without resetting the session.
Troubleshooting with show commands
| Command | What it shows |
|---|---|
show bgp summary | Peer states and route counts |
show bgp neighbor 192.0.2.2 | State, last error, timers and options |
show route receive-protocol bgp 192.0.2.2 | Routes received from the peer, before import policy |
show route advertising-protocol bgp 192.0.2.2 | Routes sent to the peer after export policy |
show route protocol bgp | BGP routes in the routing table |
show route hidden | Routes that exist but are unusable, for example an unreachable next hop |
show route 203.0.113.0/24 extensive | Every path for a prefix with attributes and the reason one was chosen |
The difference between receive-protocol and protocol bgp is useful. If the route appears in the first and not the second, import policy rejected it or the next hop is unreachable. Check show route hidden.
ping and traceroute
Use ping to test reachability to the peer address. For a loopback peering, use ping 10.255.0.2 source 10.255.0.1, so the test matches the way the BGP session is sourced. traceroute shows the forwarding path hop by hop to a destination, and it exposes loops or an unexpected exit.
Traceoptions and logging
Traceoptions write detailed protocol events to a file in /var/log.
user@router# set protocols bgp traceoptions file bgp.log size 1m files 3
user@router# set protocols bgp traceoptions flag open detail
user@router# set protocols bgp traceoptions flag update
user@router# set protocols bgp traceoptions flag state
user@router# commit
user@router> show log bgp.log
user@router> monitor start bgp.log
| Flag | Records |
|---|---|
open | Open messages, useful for AS or capability errors |
update | Update messages and route changes |
keepalive | Keepalive messages |
state | Session state changes |
policy | Policy evaluation |
monitor start bgp.log shows new lines live, and monitor stop ends it. The general system log, show log messages, records session up and down events and the Notification errors received.
Traceoptions use CPU and disk. Use specific flags rather than all, and delete the traceoptions statement when you have finished.
Common mistakes
Expecting policy to change nothing when it is not applied. A policy-statement does nothing until it is referenced by import or export.
Reading show route and missing hidden routes. An unreachable next hop hides the route from normal output.
What to remember for the exam
- Import policy filters received routes; export policy controls advertisements.
- Default: import accepts all BGP routes; export sends only active BGP routes.
local-preferencefor outbound path choice,metricandas-path-prependfor inbound path choice.- Policy matches use
as-path,community,neighbor,route-filterandprefix-list. receive-protocolshows routes before import policy;advertising-protocolshows routes after export policy.show route hiddenfinds routes with unusable next hops.- Traceoptions flags
open,updateandstateare the usual choices; read the file withshow log.
Check yourself
You want traffic to leave through ISP A. What do you configure?
An import policy on the ISP A peers that sets a higher
local-preference, such as 200.A route appears in
show route receive-protocol bgpbut not in the routing table. Where do you look next?At import policy and at
show route hidden, since the next hop may be unreachable.Which command shows what you are actually sending a peer?
show route advertising-protocol bgp neighbor-address, which lists the routes after export policy.
Topic 4 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.