ON THIS PAGE
Example: Configuring a Routing Policy That Removes BGP Communities
This example shows how to create a policy that accepts BGP routes, but removes BGP communities from the routes.
Requirements
No special configuration beyond device initialization is required before you configure this example.
Overview
This example shows two routing devices with an external BGP (EBGP) connection between them. Device R2 uses the BGP session to send two static routes to Device R1. On Device R1, an import policy specifies that all BGP communities must be removed from the routes.
By default, when communities are configured on EBGP peers, they
are sent and accepted. To suppress the acceptance of communities received
from a neighbor, you can remove all communities or a specified set
of communities. When the result of a policy is an empty set of communities,
the community attribute is not included. To remove all communities,
first define a wildcard set of communities (here, the community is
named wild
):
[edit policy-options] community wild members "* : *";
Then, in the routing policy statement, specify the community
delete
action:
[edit policy-options] policy-statement policy-name { term term-name { then community delete wild; } }
To suppress a particular community from any autonomous system
(AS), define the community as community wild members "*:community-value"
.
Configuration
CLI Quick Configuration
To quickly configure this example, copy the
following commands, paste them into a text file, remove any line breaks,
change any details necessary to match your network configuration,
and then copy and paste the commands into the CLI at the [edit]
hierarchy level.
Device R1
set interfaces fe-1/1/0 unit 0 description to-R2 set interfaces fe-1/1/0 unit 0 family inet address 10.0.0.1/30 set interfaces lo0 unit 0 family inet address 192.168.0.1/32 set protocols bgp group external-peers type external set protocols bgp group external-peers peer-as 2 set protocols bgp group external-peers neighbor 10.0.0.2 import remove-communities set policy-options policy-statement remove-communities term 1 from protocol bgp set policy-options policy-statement remove-communities term 1 then community delete wild set policy-options policy-statement remove-communities term 1 then accept set policy-options policy-statement remove-communities term 2 then reject set policy-options community wild members *:* set routing-options router-id 192.168.0.1 set routing-options autonomous-system 1
Device R2
set interfaces fe-1/1/0 unit 0 description to-R1 set interfaces fe-1/1/0 unit 0 family inet address 10.0.0.2/30 set interfaces lo0 unit 0 family inet address 192.168.0.2/32 set protocols bgp group external-peers type external set protocols bgp group external-peers export statics set protocols bgp group external-peers peer-as 1 set protocols bgp group external-peers neighbor 10.0.0.1 set policy-options policy-statement statics from protocol static set policy-options policy-statement statics then community add 1 set policy-options policy-statement statics then accept set policy-options community 1 members 2:1 set policy-options community 1 members 2:2 set policy-options community 1 members 2:3 set policy-options community 1 members 2:4 set policy-options community 1 members 2:5 set policy-options community 1 members 2:6 set policy-options community 1 members 2:7 set policy-options community 1 members 2:8 set policy-options community 1 members 2:9 set policy-options community 1 members 2:10 set routing-options static route 10.2.0.0/16 reject set routing-options static route 10.2.0.0/16 install set routing-options static route 10.3.0.0/16 reject set routing-options static route 10.3.0.0/16 install set routing-options router-id 192.168.0.3 set routing-options autonomous-system 2
Procedure
Step-by-Step Procedure
The following example requires that you navigate various levels in the configuration hierarchy. For information about navigating the CLI, see Using the CLI Editor in Configuration Mode in the Junos OS CLI User Guide.
To configure Device R1:
Configure the interfaces.
[edit interfaces] user@R1# set fe-1/1/0 unit 0 description to-R2 user@R1# set fe-1/1/0 unit 0 family inet address 10.0.0.1/30 user@R1# set lo0 unit 0 family inet address 192.168.0.1/32
Configure BGP.
Apply the import policy to the BGP peering session with Device R2.
[edit protocols bgp group external-peers] user@R1# set type external user@R1# set peer-as 2 user@R1# set neighbor 10.0.0.2 import remove-communities
Configure the routing policy that deletes communities.
[edit policy-options policy-statement remove-communities] user@R1# set term 1 from protocol bgp user@R1# set term 1 then community delete wild user@R1# set term 1 then accept user@R1# set term 2 then reject
Configure the autonomous system (AS) number and the router ID.
[edit routing-options ] user@R1# set router-id 192.168.0.1 user@R1# set autonomous-system 1
Step-by-Step Procedure
The following example requires that you navigate various levels in the configuration hierarchy. For information about navigating the CLI, see Using the CLI Editor in Configuration Mode in the Junos OS CLI User Guide.
To configure Device R2:
Configure the interfaces.
[edit interfaces] user@R2# set fe-1/1/0 unit 0 description to-R1 user@R2# set fe-1/1/0 unit 0 family inet address 10.0.0.2/30 user@R2# set lo0 unit 0 family inet address 192.168.0.2/32
Configure the router ID and the autonomous system (AS) number.
[edit routing-options] user@R2# set router-id 192.168.0.3 user@R2# set autonomous-system 2
Configure BGP.
[edit protocols bgp group external-peers] user@R2# set type external user@R2# set peer-as 1 user@R2# set neighbor 10.0.0.1
Configure multiple communities, or configure a single community with multiple members.
[edit policy-options community 1] user@R2# set members 2:1 user@R2# set members 2:2 user@R2# set members 2:3 user@R2# set members 2:4 user@R2# set members 2:5 user@R2# set members 2:6 user@R2# set members 2:7 user@R2# set members 2:8 user@R2# set members 2:9 user@R2# set members 2:10
Configure the static routes.
[edit routing-options static] user@R2# set route 10.2.0.0/16 reject user@R2# set route 10.2.0.0/16 install user@R2# set route 10.3.0.0/16 reject user@R2# set route 10.3.0.0/16 install
Configure a routing policy that advertises static routes into BGP and adds the BGP community to the routes.
[edit policy-options policy-statement statics] user@R2# set from protocol static user@R2# set then community add 1 user@R2# set then accept
Apply the export policy.
[edit protocols bgp group external-peers] user@R2# set export statics
Results
From configuration mode, confirm your configuration
by entering the show interfaces
, show protocols
, show policy-options
, and show routing-options
commands. If the output does not display the intended configuration,
repeat the instructions in this example to correct the configuration.
Device R1
user@R1# show interfaces fe-1/1/0 { unit 0{ description to-R2; family inet { address 10.0.0.1/30; } } } lo0 { unit 0 { family inet { address 192.168.0.1/32; } } }
user@R1# show protocols bgp { group external-peers { type external; peer-as 2; neighbor 10.0.0.2 { import remove-communities; } } }
user@R1# show policy-options policy-statement remove-communities { term 1 { from protocol bgp; then { community delete wild; accept; } } term 2 { then reject; } } community wild members *:*;
user@R1# show routing-options router-id 192.168.0.1; autonomous-system 1;
Device R2
user@R2# show interfaces fe-1/1/0 { unit 0 { description to-R1; family inet { address 10.0.0.2/30; } } } lo0 { unit 0 { family inet { address 192.168.0.2/32; } } }
user@R2# show protocols bgp { group external-peers { type external; export statics; peer-as 1; neighbor 10.0.0.1; } }
user@R2# show policy-options policy-statement statics { from protocol static; then { community add 1; accept; } } community 1 members [ 2:1 2:2 2:3 2:4 2:5 2:6 2:7 2:8 2:9 2:10 ];
user@R2# show routing-options static { route 10.2.0.0/16 { reject; install; } route 10.3.0.0/16 { reject; install; } } router-id 192.168.0.3; autonomous-system 2;
If you are done configuring the devices, enter commit
from configuration mode.
Verification
Confirm that the configuration is working properly.
Verifying the BGP Routes
Purpose
Make sure that the routing table on Device R1 does not contain BGP communities.
Action
On Device R1, run the
show route protocols bgp extensive
command.user@R1> show route protocols bgp extensive inet.0: 5 destinations, 5 routes (5 active, 0 holddown, 0 hidden) 10.2.0.0/16 (1 entry, 1 announced) TSI: KRT in-kernel 10.2.0.0/16 -> {10.0.0.2} *BGP Preference: 170/-101 Next hop type: Router, Next hop index: 671 Address: 0x9458270 Next-hop reference count: 4 Source: 10.0.0.2 Next hop: 10.0.0.2 via lt-1/1/0.5, selected Session Id: 0x100001 State: <Active Ext> Local AS: 1 Peer AS: 2 Age: 20:39:01 Validation State: unverified Task: BGP_2.10.0.0.2+179 Announcement bits (1): 0-KRT AS path: 2 I Accepted Localpref: 100 Router ID: 192.168.0.3 10.3.0.0/16 (1 entry, 1 announced) TSI: KRT in-kernel 10.3.0.0/16 -> {10.0.0.2} *BGP Preference: 170/-101 Next hop type: Router, Next hop index: 671 Address: 0x9458270 Next-hop reference count: 4 Source: 10.0.0.2 Next hop: 10.0.0.2 via lt-1/1/0.5, selected Session Id: 0x100001 State: <Active Ext> Local AS: 1 Peer AS: 2 Age: 20:39:01 Validation State: unverified Task: BGP_2.10.0.0.2+179 Announcement bits (1): 0-KRT AS path: 2 I Accepted Localpref: 100 Router ID: 192.168.0.3
On Device R1, deactivate the
community remove
configuration in the import policy.[edit policy-options policy-statement remove-communities term 1] user@R1# deactivate then community delete wild user@R1# commit
On Device R1, run the
show route protocols bgp extensive
command to view the advertised communities.user@R1> show route protocols bgp extensive inet.0: 5 destinations, 5 routes (5 active, 0 holddown, 0 hidden) 10.2.0.0/16 (1 entry, 1 announced) TSI: KRT in-kernel 10.2.0.0/16 -> {10.0.0.2} *BGP Preference: 170/-101 Next hop type: Router, Next hop index: 671 Address: 0x9458270 Next-hop reference count: 4 Source: 10.0.0.2 Next hop: 10.0.0.2 via lt-1/1/0.5, selected Session Id: 0x100001 State: <Active Ext> Local AS: 1 Peer AS: 2 Age: 20:40:53 Validation State: unverified Task: BGP_2.10.0.0.2+179 Announcement bits (1): 0-KRT AS path: 2 I Communities: 2:1 2:2 2:3 2:4 2:5 2:6 2:7 2:8 2:9 2:10 Accepted Localpref: 100 Router ID: 192.168.0.3 10.3.0.0/16 (1 entry, 1 announced) TSI: KRT in-kernel 10.3.0.0/16 -> {10.0.0.2} *BGP Preference: 170/-101 Next hop type: Router, Next hop index: 671 Address: 0x9458270 Next-hop reference count: 4 Source: 10.0.0.2 Next hop: 10.0.0.2 via lt-1/1/0.5, selected Session Id: 0x100001 State: <Active Ext> Local AS: 1 Peer AS: 2 Age: 20:40:53 Validation State: unverified Task: BGP_2.10.0.0.2+179 Announcement bits (1): 0-KRT AS path: 2 I Communities: 2:1 2:2 2:3 2:4 2:5 2:6 2:7 2:8 2:9 2:10 Accepted Localpref: 100 Router ID: 192.168.0.3
Meaning
The output shows that in Device R1’s routing
table, the communities are suppressed in the BGP routes sent from
Device R2. When the community remove
setting in Device
R1’s import policy is deactivated, the communities are no longer
suppressed.