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
In a nutshell
  • Import policy filters received routes; export policy controls advertisements.
  • Default: import accepts all BGP routes; export sends only active BGP routes.
  • local-preference for outbound path choice, metric and as-path-prepend for 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.

Peer sends updateImport policyfilter and set attributesRouting tablebest path chosenExport policychoose and set attributesUpdate to peers

How it works

Defaults without policy

DirectionDefault
ImportAccept all BGP routes received from peers
ExportAdvertise 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 conditionMatches
protocol bgpRoutes learned through BGP
neighbor 192.0.2.2Routes learned from that peer
as-path NAMERoutes whose AS path matches a regular expression defined in policy-options
community NAMERoutes carrying a defined community
route-filter 10.0.0.0/8 orlongerPrefixes by match type
prefix-list NAMEPrefixes from a named list
policy-options {
    as-path FROM-AS65002 "^65002 .*";
    community GOLD members 65001:100;
}

Actions that shape the path

then actionEffect
local-preference 200Sets LOCAL_PREF; higher is preferred, and it is sent to IBGP peers
metric 50Sets 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 GOLDTags the route
next-hop selfRewrites NEXT_HOP to the local address
accept or rejectEnds policy evaluation with a decision

Two common uses:

  • To make one provider the preferred exit, set a higher local-preference on 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;
        }
    }
}
Exam tip

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

CommandWhat it shows
show bgp summaryPeer states and route counts
show bgp neighbor 192.0.2.2State, last error, timers and options
show route receive-protocol bgp 192.0.2.2Routes received from the peer, before import policy
show route advertising-protocol bgp 192.0.2.2Routes sent to the peer after export policy
show route protocol bgpBGP routes in the routing table
show route hiddenRoutes that exist but are unusable, for example an unreachable next hop
show route 203.0.113.0/24 extensiveEvery 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.

Prefix missingseen in received routesImport policy or next hopcheck hidden routesPrefix missingnot in received routesPeer is not sendingcheck its export policy

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
FlagRecords
openOpen messages, useful for AS or capability errors
updateUpdate messages and route changes
keepaliveKeepalive messages
stateSession state changes
policyPolicy 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.

Watch out

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-preference for outbound path choice, metric and as-path-prepend for inbound path choice.
  • Policy matches use as-path, community, neighbor, route-filter and prefix-list.
  • receive-protocol shows routes before import policy; advertising-protocol shows routes after export policy.
  • show route hidden finds routes with unusable next hops.
  • Traceoptions flags open, update and state are the usual choices; read the file with show 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 bgp but 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.