BGP AS PATH PREPEND- BGP ATTRIBUTE - LAB

 Traffic Manipulation plays a vital role in BGP Protocol. One of the powerful attribute is BGP AS-Path prepend.  
By using this attribute, 
  • Manually configured AS path will be added to the particular neighbor.
  • BGP prefers the shortest AS path to get to a destination. Less the AS more the priority will be given.
Consider the below topology:
  • R1 prefers to use R2 router to reach the loopback IP of R4 (4.4.4.4/32).
  • Now we need to use AS-Path prepend attribute to make R1 prefers R3 to reach loopback 0 of R4.

R1 Interface Information:

R1#show ip int brief
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.12.1    YES NVRAM  up                    up
FastEthernet0/1            192.168.13.1    YES manual up                    up
Loopback0                  1.1.1.1         YES NVRAM  up                    up


R2 Interface Information:

R2#show ip int brief
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.12.2    YES NVRAM  up                    up
FastEthernet0/1            192.168.24.2    YES manual up                    up
Loopback0                  2.2.2.2         YES manual up                    up
R2#

R3 Interface Information:

R3#show ip interface brief
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.13.3    YES manual up                    up
FastEthernet0/1            192.168.34.3    YES manual up                    up
Loopback0                  3.3.3.3         YES manual up                    up
R3#

R4 Interface Information:

R4#show ip int brief
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            192.168.24.4    YES manual up                    up
FastEthernet0/1            192.168.34.4    YES manual up                    up
Loopback0                  4.4.4.4         YES manual up                    up
R4#

R1 BGP Configuration:
R1#show running-config | section router bgp
router bgp 1
 no synchronization
 bgp log-neighbor-changes
 redistribute connected
 neighbor 192.168.12.2 remote-as 2
 neighbor 192.168.13.3 remote-as 3
 no auto-summary
R1#

R2 BGP Configuration:
R2#show running-config | section router bgp
router bgp 2
 no synchronization
 bgp log-neighbor-changes
 redistribute connected
 neighbor 192.168.12.1 remote-as 1
 neighbor 192.168.24.4 remote-as 4
 no auto-summary
R2#

R3 BGP Configuration:
R3#show running-config | section router bgp
router bgp 3
 no synchronization
 bgp log-neighbor-changes
 redistribute connected
 neighbor 192.168.13.1 remote-as 1
 neighbor 192.168.34.4 remote-as 4
 no auto-summary
R3#

R4 BGP Configuration:
R4#show running-config | section router bgp
router bgp 4
 no synchronization
 bgp log-neighbor-changes
 redistribute connected
 neighbor 192.168.24.2 remote-as 2
 neighbor 192.168.34.3 remote-as 3
 no auto-summary
R4#

R1 BGP Table:

From the above table, 
  • Network 4.4.4.4/32 has two paths R2 and R3. Next-hop IP 192.168.12.2 refers to R2 and next-hop IP 192.168.13.3 refers to R3.
  • R1 prefer R2(Next hop - 192.168.12.2) to reach the destination. Best path is indicated by the symbol ">"
Now lets start configuring AS Path prepend to make R3 as the best path from R1 for the Network 4.4.4.4/32

Here, I have created a route-map named as AS-PATH-TEST. Next, I have used the command "match ip address 1" to match the access-list 1, and then if it matches I have set the as-path prepend as 100 200 300. I have created a second permit statement for the same route-map AS-PATH-TEST.

R2#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R2(config)#
R2(config)#route-map AS-PATH-TEST permit
R2(config-route-map)#match ip address 1
R2(config-route-map)#set as-path prepend 100 200 300
R2(config-route-map)#exit
R2(config)#route-map AS-PATH-TEST permit 20
R2(config-route-map)#end
R2#

You can also view the created c-map using the below command:

R2#show route-map
route-map AS-PATH-TEST, permit, sequence 10
  Match clauses:
    ip address (access-lists): 1
  Set clauses:
    as-path prepend 100 200 300
  Policy routing matches: 0 packets, 0 bytes
route-map AS-PATH-TEST, permit, sequence 20
  Match clauses:
  Set clauses:
  Policy routing matches: 0 packets, 0 bytes
R2#

Next create a access-list as below:

R2#conf terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R2(config)#access-list 1 permit host 4.4.4.4
R2(config)#end
R2#

You can view configured access-list using the below command.
R2#show access-lists
Standard IP access list 1
    10 permit 4.4.4.4
R2#

Applying the created route-map to bgp configuration.

R2#conf terminal
Enter configuration commands, one per line.  End with CNTL/Z.
R2(config)#
R2(config)#router bgp 2
R2(config-router)#neighbor 192.168.12.1 route-map AS-PATH-TEST out
R2(config-router)#end
R2#

Here, I have mapped the route-map AS-PATH-TEST as "OUT" to the neighbor R1 (192.168.12.1). so that it will advertise the additional AS number o its neighbor.

You need to clear the BGP session to take the newly applied configuration to take effect. 
In-order to clear the bgp session, use the command "clear ip bgp * soft in"


From the above image, you can see that:
  • The AS 100, 200 and 300 are added to the network 4.4.4.4/32 where the next -hop is 192.168.12.2
  • Best path changes to R3 (Next hop from R1 is 192.168.13.3) as the number of AS is less as compared to the path through R2.

Note: 
  • R1 sees that it has to pass AS 2, 100, 200, 300, 4 in order to reach 4.4.4.4/32 network through R2 as Next-hop. But if it passes through r3, it has to pass through only AS 3 and 4 which is less as compared to R2 as Next-hop.
  • Since we have configured route-map to match acl and then set the as-path prepend, only 4.4.4.4/32 (ACL 1) network will have the AS-PATH prepend. Other networks will not have it
  • If we haven't created/ used the acl in the route-map, as-path prepend will be added to all the networks that are advertised from R2 to R1. This can be seen in the BGP table of R1.
You can also look into my video tutorial in Tamil:
Thanks for reading this article.

Post a Comment