Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Example: Configuring a Routing Policy Based on the Number of BGP Communities

This example shows how to create a policy that accepts BGP routes based on the number of BGP communities.

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 the BGP-received routes can contain up to five communities to be considered a match. For example, if a route contains three communities, it is considered a match and is accepted. If a route contains six or more communities, it is considered a nonmatch and is rejected.

It is important to remember that the default policy for EBGP is to accept all routes. To ensure that the nonmatching routes are rejected, you must include a then reject action at the end of the policy definition.

Topology

Figure 1 shows the sample network.

Figure 1: BGP Policy with a Limit on the Number of Communities AcceptedBGP Policy with a Limit on the Number of Communities Accepted

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

Device R2

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:

  1. Configure the interfaces.

  2. Configure BGP.

    Apply the import policy to the BGP peering session with Device R2.

  3. Configure the routing policy that sends direct routes.

  4. Configure the autonomous system (AS) number and the router ID.

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:

  1. Configure the interfaces.

  2. Configure the router ID and the autonomous system (AS) number.

  3. Configure BGP.

  4. Configure multiple communities, or configure a single community with multiple members.

  5. Configure the static routes.

  6. Configure a routing policy that advertises static routes into BGP and adds the BGP community to the routes.

  7. Apply the export policy.

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

Device R2

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 contains the expected BGP routes.

Action

  1. On Device R1, run the show route protocols bgp command.

  2. On Device R1, change the community-count configuration in the import policy.

  3. On Device R1, run the show route protocols bgp command.

  4. On Device R1, run the show route protocols bgp extensive command to view the advertised communities.

Meaning

The output shows that in Device R1’s routing table, the BGP routes sent from Device R2 are hidden. When the community-count setting in Device R1’s import policy is modified, the BGP routes are no longer hidden.