• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

Roger Perkin

Network Automation Architect

  • Network Automation
    • Network Automation Courses
    • Ansible Automation Platform
    • Ansible Workshop
    • What is Network Automation?
    • Network Automation Tools
    • ContainerLab
    • Ansible Training
      • What is Ansible Software?
      • Ansible Tutorial for Beginners
      • Ansible Network Automation
      • Ansible Hosts File
    • Python Network Automation
      • Nornir
      • Python Network Automation Course
      • Python for Network Engineers
      • Python VENV / Virtual Environment Tutorial
      • Python Tutorial for Beginners
      • pyATS
    • Network Source of Truth
      • NetBox Training
      • Infrahub
    • NetDevops
    • DevOps Tutorial
      • Git Training
      • Terraform Training
      • Linux Training
      • Kubernetes Training
      • Devops Training Course
      • Azure Devops Training
    • Terraform
    • GIT
      • Git Commands
      • What is GitHub?
    • Docker Training
    • Confluence
    • Microsoft Azure
  • Cisco
    • ISE
    • SD WAN Training
    • Password Recovery
    • Software-Upgrade-Guides
    • BGP
    • Data Center
    • WIRELESS
  • CCIE
  • Blog
  • About
    • My Red Special Guitar
  • Contact

BGP Weight Attribute Configuration Tutorial

Home » BGP Protocol

BGP Weight Attribute Explained

The BGP weight attribute is the first on the list in the BGP best path algorithm

  1. Prefer the path with the highest WEIGHT.
    Note:  BGP Weight is a Cisco-specific parameter. It is local to the router on which it is configured.

So if you want to influence your BGP routing outbound on a cisco router you can set the weight attribute. However this value is only locally significant on the router and the information is not passed between neighbors. This solution does not scale very well and in most cases local preference is used as this attribute is passed between iBGP neighbors.

There are some circumstances where weight is used and in the following examples I will show you how to configure it.

Note: The default weight for learned routes is 0 and the default weight for a locally originated route is 32768

Using the topology below lets go through a bgp weight configuration example.

bgp weight attribute topology

BGP Weight Attribute Configuration

Each router in this topology is addressed with its router number as the last octet .eg all interfaces on R1 end in .1 and on R5 .5 etc

Each router has a loopback configured and advertised into BGP R1=1.1.1.1, R2=2.2.2.2 etc

All routers are peering with each other using eBGP

Lets take a look at the BGP output on R1 to see its view of the network.

Using the command sh ip bgp we can see all the prefixes in BGP the chosen route is the one with the < beside it.

In this case for R1 to get to R6 it has chosen the path through R4

sh ip bgp weight

You can see for the prefix 6.6.6.6/32 there are two paths one through 10.0.15.4 (R5) and the other through 10.0.14.4 (R4)

The weights for both of these routes are 0, you can also see for the prefix 1.1.1.1 (loopback on R1) that the weight is 32768 this is because it is a locally generated route.

You might be wondering why R1 has chosen to route via R5? If we take a moment away from BGP Weight and just step through the BGP best path algorithm you we will work it out.

  1. Prefer the path with the highest Weight – Both Weights are equal so move onto step2
  2. Prefer the path with the highest Local Preference – Local preference is the same for both routes
  3. Prefer the path that was locally originated – Same for both
  4. Prefer the path with lowest AS Path – Both routes have an AS path of 2
  5. Prefer the path with the lowest origin type – Same for both
  6. Prefer the path with the lowest MED – Skipped
  7. Prefer eBGP over iBGP – both routes are eBGP
  8. Prefer the path with the lowest IGP metric to the next BGP Hop – Same for both
  9. Check if multipath is enabled – Skipped
  10. When both paths are external prefer the oldest one – This is the tiebreaker!

BGP Best Path Algorithm from Cisco 

So after all of that we have come down to the oldest route in the table, so basically the one that loaded first.

To prove that we can restart the bgp process on R4 to make R5 the oldest route. On R4 I have done a clear ip bgp * This now makes the route through R5 the oldest one and is preferred.

bgp both paths

Back to BGP weight! – we now want to ensure that whatever happens R1 will route through R4 (10.0.14.4) to get to 6.6.6.6

To achieve that using weight we have two options.

  1. Set the Weight Attribute on the neighbor – this will affect all routes learnt from that neighbor
  2. Using a route-map and an access list only match specific routes to have the weight set on.

First lets set the weight using the neighbor statement.

Under BGP enter the following command – neighbor 10.0.14.4 weight 100 

R1#conf t
 Enter configuration commands, one per line. End with CNTL/Z.
 R1(config)#router bgp 1
 R1(config-router)#neighbor 10.0.14.4 weight 100
 R1(config-router)#end
 R1#
 R1#sh run | sec router bgp
 router bgp 1
 bgp log-neighbor-changes
 network 1.1.1.1 mask 255.255.255.255
 network 10.0.14.0 mask 255.255.255.0
 network 10.0.15.0 mask 255.255.255.0
 neighbor 10.0.14.4 remote-as 4
 neighbor 10.0.14.4 weight 100
 neighbor 10.0.15.5 remote-as 5
 R1#

