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
In a nutshell
  • 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 accept or reject ends 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.

PeerUPDATEImport policyaccept, reject, modifyacceptedRouting tableactive routesExport policyaccept, reject, modifyUPDATEPeer

How it works

Common BGP options

OptionWhat it doesExample
local-addressSources the TCP session from this address, usually lo0set protocols bgp group IBGP local-address 10.255.0.1
multihopAllows EBGP to a peer that is not directly connected; TTL defaults to 64 when setset protocols bgp group EXT multihop ttl 2
authentication-keyMD5 authentication of the TCP session; must match on both sidesset protocols bgp group EXT authentication-key "secret"
hold-timeProposed hold time (default 90 seconds)set protocols bgp group EXT hold-time 30
passiveDo not open TCP; wait for the peer to connectset protocols bgp group EXT passive
local-asPresents a different AS number to the peer, for example during an AS migrationset protocols bgp group EXT local-as 64999
remove-privateStrips private AS numbers from the AS path when advertising to EBGP peersset protocols bgp group EXT remove-private
as-overrideReplaces the customer AS with your own AS in the path, so sites that share one AS accept each other's routesset protocols bgp group CE as-override
local-preferenceSets local preference on routes sent to IBGP peersset protocols bgp group IBGP local-preference 150
metric-outSets MED on routes sent to this peerset protocols bgp group EXT metric-out 50
dampingEnables route flap dampingset protocols bgp damping
prefix-limitLimits the routes accepted from a peer per familyset protocols bgp group EXT family inet unicast prefix-limit maximum 1000 teardown
advertise-peer-asAdvertises routes to an EBGP peer even if they came from that peer's ASset 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

DirectionJunos default
ImportAccept all BGP routes received from peers (routes whose AS path contains your own AS are dropped by loop detection)
ExportAdvertise 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.

RouteNHS term BGP matchesNext hop selfno terminating actionDefault BGP exportactive BGP routeAdvertised
Exam tip

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.

Watch out

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 accept or reject ends evaluation; then the default policy.
  • then next-hop self in an IBGP export policy fixes unresolvable external next hops.
  • multihop is required for EBGP between non-adjacent addresses; TTL 64 when set without ttl.
  • remove-private strips private ASs; as-override replaces the customer AS; local-as presents another AS.
  • advertising-protocol shows after export; receive-protocol shows 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 A and one neighbor in it has export 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 self with 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.