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 for AS Path Prepending

This example shows how to configure a routing policy to prepend the AS path on specific routes advertised by BGP.

Requirements

Before you begin, make sure your router interfaces and protocols are correctly configured. We provide the interface and BGP protocol configuration used in this document.

Note:

This example was updated and re-validated on Junos release 22.1R1.

Overview

In this example, you create a routing policy called prependpolicy1 and a term called prependterm1. The routing policy prepends AS number 65001 three times to routes that match the 172.16.0.0/12, 192.168.0.0/16, and 10.0.0.0/8 prefixes, when the mask length is equal to or longer than the specified mask. The result is a match occurs when the route's mask length is equal to or longer than the specified network mask. The prependpolicy1 policy is applied as an export policy to the BGP routes advertised by R1 in AS 65001 to R2 in AS number 65000. Routes that don't match the specified prefix ranges do not undergo AS path prepending.

Topology

Topology

In the topology EBGP peering is configured between R1 and R2. Direct interface peering to the 10.1.23.0/24 subnet addresses is used. R1 belongs to AS number 65001 and is configured to prepend its AS number to a specific set of matching routes when advertised to R2.

By adding AS numbers to the AS path the route becomes less likely to be selected for forwarding. This might be done by the owner of AS 65001 to reduce the amount of ingress traffic it receives from the operator of AS 65000.

Note:

In this example we demonstrate AS path prepending through an export policy. You can also use an import policy to match on routes for attribute manipulation. In general its a best practice to only prepend your local AS number to routes. Prepending AS numbers that belong to remote networks can lead to unexpected results.

For details on BGP paths selection see Understanding BGP Path Selection.

Configuration

Procedure

CLI Quick Configuration

In this section we focus on the configuration of the R1 device. Refer to the appendix for the complete configurations of all devices used in this example.

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.

In this example we assign three test prefixes to an unused interface on R1. A fourth test prefix is assigned to R1's loopback address. This provides four direct routes that can be advertised into BGP. Our policy uses a combination of protocol direct and route-filter statements to control which prefixes undergo AS path prepending.

Step-by-Step Procedure

The following steps requires you to navigate various levels in the configuration hierarchy. For instructions on how to do that, see Use the CLI Editor in Configuration Mode in the Junos OS CLI User Guide.

To create a routing policy that prepends AS numbers to specific routes:

  1. Configure the peering and loopback interfaces.

  2. Configure the AS number, RID, and the external BGP peer group. You define the prependpolicy1 policy in the next step. The policy is applied as an export policy to affect the routes advertised by R1.

  3. Configure the prependpolicy1 policy. The use of or-longer switch to the route filter statements allows a match when the mask length is equal to or longer than the specified mask. Other options like exact match only when the prefix and mask lengths are equal. The else term demonstrates how a route that does not match the prependterm1 term is advertised without AS path prepending by matching the else term.

    Note:

    When you enter multiple AS numbers, you must separate each number with a space. Enclose the string of AS numbers in double quotation marks.

  4. Define test routes. In our sample topology we assign prefixes to an unused interface that is operationally up. This provides direct routes for BGP to advertise for testing the operation of the export policy.

Results

Confirm your configuration by entering the show policy-options, show protocols bgp, show routing-options, and show interfaces commands from configuration mode. If the output does not display the intended configuration, repeat the configuration instructions in this example to correct it.

If you are done configuring the R1 device, enter commit from configuration mode.

Verification

To confirm that the configuration is working properly, perform these tasks:

Verifying the AS Prepending Policy

Purpose

Verify that the policy is configured on the device, and that the appropriate routes are specified to prepend with AS numbers.

Action

From operational mode, enter the show policy prependpolicy1 command.

The policy displays the correct match conditions and actions.

Verifying Routing Policy Application and BGP Peering

Purpose

Verify the routing policy is applied as an export policy to the EBGP peer group. This step also confirms the BGP session to R2 is correctly established.

Action

From operational mode, enter the show bgp neighbor 10.1.23.2 command.

The command output confirms the BGP session is established and that R1 has applied the prependpolicy1 policy as export.

Verify AS Path Prepending

Purpose

Verify the export policy works as design to prepend AS numbers to matching routes.

Action

From operational mode, enter the show route protocol bgp command on R2. Alternatively, use the show route advertising-protocol bgp 10.1.23.2 at R1 to display details about the routes it advertises to R2.

The routes show the expected AS path prepending. Note that the 10.200.1.0/24 route only has one instance of AS number 65001. This route does not match the route filter statements in the prependterm1 of the prependpolicy1 policy and so does not undergo any prepending.

R1's view of the BGP routes it advertises to R2 is provided for completeness:

Appendix Full Configurations

The full configuration for R1.

The full configuration for R2.