Weight is a Cisco proprietary BGP attributes that can be used to select a certain path. Here’s what you need to know about weight:
- Weight is the first BGP attribute in the list.
- Cisco proprietary so you won’t find it on other vendor routers.
- Weight is not exchanged between BGP routers.
- Weight is only local on the router.
- The path with the highest weight is preferred.
Let me give you an example for BGP weight:
R1 in AS 1 can reach AS 3 through AS 2 or AS 4. If we want to ensure AS 2 is always used as the best path you can change the weight. In my example, the weight for the path to AS 2 is set to 500 and higher than the weight of 400 for AS 4. Let’s see what this looks like on real Cisco routers, this is the topology that I will use:
Above we have a simple scenario with two autonomous systems. R2 and R3 both have network 18.104.22.168/24 configured on their loopback0 interface and I’ll advertise that in BGP.
R1(config)#router bgp 1 R1(config-router)#bgp router-id 22.214.171.124 R1(config-router)#neighbor 192.168.12.2 remote-as 2 R1(config-router)#neighbor 192.168.13.3 remote-as 2
R2(config)#router bgp 2 R2(config-router)#bgp router-id 126.96.36.199 R2(config-router)#neighbor 192.168.12.1 remote-as 1 R2(config-router)#neighbor 192.168.23.3 remote-as 2 R2(config-router)#network 188.8.131.52 mask 255.255.255.0
R3(config)#router bgp 2 R3(config-router)#bgp router-id 184.108.40.206 R3(config-router)#neighbor 192.168.13.1 remote-as 1 R3(config-router)#neighbor 192.168.23.2 remote-as 2 R3(config-router)#network 220.127.116.11 mask 255.255.255.0
Above you’ll find the configuration for BGP. I configured the manual router ID for a reason. R2 and R3 have the same IP address on the loopback interface which means they would get the same router ID, and they would be unable to form a BGP neighbor adjacency. Let’s take a detailed look at R1:
R1#show ip bgp BGP table version is 2, local router ID is 192.168.13.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 *> 18.104.22.168/24 192.168.12.2 0 0 2 i * 192.168.13.3 0 0 2 i
Router R1 decided to use 192.168.12.2 as the next hop. All the BGP attributes are the same so it came down to the router ID to select a winner. Now let’s change this behavior using the weight attribute…
R1(config)#router bgp 1 R1(config-router)#neighbor 192.168.13.3 weight 500
You can configure weight per neighbor using the weight command. All prefixes from this neighbor will have a weight of 500.