Related Documentation
- ACX Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
- J Series
- Understanding BGP Path Selection
- M Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
- MX Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
- PTX Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
- QFX Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
- SRX Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
- T Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
Example: Configuring a Routing Policy to Prepend the AS Path
This example shows how to configure a routing policy to prepend the AS path.
Requirements
No special configuration beyond device initialization is required before configuring this example.
Overview
The BGP best path algorithm determines how the best path to an autonomous system (AS) is selected.
In this example, an enterprise (AS 64510) has multihoming to two service providers, one in AS 64513 and the other in AS 64514. The enterprise prefers that incoming traffic take a particular path to reach its network because it has one fast primary connection and some slower connections that are to be used as backups if the primary connection is down. AS path prepending is used to influence inbound routing to the enterprise AS.
BGP does not take bandwidth into consideration when determining the best path. By using AS path prepending, you can lengthen the AS path that routing devices advertise to neighbors to make the neighbors calculate the path to be longer than it actually is.
AS 64510 has a T1 connection to AS 64513 and a T1 connection to AS 64514.
AS 64513 and AS 64514 also peer directly with each other, and have a 100-Mbps connection between them.
In addition, AS 64510 has a 100-Mbps connection from Device R2 to Device R3 in AS 64513.
Because of the large difference in bandwidth, the administrators of AS 64510 prefer that all (or, at least, the majority) of incoming traffic come in over this much faster 100-Mbps Ethernet connection. AS 64510 is connected directly to Device R4, however, and this results in a short AS path in Device R4’s routing table to AS 64510’s prefixes. AS 64514, by default, sends any traffic for AS 64510 over its 1.5-Mbps T1 connection.
This example uses AS prepending to cause Device R4 to, instead, send any traffic destined to AS 64510 over the 100-Mbps connection to AS 64513. AS prepending is used to cause AS 64513 to send any traffic destined to AS 64510 over the 100-Mbps connection to Device R2 in AS 64510.
Topology
Figure 1 shows the sample network.
Figure 1: BGP Topology AS Path Prepending

CLI Quick Configuration shows the configuration for all of the devices in Figure 1.
The section Step-by-Step Procedure describes the steps on Device R2.
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
Device R3
Device R4
Step-by-Step Procedure
The following example requires you to navigate various levels in the configuration hierarchy. For instructions on how to do that, see Using the CLI Editor in Configuration Mode in the CLI User Guide.
To configure Device R2:
- Configure the device interfaces.[edit interfaces]user@R2# set fe-1/2/0 unit 0 family inet address 10.0.0.2/30
user@R2# set fe-1/2/2 unit 0 family inet address 10.2.0.1/30
user@R2# set fe-1/2/1 unit 0 family inet address 10.3.0.2/30
user@R2# set lo0 unit 0 family inet address 192.168.0.2/32user@R2# set lo0 unit 0 family inet address 172.16.2.1/24 - Configure an interior gateway protocol (IGP) connection
to Device R1.[edit protocols ospf area 0.0.0.0]user@R2# set interface lo0.0 passiveuser@R2# set interface fe-1/2/0.0
Create the routing policy that will be applied to Device R1 and Device R3.
This policy simply advertises the routes that are in Device R2’s routing table.
[edit policy-options policy-statement send-routes term 1]user@R2# set from route-filter 10.0.0.0/8 orlongeruser@R2# set from route-filter 172.16.0.0/16 orlongeruser@R2# set then acceptCreate the routing policy that will be applied to Device R4.
This policy prepends the routes that are advertised to Device R4, so that Device R4 is less likely to use its direct connection to Device R2.

