#

Friday, August 18, 2017

BGP Path Selection by AS-Path

AS-Path is the 4th BGP attribute in the list..

(1) Can use to choose the best path for inbound traffic which means influence routing in eBGP neighbors..
(2) Route with the shortest AS-Path is better..

Normally this is the real attribute which is by default working on Internet.. However we can manipulate the traffic by prepending the AS path.. Which means we can add our own AS number multiple times so the AS-path becomes longer. From this method we can tell eBGP neighbors to send the traffic to specific routes from the path we need.

Let's see an example..

















Basic routing (EIGRP) configurations in AS-1

R1(config)#router eigrp 10
R1(config-router)#network 192.168.12.0
R1(config-router)#network 192.168.13.0
R1(config-router)#network 1.0.0.0

R2(config)#router eigrp 10
R2(config-router)#network 192.168.12.0
R2(config-router)#network 2.0.0.0

R3(config)#router eigrp 10
R3(config-router)#network 192.168.13.0
R3(config-router)#network 3.0.0.0

Basic routing (static) on R1 to reach the R2-R4 & R3-R4 links

R1(config)#ip route 192.168.24.0 255.255.255.0 192.168.12.2
R1(config)#ip route 192.168.34.0 255.255.255.0 192.168.13.3

Basic BGP configurations

R1(config)#router bgp 1
R1(config-router)#neighbor 2.2.2.2 remote-as 1
R1(config-router)#neighbor 2.2.2.2 update-source Loopback0
R1(config-router)#neighbor 3.3.3.3 remote-as 1
R1(config-router)#neighbor 3.3.3.3 update-source Loopback0

R2(config)#router bgp 1
R2(config-router)#neighbor 1.1.1.1 remote-as 1   
R2(config-router)#neighbor 1.1.1.1 update-source lo0
R2(config-router)#neighbor 3.3.3.3 remote-as 1           
R2(config-router)#neighbor 3.3.3.3 update-source lo0
R2(config-router)#neighbor 192.168.24.4 remote-as 2
R2(config-router)#network 192.168.12.0 mask 255.255.255.0
R2(config-router)#network 192.168.13.0 mask 255.255.255.0

R3(config)#router bgp 1
R3(config-router)#neighbor 1.1.1.1 remote-as 1
R3(config-router)#neighbor 1.1.1.1 update-source lo0
R3(config-router)#neighbor 2.2.2.2 remote-as 1       
R3(config-router)#neighbor 2.2.2.2 update-source lo0
R3(config-router)#neighbor 192.168.34.4 remote-as 2
R3(config-router)#network 192.168.12.0 mask 255.255.255.0
R3(config-router)#network 192.168.13.0 mask 255.255.255.0

R4(config)#router bgp 2
R4(config-router)#neighbor 192.168.24.2 remote-as 1
R4(config-router)#neighbor 192.168.34.3 remote-as 1

In red lines, you can see that I have advertised R1-R2 & R1-R3 links in both R2 & R3. This is possible since R2 and R3 has valid routes to those subnets in their routing tables.

Now let's see what R4 can see..










Because of the Metric values, the best path to 192.168.12.0 is chosen through R2 & the best path to 192.168.13.0 is chosen through R3..

This means that the routers in AS-2 sends traffic to R2 to reach 192.168.12.0 network and sends traffic to R3 to reach 192.168.13.0 network..








From AS-1, we can change the routing of AS-2 router (R4) by using route maps..

Here is how to change the routing path to 192.168.12.0 network..

R2(config)#access-list 10 permit 192.168.12.0 255.255.255.0

R2(config)#route-map AS-PATH-R2 permit 10
R2(config-route-map)#match ip address 10
R2(config-route-map)#set AS-path prepend 1 
R2(config-route-map)#route-map AS-PATH-R2 permit 20

R2(config-route-map)#router bgp 1
R2(config-router)#neighbor 192.168.24.4 route-map AS-PATH-R2 out 












Now you can see that the path is changed in R4. Notice that the Path is 1 1 i through R2 and it is 1 i through R3. We only added one "1" in the route map, the other 1 came from the default behavior. You can see even the Metric is large, path from R3 is preferred because AS-Path comes before Metric in BGP..

You can tweek the route to 192.168.13.0 from R3 using a route map too.

Note:- 

This is pointless to be used with iBGP neighbors because they do not update the AS path..
The AS number use to prepend must be the router's AS number. Cannot use any arbitrary number..
Also this can be used both inbound & outbound routing updates to an eBGP neighbor..

No comments:

Post a Comment