You can see now the weight attribute is configured for the neighbor 10.0.14.4 (R4) This will affect all routes learnt from R4 lets take a look at the bgp table now.

You will also notice that all prefixes received from R4 have also had their weight changed to 100

bgp routes changed

So the other option is to set the weight on a per prefix basis using a route-map

For this example we only want to set the weight for the 6.6.6.6/32 prefix

First we need to match this prefix in an access list

R1(config)#access-l 1 permit 6.6.6.6 0.0.0.0
R1(config)#route-map SET-WEIGHT permit
R1(config-route-map)#match ip address 1
R1(config-route-map)#set weight 100
R1(config-route-map)#route-map SET-WEIGHT permit 20

This is now applied to the neighbor statement for R4 – we also need to remove the previous weight attribute

R1(config)#router bgp 1
R1(config-router)#no neighbor 10.0.14.4 weight 100
R1(config-router)#neighbor 10.0.14.4 route-map SET-WEIGHT in

If we just do a route-refresh you can see the attributes change

R1#clear ip bgp * soft in

This does a route refresh with the new attributes but does not take down the BGP neighbor

Take a look at the changes below

bgp weight using route-map and access-list

You can see now that we have changed the weight attribute for the 6.6.6.6/32 prefix only. All other routes have the default weight of 0.

Good luck with your studies!

To compare the differences of BGP Weight vs Local Preference please read my other posts on BGP

  • BGP Local Preference Explained
  • BGP Listen Range command
  • BGP Weight attribute
  • BGP Confederation vs Route Reflector
  • What is BGP synchronization?
  • BGP Update source command
Category: BGP ProtocolTag: bgp, bgp weight, CCIE
ansible course for network engineers
Get Access to my Ansible Course NOW
Previous Post:bgp route serverPeering with Route Servers
Next Post:Cisco Access Point Default Passwordcisco 3700 access point

Reader Interactions

Comments

  1. Syed

    November 24, 2015 at 9:56 pm

    Roger!

    I am a rookie in BGP, but in field for long time. One of my hobby is reading networking articles and tutorials where i can advance myself with these free knowledge base blogs. I know there are very few peoples who writes these blogs in a simple form. YOU ARE ONE OF THESE GUYS!!!!!. Please keep doing the great work. I have tested this topology and it’s on the $$$$.. Have a great thanksgiving!!
    syed

    • Roger Perkin

      November 25, 2015 at 5:31 pm

      Thank you for the kind comments Syed. I am glad it has helped build your knowledge of BGP

  2. Mathieu Zandji

    February 29, 2016 at 2:21 pm

    Thanks for a simple and clear explanation for me as CCNP learner. Hopping to get more for other topic..

  3. Peter Kangunga

    August 29, 2016 at 7:52 am

    Roger!

    This is great, Nice and simple to understand. Please keep on doing the good job !!!!!!!!!!!!!!

  4. Ahamed

    March 19, 2017 at 3:37 pm

    ROJER, I HAD DIFFICULTIES IN UNDERSTANDING THE WEIGHT AND LOCAL PREFERENCE. NOW I UNDERSTAND WELL AND CLEAR TO ME. PLEASE POST SOME TOPICS ON BGP OR SEND SOME LINKS TO THE EMAIL.

    Thanks
    Ahamed

    • Roger Perkin

      March 20, 2017 at 1:56 pm

      Ahamed,

      All my BGP posts can be found here https://www.rogerperkin.co.uk/bgp/

      Regards,
      Roger

  5. Rideep

    October 13, 2017 at 7:41 am

    Really really liked the topic. easy understanding. Thanks

  6. SUdhakar Sharma

    August 2, 2019 at 11:02 am

    Well done .. Its easy to understand .. Keep writing the blogs with topology and example . You are helping many people . God Bless you 🙂

    • Roger Perkin

      August 21, 2019 at 7:45 pm

      Thanks Sudhakar

Sidebar

Hi I'm Roger Perkin,
Based in the UK working as a Network Automation Architect, CCIE #50038
About Roger | Twitter | Linkedin

python course for network engineers

Topics

Network Automation
Ansible
Python for Network Automation
CCIE
Cisco ISE
F5 Certification
BGP
OSPF
Network Automation Conferences
auvik promo banner
Pluralsight Trial

Git for Network Engineers

Ansible vs Nornir

Start learning today with my Network Automation Courses

Master Ansible, Python, Git, Nornir, Jenkins and more..


Buy me a coffeeBuy me a coffee

ansible network automation course

Have you seen my YouTube Channel?

YouTube Subscribe

Let’s get started

Take a look at my premium courses on Ansible, Nornir & Git or buy them all with the Network Automation Bundle!

Network Automation Courses

Navigation

Home

Blog

About

C

Python VENV Tutorial
Python for Network Engineers

Network Automation
Network Automation Courses
Network Discovery Tools
Network Automation Conferences
Ansible Training
Devops Tutorial
Network Source of Truth
DevOps Glossary
Network Monitoring Software

Contact

Contact

Get in touch with me here

[email protected]

  • Twitter
  • LinkedIn
  • YouTube
Buy me a coffeeBuy me a coffee

Copyright © 2025 · Roger Perkin · All Rights Reserved · Privacy Policy – Terms