# AS Path Prepending on XE and XR

This short article explores what happens when you do AS path prepending and apply it outbound to an eBGP neighbor.

Consider the following topology:

<figure><img src="/files/541olB2H15sY4W913kIC" alt=""><figcaption></figcaption></figure>

R1 originates 10.10.10.10/32 into BGP. R2 uses the following route-map and applies it to the neighbor statement for R3 outbound:

```
route-map AS_PREPEND
 set as-path prepend 100
!
router bgp 65001
 neighbor <R3> route-map AS_PREPEND out
```

What is the AS path for 10.10.10.10/32 as seen on R3? There are two options that might make sense:

1. 100 65001 65000 i
2. 65001 100 65000 i

The answer is **65001 100 65000 i**. This is because the route-map is applied before the local AS is finally added to the AS path, when advertising the route to the eBGP peer.

<figure><img src="/files/OH7Hflwa4jkOL1WW1qOq" alt=""><figcaption></figcaption></figure>

```
R3#show bgp ipv4 uni | be Network
     Network          Next Hop            Metric LocPrf Weight Path
 *>   10.10.10.10/32   10.10.12.1                             0 65001 100 65000 i
```

Note that this is logic is not applicable when you change the next-hop IP address in the route-map. The router doesn’t then change this to its interface address used for the eBGP session. The next-hop that the route-map sets takes precedence.

### AS Path Prepending on IOS-XR <a href="#id-61ad0a68-0305-4fcf-b297-28cfc9a503bb" id="id-61ad0a68-0305-4fcf-b297-28cfc9a503bb"></a>

This same logic applies when preforming AS path prepending on XR with the following route-policy:

```
#R2
route-policy AS_PREPEND
 prepend as-path 100
end-policy
!
router bgp 65001
 neighbor <R3>
  address-family ipv4 unicast
   route-policy AS_PREPEND out
```

The local AS is prepended *after* the RPL prepending takes place:

```
RP/0/0/CPU0:R3#show bgp ipv4 uni | be Network
Thu Dec  8 04:07:53.213 UTC
   Network            Next Hop            Metric LocPrf Weight Path
*> 10.10.10.10/32     10.2.3.2                               0 65001 100 65000 i
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ccnp-sp.gitbook.io/studyguide/routing/bgp/as-path-prepending-on-xe-and-xr.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