Note: If you enter multiple numbers, you must separate each number with a space. Enclose the numbers in double quotation marks.
[edit policy-options policy-statement send-routes-and-prepend term 1]user@R2# set from route-filter 172.16.0.0/16 orlongeruser@R2# set then as-path-prepend "64510 64510"user@R2# set then acceptConfigure the internal BGP (IBGP) connection to Device R1.
[edit protocols bgp group int]user@R2# set type internaluser@R2# set local-address 192.168.0.2user@R2# set export send-routesuser@R2# set neighbor 192.168.0.1Configure the external BGP (EBGP) connection to Device R3 and Device R4.
For Device R3, apply the send-routes policy. For Device R4, apply the send-routes-and-prepend policy.
[edit protocols bgp group ext]user@R2# set type externaluser@R2# set neighbor 10.3.0.1 export send-routes-and-prependuser@R2# set neighbor 10.3.0.1 peer-as 64514user@R2# set neighbor 10.2.0.2 export send-routesuser@R2# set neighbor 10.2.0.2 peer-as 64513Configure the AS number.
[edit routing-options]user@R2# set autonomous-system 64510
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.
If you are done configuring the device, enter commit from configuration mode.
Verification
Confirm that the configuration is working properly.
Verifying That the Routes Are Prepended
Purpose
On Device R3 and Device R4, use the show route command to view the routing tables.
Action
user@R3> show route match-prefix 172.16.*/24
protocol bgp
inet.0: 17 destinations, 30 routes (17 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.1.0/24 *[BGP/170] 03:36:53, MED 1, localpref 100
AS path: 64510 I, validation-state: unverified
> to 10.2.0.1 via fe-1/2/2.0
[BGP/170] 03:37:08, localpref 100
AS path: 64510 64510 64510 I, validation-state: unverified
> to 10.1.0.1 via fe-1/2/1.0
172.16.2.0/24 *[BGP/170] 03:37:07, localpref 100
AS path: 64510 I, validation-state: unverified
> to 10.2.0.1 via fe-1/2/2.0
[BGP/170] 03:36:53, MED 1, localpref 100
AS path: 64510 64510 64510 I, validation-state: unverified
> to 10.1.0.1 via fe-1/2/1.0
172.16.4.0/24 *[BGP/170] 03:37:31, localpref 100
AS path: 64514 I, validation-state: unverified
> to 10.4.0.2 via fe-1/2/0.0
[BGP/170] 03:37:07, localpref 100
AS path: 64510 64514 I, validation-state: unverified
> to 10.2.0.1 via fe-1/2/2.0
[BGP/170] 03:36:35, localpref 100
AS path: 64510 64510 64510 64514 I, validation-state: unverified
> to 10.1.0.1 via fe-1/2/1.0user@R4> show route match-prefix 172.16.* protocol
bgp
inet.0: 15 destinations, 22 routes (15 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
172.16.1.0/24 *[BGP/170] 03:34:31, localpref 100
AS path: 64513 64510 I, validation-state: unverified
> to 10.4.0.1 via fe-1/2/0.0
[BGP/170] 03:34:31, MED 1, localpref 100
AS path: 64510 64510 64510 I, validation-state: unverified
> to 10.3.0.2 via fe-1/2/1.0
172.16.2.0/24 *[BGP/170] 03:34:45, localpref 100
AS path: 64513 64510 I, validation-state: unverified
> to 10.4.0.1 via fe-1/2/0.0
[BGP/170] 03:35:09, localpref 100
AS path: 64510 64510 64510 I, validation-state: unverified
> to 10.3.0.2 via fe-1/2/1.0
172.16.3.0/24 *[BGP/170] 03:35:09, localpref 100
AS path: 64513 I, validation-state: unverified
> to 10.4.0.1 via fe-1/2/0.0
[BGP/170] 03:34:45, localpref 100
AS path: 64510 64510 64510 64513 I, validation-state: unverified
> to 10.3.0.2 via fe-1/2/1.0
Meaning
Active routes are marked with an asterisk (*). The output shows the AS paths that are prepended with “64510 64510” to make the AS path longer, and thereby make the associated route inactive.
Device R3 does not use its fe-1/2/1.0 interface to reach 172.16 destinations in AS 64510. Instead, Device R3 uses its fe-1/2/2.0 interface, even for destinations that are advertised by Device R1.
Device R4 does not use its fe-1/2/1.0 interface to reach 172.16 destinations in AS 64510. Instead, Device R4 goes through Device R3 to reach AS 64510. This way, the higher bandwidth (fast) link is utilized, and the slower links are used as backups when the fast link is unavailable.
Related Documentation
- ACX Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
- J Series
- Understanding BGP Path Selection
- M Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
- MX Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
- PTX Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
- QFX Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
- SRX Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection
- T Series
- Understanding Prepending AS Numbers to BGP AS Paths
- Understanding Adding AS Numbers to BGP AS Paths
- Understanding BGP Path Selection