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.
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.255Then 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#
as-pathaccess lists and
match as-pathroute-map statement. Thanks for reading!