BGP – as-path-prepend
1. Intro
You can prepend one or more autonomous system (AS) numbers at the beginning of an AS path. The AS numbers are added at the beginning of the path after the actual AS number from which the route originates has been added to the path. Prepending an AS path makes a shorter AS path look longer and therefore less preferable to BGP.
2. Configuring as-path-prepend:
This time we will apply the configuration on the R3 router. R3 is receiving the 192.168.50.0/26 prefix and is advertising that to R2. At this point we will the as-path-prepending:

The configuration is straightforward:
### Initial config on R3:
root@R3# show protocols bgp | display set
set protocols bgp group AS-200 peer-as 200
set protocols bgp group AS-200 neighbor 17.8.8.1
set protocols bgp group AS-400 keep all
set protocols bgp group AS-400 peer-as 400
set protocols bgp group AS-400 neighbor 17.8.11.2
### What are we advertising to R2:
root@R3# run show route advertising-protocol bgp 17.8.8.1
inet.0: 24 destinations, 24 routes (24 active, 0 holddown, 0 hidden)
Prefix Nexthop MED Lclpref AS path
* 192.168.50.0/26 Self 400 65500 I
### How R2 is receiving the prefix:
root@R2# run show route receive-protocol bgp 17.8.8.2
inet.0: 23 destinations, 23 routes (23 active, 0 holddown, 0 hidden)
Prefix Nexthop MED Lclpref AS path
* 192.168.50.0/26 17.8.8.2 65300 400 65500 I
### Apply the prepend policy:
root@R3# show policy-options policy-statement BGP-EXPORT | display set
set policy-options policy-statement BGP-EXPORT from protocol bgp
set policy-options policy-statement BGP-EXPORT then as-path-prepend "65300 65300"
set policy-options policy-statement BGP-EXPORT then accept
set protocols bgp group AS-200 export BGP-EXPORT
### We can see how R3 is prepending exactly as in the policy:
root@R3# run show route advertising-protocol bgp 17.8.8.1
inet.0: 24 destinations, 24 routes (24 active, 0 holddown, 0 hidden)
Prefix Nexthop MED Lclpref AS path
* 192.168.50.0/26 Self 65300 65300 [65300] 400 65500 I
### R2 is receiving the route with 3 x AS65300 (the default 65300 + the prepend "65300 65300"):
root@R2# run show route receive-protocol bgp 17.8.8.2
inet.0: 23 destinations, 23 routes (23 active, 0 holddown, 0 hidden)
Prefix Nexthop MED Lclpref AS path
* 192.168.50.0/26 17.8.8.2 65300 65300 65300 400 65500 I
3. We can prepend any number:
We will change the policy, so that we prepend some random numbers:
root@R3# set policy-options policy-statement BGP-EXPORT then as-path-prepend "4567 5678"
[edit]
root@R3# show | compare
[edit policy-options policy-statement BGP-EXPORT then]
- as-path-prepend "65300 65300";
+ as-path-prepend "4567 5678";
[edit]
root@R3# commit
commit complete
[edit]
root@R3# run show route advertising-protocol bgp 17.8.8.1
inet.0: 24 destinations, 24 routes (24 active, 0 holddown, 0 hidden)
Prefix Nexthop MED Lclpref AS path
* 192.168.50.0/26 Self 4567 5678 [65300] 400 65500 I
### The view on R2:
root@R2# run show route receive-protocol bgp 17.8.8.2
inet.0: 23 destinations, 23 routes (23 active, 0 holddown, 0 hidden)
Prefix Nexthop MED Lclpref AS path
* 192.168.50.0/26 17.8.8.2 4567 5678 65300 400 65500 I
Any AS number can be used when prepending, as long as it is within the range 1 to 4294967295. So, watch out for typos.
root@R3# set policy-options policy-statement BGP-EXPORT then as-path-prepend "4567 56700000000000000000"
[edit]
root@R3# commit check
[edit policy-options policy-statement BGP-EXPORT]
'then'
AS Number is not within the range 1 to 4294967295
error: configuration check-out failed
External Resources: