Pages

Wednesday, May 30, 2012

Configuring BGP - AS PATH PREPEND

Imagine you have 2 ISPs coming into a single router and you have a BGP relationship with both ISPs. One is a 100meg connection from AT&T and the other is a slower internet connection from a local ISP. Your manager requests that we should be using the 100meg connection for outgoing and incoming traffic.Well the outgoing traffic is very easy to manipulate using IGP, metric, PBR, route-maps or whatever your heart desires. But how do we control the inbound traffic? There are a few options available to us, however in this blogtorial we will see how we can manipulate inbound traffic using as path-prepend.

Consider this simple topology and let's get started. 

To understand as path-prepend we must first understand how BGP selects a path using the path selection algorithm. I will not go into the whole list but the first few are: 
  • Is the next-hop reachable?
  • Highest weight *Cisco proprietary* - Although many vendors are implementing it
  • Prefer the path with the highest local preference (preference is only internal and does not get sent to eBGP neighbors)
  • Prefer the path with the shortest AS PATH
Prefer the shortest AS PATH is the basis behind as path-prepend. Since the shortest as path will be preferred the idea is to prepend your own AS to the less preferred ISP before advertising the route (NLRI). Note that the AS PATH is a well known mandatory PA (Path Attribute) meaning it needs to be supported by all implementation for BGP and this PA should be advertised to all other neighbors. 

Now that you have a basic understanding let's see it in action. 

First let's get the basic interface settings configured.




Second let's get the BGP configured. Note that in this 2 ISP setup I am not configuring any filtering (incoming or outgoing) however it is good practice to do so.




We now have BGP peer and both ISPs are seeing the advertised routes. As expected, each ISPs is preferring the direct connection that they have to to the Enterprise Edge to get to 3.3.3.0/24.



Now let's see how can use as path-prepend to always prefer the 100meg ATT connection for incoming traffic.

  1. Create an access-list to match 3.3.3.0/24. You can also create a prefix list. 
  2. Create a route-map to match the access-list and set as path-prepend and prepend your own AS. 
  3. Apply this route map to the existing peer (slow internet peer).
  4. Clear the bgp relationship using clear ip bgp 2.2.2.2. 
Show commands to verify that the changes took effect. Please note that BGP is slow and may take a minute or so to converge.

Note that to ISPB now prefers to go over the ATT connection (ISPA) to get to 3.3.3.0/24 (advertised by R1) than the direct connection it has to R1. Reason being -- the shortest AS PATH (2,1) is only 2 hops away where as the direct connection lists 4 hops (AS) away (1, 1, 1, 1). So the shortest AS path route gets installed into the routing table.

Many more articles to come so stay tuned. If you like what you read please comment/like/+1/join this site --->changes

2 comments: