BGP AS-PATH Prepend Configuration Example [GNS3 Lab]

BGP AS-PATH Prepend Configuration Example [GNS3 Lab]

Topology

In this setup, we will first check the BGP AS-PATH attribute and its impact on Path selection. After that, we will modify the AS-PATH attribute, to manipulate the Path.

In the output below from router R1, we can see that neighbor Router R3 (172.16.30.2) was selected for the route 5.5.5.5/32 because it has the shortest AS Path segment (default behavior):

R1#show ip bgp
BGP table version is 3, local router ID is 172.16.30.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
              x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *>  1.1.1.1/32       0.0.0.0                  0         32768 i
 *   5.5.5.5/32       172.16.20.2                            0 65002 65004 65005 i
 *>                   172.16.30.2                            0 65003 65005 i

R1#show ip route
Gateway of last resort is not set

      1.0.0.0/32 is subnetted, 1 subnets
C        1.1.1.1 is directly connected, Loopback0
      5.0.0.0/32 is subnetted, 1 subnets
B        5.5.5.5 [20/0] via 172.16.30.2, 05:30:23
      172.16.0.0/16 is variably subnetted, 4 subnets, 2 masks
C        172.16.20.0/30 is directly connected, FastEthernet0/0
L        172.16.20.1/32 is directly connected, FastEthernet0/0
C        172.16.30.0/30 is directly connected, FastEthernet0/1
L        172.16.30.1/32 is directly connected, FastEthernet0/1


Inbound AS-PATH prepend

Let’s try to manipulate this Path selection by prepending AS Paths in R1.

Configurations:

R1#
router bgp 65001
 bgp log-neighbor-changes
 network 1.1.1.1 mask 255.255.255.255
 neighbor 172.16.20.2 remote-as 65002
 neighbor 172.16.30.2 remote-as 65003
 neighbor 172.16.30.2 route-map Prep-me in

route-map Prep-me permit 10
 set as-path prepend 65001 65001


Verifications:

R1#show ip route

      1.0.0.0/32 is subnetted, 1 subnets
C        1.1.1.1 is directly connected, Loopback0
      5.0.0.0/32 is subnetted, 1 subnets
B        5.5.5.5 [20/0] via 172.16.20.2, 00:13:22
      172.16.0.0/16 is variably subnetted, 4 subnets, 2 masks
C        172.16.20.0/30 is directly connected, FastEthernet0/0
L        172.16.20.1/32 is directly connected, FastEthernet0/0
C        172.16.30.0/30 is directly connected, FastEthernet0/1
L        172.16.30.1/32 is directly connected, FastEthernet0/1
R1#
R1#show ip bgp
BGP table version is 2, local router ID is 1.1.1.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
              x best-external, a additional-path, c RIB-compressed,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found

     Network          Next Hop            Metric LocPrf Weight Path
 *   5.5.5.5/32       172.16.30.2                            0 65001 65001 65003 65005 i
 *>                   172.16.20.2                            0 65002 65004 65005 i

we can see that the path via Router R2 (172.16.20.2) has now a shorter AS-PATH segment and it was selected as the best path in R1, therefore installed in the routing table.


But what about the return traffic:

At this stage, we are able to manipulate the outgoing traffic from R1 to R5 by preferring R2, but for the return traffic from R5 to R1, it still gonna use the Path throw R3 router:


R5#show ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *   1.1.1.1/32       172.16.45.1                            0 65004 65002 65001 i
 *>                   172.16.50.1                            0 65003 65001 i
 *>  5.5.5.5/32       0.0.0.0                  0         32768 i

R5#show ip route
      1.0.0.0/32 is subnetted, 1 subnets
B        1.1.1.1 [20/0] via 172.16.50.1, 00:19:16
      5.0.0.0/32 is subnetted, 1 subnets
C        5.5.5.5 is directly connected, Loopback0
      172.16.0.0/16 is variably subnetted, 4 subnets, 2 masks
C        172.16.45.0/30 is directly connected, FastEthernet0/0
L        172.16.45.2/32 is directly connected, FastEthernet0/0
C        172.16.50.0/30 is directly connected, FastEthernet0/1
L        172.16.50.2/32 is directly connected, FastEthernet0/1


we can manipulate that by configuring an outbound AS-PATH prepending on R1.

Outbound AS-PATH prepend

Configuration:

R1#
router bgp 65001
 neighbor 172.16.30.2 route-map Prep-me out

route-map Prep-me permit 10
 set as-path prepend 65001 65001


Verifications:

R5#show ip bgp

     Network          Next Hop            Metric LocPrf Weight Path
 *>  1.1.1.1/32       172.16.45.1                            0 65004 65002 65001 i
 *                    172.16.50.1                            0 65003 65001 65001 65001 i
 *>  5.5.5.5/32       0.0.0.0                  0         32768 i

R5#show ip route
      1.0.0.0/32 is subnetted, 1 subnets
B        1.1.1.1 [20/0] via 172.16.45.1, 00:03:27
      5.0.0.0/32 is subnetted, 1 subnets
C        5.5.5.5 is directly connected, Loopback0
      172.16.0.0/16 is variably subnetted, 4 subnets, 2 masks
C        172.16.45.0/30 is directly connected, FastEthernet0/0
L        172.16.45.2/32 is directly connected, FastEthernet0/0
C        172.16.50.0/30 is directly connected, FastEthernet0/1
L        172.16.50.2/32 is directly connected, FastEthernet0/1


With AS-PATH Prepend, we can influence the incoming and outgoing traffic, so both use the same Path:

Bilel Ameur

Enthusiastic Network Engineer specializing in Cisco ACI, passionate about solving challenges. A lifelong learner who loves gaining and sharing knowledge. Profile: https://www.linkedin.com/in/bilel-ameur-71116b2b5
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x