The fourth BGP attribute is called AS Path:
- BGP prefers the shortest AS path to get to a destination. Less is more!
- We can manipulate this by using AS path prepending.
Let me show you an example:

In my example AS 1 wants to make sure traffic enters the autonomous system through R2. We can add our own autonomous system number multiple times so the as-path becomes longer. Since BGP prefers a shorter AS path we can influence our routing. This is called AS path prepending. Let’s see what this looks like on Cisco routers, this is the topology that I will use:

Above we have 3 routers. R1 and R3 are both in AS 1 advertising the same network (1.1.1.0/24) to R2. We can use AS Path prepending to make R2 prefer a certain path.
R1(config)#router bgp 1
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#neighbor 192.168.12.2 remote-as 2
R3(config)#router bgp 1
R3(config-router)#bgp router-id 3.3.3.3
R3(config-router)#neighbor 192.168.23.2 remote-as 2
R2(config)#router bgp 2
R2(config-router)#neighbor 192.168.12.1 remote-as 1
R2(config-router)#neighbor 192.168.23.3 remote-as 1
First, we’ll configure BGP between the three routers.
R1(config)#router bgp 1
R1(config-router)#network 1.1.1.0 mask 255.255.255.0
R3(config)#router bgp 1
R3(config-router)#network 1.1.1.0 mask 255.255.255.0
And we’ll advertise both networks in BGP.
R2#show ip bgp
BGP table version is 2, local router ID is 192.168.23.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
* 1.1.1.0/24 192.168.23.3 0 0 1 i
*> 192.168.12.1 0 0 1 i
In the table above you can see that it prefers 192.168.12.1 as its path. Let’s change the AS path so that we’ll use 192.168.23.3 as the preferred path.
R1(config)#route-map PREPEND permit 10
R1(config-route-map)#set as-path prepend 1 1 1 1 1
R1(config-route-map)#exit
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 route-map PREPEND out
Here’s an example for you. First, create a route-map and use set as-path prepend to add your own AS number multiple times.
Don’t forget to add the route-map to your BGP neighbor configuration and since you are sending this to your remote neighbor it should be outbound!
Don’t forget to add the route-map to your BGP neighbor configuration and since you are sending this to your remote neighbor it should be outbound!
R2#show ip bgp
BGP table version is 2, local router ID is 192.168.23.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 1.1.1.0/24 192.168.23.3 0 0 1 i
* 192.168.12.1 0 0 1 1 1 1 1 1 i
Now we see that 192.168.23.3 is the next hop IP address that we use. You can also see that the AS Path has become longer for the second entry.
That’s all there is for now! If you have any questions just leave a comment…
hostname R1
!
interface Loopback 0
ip address 1.1.1.1 255.255.255.0
!
interface fastEthernet2/0
ip address 192.168.12.1 255.255.255.0
!
router bgp 1
bgp router-id 1.1.1.1
neighbor 192.168.12.2 remote-as 2
network 1.1.1.0 mask 255.255.255.0
neighbor 192.168.12.2 route-map PREPEND out
!
route-map PREPEND permit 10
set as-path prepend 1 1 1 1 1
end
hostname R2
!
interface fastEthernet0/0
ip address 192.168.12.2 255.255.255.0
!
interface fastEthernet1/0
ip address 192.168.23.2 255.255.255.0
!
router bgp 2
neighbor 192.168.12.1 remote-as 1
neighbor 192.168.23.3 remote-as 1
!
end
hostname R3
!
interface Loopback 0
ip address 1.1.1.1 255.255.255.0
!
interface fastEthernet2/0
ip address 192.168.23.3 255.255.255.0
!
router bgp 1
bgp router-id 3.3.3.3
neighbor 192.168.23.2 remote-as 2
network 1.1.1.0 mask 255.255.255.0
!
end
No comments:
Post a Comment