BGP Weight

BGP Weight is the first BGP attribute if we dive deep into BGP’s algorithm of best path selection followed by Local_Preference & aggregate (detailed in my first post in BGP section). Weight is vendor specific (Cisco proprietary) so it is found only on Cisco routers. Weight is always local on a router and it is not exchanged between BGP routers. The path with the highest weight is always preferred.

The range of Weight is 0-65535 and it defaults to 0 always. i.e. The default weight for learned routes is 0 and the default weight for a locally originated route is 32768. We use Weight when we want to influence our BGP routing Outwards on a cisco router.

There are different methods to set weight in BGP. It can be set either through neighbor command, route maps or via the AS-PATH access list.

 

Configuration Example

Let me explain it through a simple example in below.

Here we have three Routers. R1 is receiving a route for 2.2.2.2/32 from both R2 & R3. In normal conditions, it will prefer the route from fa0/0. We can influence this selection by using higher Weight towards R3.

 

First, lets establish simple BGP as in below:

 

atech_R1
atech_R1(config)#router bgp 100
atech_R1(config-router)#bgp router-id 1.1.1.1
atech_R1(config-router)#bgp log-neighbor-changes
atech_R1(config-router)#neighbor 12.12.12.2 remote-as 200
atech_R1(config-router)#neighbor 13.13.13.3 remote-as 200

 

atech_R2
atech_R2(config)#router bgp 200
atech_R2(config-router)#bgp router-id 2.2.2.2
atech_R2(config-router)#bgp log-neighbor-changes
atech_R2(config-router)#network 2.2.2.2 mask 255.255.255.255
atech_R2(config-router)#neighbor 3.3.3.3 remote-as 200
atech_R2(config-router)#neighbor 3.3.3.3 update-source Loopback0
atech_R2(config-router)#neighbor 3.3.3.3 next-hop-self
atech_R2(config-router)#neighbor 12.12.12.1 remote-as 100

 

atech_R3
atech_R3(config)#router bgp 200
atech_R3(config-router)#bgp router-id 3.3.3.3
atech_R3(config-router)#bgp log-neighbor-changes
atech_R3(config-router)#neighbor 2.2.2.2 remote-as 200
atech_R3(config-router)#neighbor 2.2.2.2 update-source Loopback0
atech_R3(config-router)#neighbor 2.2.2.2 next-hop-self
atech_R3(config-router)#neighbor 13.13.13.1 remote-as 100

Now, if we check the route at R1:

atech_R1#sh ip bgp
BGP table version is 3, 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 foundNetwork        Next Hop     Metric   LocPrf     Weight     Path
*>2.2.2.2/32   12.12.12.2                        0         200 i
*              13.13.13.3                        0         200 i

We can see that although it is receiving 2.2.2.2/32 route from both R2 & R3 but it is preferring the route from R2 by default.Now, if we increase the weight on R1 towards R3:

atech_R1(config)#router bgp 100
atech_R1(config-router)# neighbor 13.13.13.3 weight 100

 

atech_R1#sh ip bgp
BGP table version is 3, 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 foundNetwork       Next Hop    Metric LocPrf Weight Path
*> 2.2.2.2/32 13.13.13.3                100    200 i
*             12.12.12.2  0             0      200 i

 

As in above, R1 is preferring route from R3 now because it has more weight as compared to R2. So, we can influence the BGP route selection by changing the weight.

We can achieve the same results by using Route Maps which gives more granularity & control upto prefix level. The route map simply captures all the desired routes & apply it on the neighbor command.

 

 

I hope this article has been helpful to you. You suggestion, comments & questions are welcomed. Please write in comments below if any…

Leave a Reply

12 Comments on "BGP Weight"

avatar
  Subscribe  
newest oldest most voted
Notify of
Sienna Matilda
Guest

How is weight diff from Multi Exit Disc / MED?

Eva Lucy
Guest

nice explanation

Scarlett Harper
Guest

Is there any other way of setting the weight as well in addition to the above method you mentioned

Zümra Esmanur
Guest

Like your style of explanation

Ayse Buglem
Guest

What are discretionary attributes?