BGP AS path Prepending outbound routes
BGP AS path Prepending outbound routes is rich in features that you can have more control than on what IGP’s offer however, you can only have control on how the traffic leaves your autonomous system and can’t really control how other autonomous systems reach you. Other AS’es might have BGP policies that route the traffic in a way you don’t intend it to go. You don’t have control over those because, its their autonomous systems after all. However, there are work arounds which allow, an autonomous system affect the other autonomous systems, one of this is called BGP AS-path prepending. It is basically adding additional AS-paths by repeating your own AS number.
Consider the diagram below. By looking at the diagram, if you are familiar with BGP, the AS-path the networks from R4 will take towards R1 will be AS4, AS3 and then AS1. If all the attributes are set to the default values, most likely the AS-path attribute will determine which path to take. The more desirable path in this scenario is AS4, AS3, AS2 and then AS1 for the reason that there is a 100mbps link connecting AS1 and AS2 which makes traffic forwarding more efficient. But remember, unlike IGP’s, BGP doesn’t take to account the bandwidth.
In this scenario we are in AS1 and we make AS2 the more desirable path for AS4 to reach us using AS-path prepending.
Checking on R4 we will see how it gets to R1.
Just as we guessed, it would take AS3 then AS1 which is the shortest path based on BGP attributes. Now we will configure AS-prepending on R1 for R4 to take the AS3, AS2 then AS1 path. [bodylink]
R1(config)#route-map ASPREPEND permit 10 R1(config-route-map)#set as-path prepend 1 1 1 R1(config)#route-map ASPREPEND permit 20
We made it 1 1 1 cause it would only 2 AS paths to reach R1 from R4 through R3. We will make that AS-path longer and less desirable. We will apply this route map we created to the neighbor-ship peering between R1 and R3.
R1(config)#router bgp 1
R1(config-router)#neighbor 184.108.40.206 route-map ASPREPEND out
The reason its in the outbound direction because R1 is advertising the subnets. Let’s clear the bgp process in R1 to make the changes. Then lets see what happened to the AS-path in R4.
Ok, you can see the difference now, its now taking 3-2-1. This is because it received an advertisement from R3 about the best path. BGP only advertises the best path to a network to its neighbor. Since R3 is seeing the AS_Path going to R1 is longer, it now takes AS2 to get to R1. Lets see what happened to the BGP table after applying the route map.
Three 1’s were added to the AS_Path based on what we put on the route-map, so from the AS-path values, R3 will not go directly to R1 but will take R2 now instead.
Now what if we want traffic to 220.127.116.11 to take A3 directly and traffic to 18.104.22.168 take AS3 then AS2 from R4. We will create an access-list TAKER2 and modify the route-map to match the condition.
R1(config)#ip access-list extended TAKER2 R1(config-ext-nacl)#permit ip host 22.214.171.124 any R1(config)#route-map ASPREPEND permit 10 R1(config-route-map)#match ip address TAKER2 R1(config-route-map)#set as-path prepend 1 1 1
Let’s check what happened to R3
Cool, you can see the difference with the ACL. Now 126.96.36.199 in R3 has prepend but 188.8.131.52 has no prepend. Finally, lets check R4.
From R4 traffic to 184.108.40.206 will pass through AS2 but to 220.127.116.11 it will go directly to R3 then R1.