BGP Weight manipulation with Route Maps

Written on by admin on. Posted in BGP, Route Maps

For advanced control over BGP Weight attribute, Route Maps can be used. To recall, Weight attribute is used by BGP to break the tie when there are more routes to the same network. Route with the highest weight is preferred. Weight attribute is a Cisco feature, it has local meaning and it is not transmitted to other routers.

In this example we will discuss about how to change BGP Weight attribute by using Route Maps. Topology is the same as in the other article where we discussed about BGP Weight. See it below.

BGP-weight-scenario

In the picture you see that WEST router in AS 65520 receives the routes advertised by EAST router in AS 65523 (172.16.0.0/24 and 192.168.100.0/24) over ISP-1 and ISP-2 routers. BGP will choose to reach those routes over ISP-1 or ISP-2. Let’s assume that all configurations are already made, and all settings are left default. If so, let’s check bgp table of WEST router:

WEST#show ip bgp 
BGP table version is 5, local router ID is 10.0.1.1
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
*  172.16.0.0/24    10.0.0.2                               0 65521 65523 i
*>                  10.0.1.2                               0 65522 65523 i
*  192.168.100.0    10.0.0.2                               0 65521 65523 i
*>                  10.0.1.2                               0 65522 65523 i
WEST#

As you can see, BGP weight attribute is “0″ for updates received from neighbors. It chose the path over 10.0.1.2 as the best one (marked with “>”), most likely because 10.0.1.2 was the first who advertised the routes received from EAST router. The routes to EAST networks over 10.0.1.2 will be put in routing table by BGP.

Further I will change the weight on WEST router  in such a manner, that packets to 192.168.100.0/24 network will be sent over ISP-1, and packets to 172.16.0.0/24 will be sent over ISP-2 router.

Firstly, we need two access lists to match networks contained in BGP updates:

WEST(config)#access-list 1 permit 192.168.100.0 0.0.0.255
WEST(config)#access-list 2 permit 172.16.0.0 0.0.0.255
Then two route maps which I named ISP-1 and ISP-2:
WEST(config)#route-map ISP-1 permit 10
WEST(config-route-map)# match ip address 1
WEST(config-route-map)# set weight 100
WEST(config-route-map)#route-map ISP-1 permit 20

WEST(config)#route-map ISP-2 permit 10
WEST(config-route-map)# match ip address 2
WEST(config-route-map)# set weight 100
WEST(config-route-map)#route-map ISP-2 permit 20

Both route maps contain sequence number 10 and 20. Sequence 10 is used to match access lists (route map ISP-1 matches access list 1, ISP-2 matches access list 2). Also in sequence 10 is changed the weight to 100 for those updates matched by corresponding access list. Sequence 20 is empty and is used to avoid implicit deny at the end of route-map, i.e., to keep the updates that were not matched by the access list.

Next step is to apply route maps to neighbors:

WEST(config)#router bgp 65520
WEST(config-router)#neighbor 10.0.0.2 route-map ISP-1 in
WEST(config-router)#neighbor 10.0.1.2 route-map ISP-2 in

And that’s all! Because we changed local router policies we need to make router to generate new inbound updates from stored table.

WEST#clear ip bgp * soft in

Now, the best route for 192.168.0.0/24 will be through ISP-1, for 172.16.0.0/24 through ISP-2. Let’s check again:

WEST#show ip bgp 
BGP table version is 8, local router ID is 10.0.1.1
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
*  172.16.0.0/24    10.0.0.2                               0 65521 65523 i
*>                  10.0.1.2                             100 65522 65523 i
*  192.168.100.0    10.0.1.2                               0 65522 65523 i
*>                  10.0.0.2                             100 65521 65523 i
WEST#

You can see the results are as expected. Below you see routing table on WEST router:

WEST#show ip route 

       ... output omitted ...

Gateway of last resort is not set

     172.16.0.0/24 is subnetted, 1 subnets
B       172.16.0.0 [20/0] via 10.0.1.2, 00:53:03
     10.0.0.0/24 is subnetted, 2 subnets
C       10.0.0.0 is directly connected, FastEthernet0/0
C       10.0.1.0 is directly connected, FastEthernet0/1
B    192.168.100.0/24 [20/0] via 10.0.0.2, 00:33:32
WEST#
That’s it, with route maps also can be changed the weight for updates generated from a specific AS by using as-path access lists and match as-path route-map statement. Thanks for reading!

14309 views

Comments (5)

  • Jitendra Choudhary

    |

    Hi , nice informative.

    Thanks….

    can you help me how can get ping west to 192.168.100.1 looback…

    thanks in advance…..

    Reply

  • jitendra

    |

    Dear Admin,

    i need help regarding this lab. if i want to ping from west router to 172.16.0.1 or 192.168.100.1 both network’s are unreachable ….. why

    but if i m ping ISP-1 it’s accessible.

    thanks for lab ..i hope u understand my query.

    Reply

    • admin

      |

      Hi Jitendra,

      172.16.0.1 and 192.168.100.1 are both advertised in BGP by EAST router as they are in a different AS. First, establish E-BGP peering between all directly connected routers and then advertise those routes in BGP. In my case BGP config on EAST router looks like this:

      router bgp 65523
      no synchronization
      bgp log-neighbor-changes
      network 172.16.0.0 mask 255.255.255.0
      network 192.168.100.0
      neighbor 10.0.2.2 remote-as 65522
      neighbor 10.0.3.2 remote-as 65521
      no auto-summary

      Download GNS lab from this article and try to add it in your GNS, or just look through config files in the attached lab.

      Reply

  • Muhammad Nasrullah

    |

    Sir you have set weight for both router 192.168.1.0 and 172.16.0.0 how this route map will decide that this network to isp 1 and other to isp 2

    Reply

  • muhammad ansrullah

    |

    set weight 100 for both router 192.168.0.0 and 172.16.0.0

    Reply

Leave a comment


+ seven = 15