• 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 Local Preference

Home » BGP Protocol

BGP Local Preference Explained

Local preference is the second BGP attribute and is used to choose the exit path for an autonomous system. The BGP preference has to be set inbound on routes being received to influence the outbound routing behaviour.

A higher local preference is preferred and the default is 100.

The BGP Local Preference attribute or local-pref is used to influence the outbound routing decision of  a router running BGP.

It is the second attribute in the BGP best path algorithm with BGP Weight being the first.

Follow @rogernperkin

How to check Local Preference in BGP Cisco

For this BGP tutorial I will be using the simple topology below. The route 6.6.6.6/32 is being learned via R6 and we are going to try to influence the routing decision on R2 to take the path via the longer AS path through R4 and R5. All routers are addressed with the interface ip relevant to the router. e.g all R2’s ip addresses will end with .2

bgp local preference topology rogers ccie blog

If you want to know how does BGP choose the best path please read BGP best path algorithm which states that if local preference is the same then the path with the shortest AS path will be chosen. As local preference is higher up the decision process if we can change that we can influence the routing over the shortest AS-path choice.

ansible training course

Cisco BGP Local Preference Command

Lets take a look at the routing on R2 and the path it is currently choosing to get to 6.6.6.6

R2#sh ip bgp
BGP table version is 15, local router ID is 10.0.12.2
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
*  6.6.6.6/32       10.0.24.4                              0 65504 65505 65506 i
*>                  10.0.23.3                              0 65503 65506 i
* i10.0.12.0/24     10.0.12.1                0    100      0 i
*>                  0.0.0.0                  0         32768 i
*  10.0.23.0/24     10.0.23.3                0             0 65503 i
*>                  0.0.0.0                  0         32768 i
*  10.0.24.0/24     10.0.24.4                0             0 65504 i
*>                  0.0.0.0                  0         32768 i
*> 10.0.36.0/24     10.0.23.3                0             0 65503 i
*> 10.0.45.0/24     10.0.24.4                0             0 65504 i
*  10.0.56.0/24     10.0.23.3                              0 65503 65506 i
*>                  10.0.24.4                              0 65504 65505 i

So as you can see R2 is preferring the path via R3 as indicated by the > symbol, you can also see that there are two paths available, but the path through R4 is via a longer AS path. We are now going to change the routing behaviour by setting the Local Preference of all routes coming in via R4 higher. This will mean R2 will decide to route to R4 to get to 6.6.6.6 as it has a higher local preference.

To set this we will configure a route map on connection to R4 inbound as below

R2(config-router)#neighbor 10.0.24.4 route-map LOCAL-PREF-150 in
R2(config-router)#route-map LOCAL-PREF-150
R2(config-route-map)#set local-preference 150

After you make this change it’s best to clear the process, as this is a lab environment it is safe to just do clear ip bgp *

R2#clear ip bgp *
R2#
*Mar  1 01:21:08.847: %BGP-5-ADJCHANGE: neighbor 10.0.12.1 Down User reset
*Mar  1 01:21:08.847: %BGP-5-ADJCHANGE: neighbor 10.0.23.3 Down User reset
*Mar  1 01:21:08.851: %BGP-5-ADJCHANGE: neighbor 10.0.24.4 Down User reset
R2#
*Mar  1 01:21:22.607: %BGP-5-ADJCHANGE: neighbor 10.0.23.3 Up 
*Mar  1 01:21:22.611: %BGP-5-ADJCHANGE: neighbor 10.0.24.4 Up 
*Mar  1 01:21:22.627: %BGP-5-ADJCHANGE: neighbor 10.0.12.1 Up

There is a much better method to perform the route-refresh is to do a soft reset as below

R2#clear ip bgp 10.0.24.4 soft

This keeps the tcp session up and just refreshes any routing changes.
So lets see if our route-map changing the bgp local preference has made any difference?

R2#sh ip bgp 
BGP table version is 22, local router ID is 10.0.24.2
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
*> 6.6.6.6/32       10.0.24.4                     150      0 65504 65505 65506 i
*                   10.0.23.3                              0 65503 65506 i
*> 10.0.12.0/24     0.0.0.0                  0         32768 i
* i                 10.0.12.1                0    100      0 i
*> 10.0.23.0/24     0.0.0.0                  0         32768 i
*                   10.0.23.3                0             0 65503 i
*> 10.0.24.0/24     0.0.0.0                  0         32768 i
*                   10.0.24.4                0    150      0 65504 i
*> 10.0.36.0/24     10.0.24.4                     150      0 65504 65505 65506 i
*                   10.0.23.3                0             0 65503 i
*> 10.0.45.0/24     10.0.24.4                0    150      0 65504 i
*                   10.0.23.3                              0 65503 65506 65505 i
*> 10.0.56.0/24     10.0.24.4                     150      0 65504 65505 i
*                   10.0.23.3                              0 65503 65506 i

As you can see the route for 6.6.6.6/32 now has the > by the path via 10.0.24.4 (R4) and the local preference is showing as 150 this means it is taking a longer AS path but as local preference is higher up the bgp algorithm it is chosen first as the routing decision.

One last point is that the local-preference value is passed between iBGP neighbors but it is not passed between eBGP neighbors. So if we look on R1 you will see the bgp local preference value as 150

R1#sh ip bgp 
BGP table version is 35, local router ID is 10.0.12.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
*>i6.6.6.6/32       10.0.24.4                0    150      0 65504 65505 65506 i
* i10.0.12.0/24     10.0.12.2                0    100      0 i
*>                  0.0.0.0                  0         32768 i
*>i10.0.23.0/24     10.0.12.2                0    100      0 i
*>i10.0.24.0/24     10.0.12.2                0    100      0 i
*>i10.0.36.0/24     10.0.24.4                0    150      0 65504 65505 65506 i
*>i10.0.45.0/24     10.0.24.4                0    150      0 65504 i
*>i10.0.56.0/24     10.0.24.4                0    150      0 65504 65505 i

There is one more thing we can do and that is get a bit more specific. As you can see the local preference attribute has been applied to all routes coming in from R4, if we just wanted to do it for 6.6.6.6 then we could match this network in a prefix-list and add that to the route-map.

First I need to create a prefix-list and then match it in the route-map

ip prefix-list 6-6-6-6 seq 5 permit 6.6.6.6/32

route-map LOCAL-PREF-150 permit 10
 match ip address prefix-list 6-6-6-6
 set local-preference 150

If we then do a soft reset and check the sh ip bgp output again you will see that it is only affecting the 6.6.6.6 network

R2#sh ip bgp 
BGP table version is 25, local router ID is 10.0.24.2
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
*> 6.6.6.6/32       10.0.24.4                     150      0 65504 65505 65506 i
*                   10.0.23.3                              0 65503 65506 i
*> 10.0.12.0/24     0.0.0.0                  0         32768 i
* i                 10.0.12.1                0    100      0 i
*> 10.0.23.0/24     0.0.0.0                  0         32768 i
*                   10.0.23.3                0             0 65503 i
*> 10.0.24.0/24     0.0.0.0                  0         32768 i
*> 10.0.36.0/24     10.0.23.3                0             0 65503 i
*> 10.0.45.0/24     10.0.23.3                              0 65503 65506 65505 i
*> 10.0.56.0/24     10.0.23.3                              0 65503 65506 i

We can verify this is working with a trace showing the path to 6.6.6.6 is via 10.0.24.4 (R4)

R2#trace 6.6.6.6 Type escape sequence to abort. Tracing the route to 6.6.6.6   1 10.0.24.4 72 msec 84 msec 32 msec   2 10.0.45.5 [AS 65505] 64 msec 64 msec 68 msec   3 10.0.56.6 [AS 65506] 68 msec *  184 msec R2#trace

BGP Local Preference vs Weight

The major difference between the Weight and LOCAL_PREF attributes is that when the LOCAL_PREF attribute is changed, that change is reflected throughout the AS. The new LOCAL_PREF value will be advertised to all other routers in the AS, as compared to the Weight attribute, which is locally significant only.

BGP Local Preference vs MED

BGP MED or Multi Exit Discriminator attribute is the BGP Path attribute which provides information to their external neighbours, about how to get to their Autonomous System.
This is opposite of Local Preference.
BGP Local Preference attribute tells the internal neighbours how to exit the AS.

Good control of your routing via BGP is an essential part of network security.

Cisco BGP Local Preference Higher or Lower?

The default value of BGP localpref is 100 and a higher local preference is preferred.

Cisco Documentation can be found here 

Follow @rogernperkin

Frequently asked questions

What is local preference in BGP?

The local preference BGP attribute is the second attribute and used to choose the exit path to an autonomous system from a local perspective. It is not exchanged between routers, it’s default value is 100 and the path with the highest local preference is preferred.

How does BGP choose the best path?

Using the best path selection algorithm BGP works through each attribute until it finds one to that gives a preference, if there is no preferred attribute BGP will always route over the shortest AS path

Is Local Preference Transitive?

Local Preference is transitive. It is a Well Known attribute meaning it must be supported by all BGP implementations, and all well known attributes are transitive.
Local Preference is not attached to eBGP updates, only to iBGP updates.

What is the difference between Weight & Local Preference in BGP?

The major difference between the Weight and LOCAL_PREF attributes is that when the LOCAL_PREF attribute is changed, that change is reflected throughout the AS. The new LOCAL_PREF value will be advertised to all other routers in the AS, as compared to the Weight attribute, which is locally significant only

What is the difference between local Pref and AS path?

Local Pref influences routes you receive from your neighbour and therefore influences how you will send the traffic out. Path prepend influences what you advertise to your neighbours and therefore influences how the Internet sends to you. So local-preference controls how you send and path prepend controls how you receive traffic

Table of Contents
  • BGP Local Preference Explained
  • How to check Local Preference in BGP Cisco
  • Cisco BGP Local Preference Command
  • BGP Local Preference vs Weight
  • BGP Local Preference vs MED
  • Cisco BGP Local Preference Higher or Lower?

Further Reading on BGP

  • BGP Weight Attribute
  • BGP Listen Range Command
  • BGP Confederation vs Route Reflector
Category: BGP ProtocolTag: bgp, ccie blog, local-preference
ansible course for network engineers
Get Access to my Ansible Course NOW
Previous Post:bgp route reflector featured imageBGP Confederation vs Route Reflector
Next Post:GNS3 100% CPU Usage – Just hit Enter!

Reader Interactions

Comments

  1. samuel

    January 7, 2015 at 3:20 pm

    Clear and Simple Good Stuff. thanks.

    • Roger Perkin

      January 9, 2015 at 3:56 pm

      Glad it helped you understand BGP Local Preference.
      Roger

  2. Helcio

    January 24, 2015 at 9:25 pm

    Hi, Roger.

    Please take a look at this topology:

    R1
    /
    /
    /
    R2——-R3

    R1 belongs to AS 100 and R2 and R3 belong to AS 200.There are eBGP sessions between R1 and R2 and between R1 and R3. There is an iBGP session between R2 and R3.

    Initially, I have two paths to a network in R1 from either R2 or R3 – in any case, the direct link is the preferred route and the link passing through the iBGP peer is the secondary route. I’ve set the local preference attribute in R3 to apply it to routes learned from R1. Everything is going well – I can reach a network in R1 from R2 through R3 and I can reach that network from R3 directly. However, I can’t understand why there is not a secondary route in R3 when I type ‘show ip bgp’ in that router. Actually, I can see only the route using the direct link between R3 and R1.

    I’ve used GNS3 to build this topology, and I trying to understand how BGP works – by the weay, I’m a computer network professor in Brazil.

    Thanks in advance, Roger.

    Helcio.

    • Roger Perkin

      January 26, 2015 at 9:57 am

      Helcio,

      Without seeing what config you have on your routers it is very tricky to see where your problem is, send me a message with your router configuration and I will take a look.

      Just click on the email icon at the top right of the site.

      Roger

  3. zach

    May 15, 2015 at 10:09 am

    Thanks roger, this tutorial realy help me to understand how to configure the bgp local preference.

    • Roger Perkin

      May 15, 2015 at 4:18 pm

      I am glad it helped

  4. Helcio

    May 24, 2015 at 2:29 am

    Hi, Roger. Could you tell me why we don’t see two routes to 6.6.6.6/32 in R1?

    I suppose BGP propagates only the best route it has received to a given destination (I think I’ve seen something like that in some place, but I’m not sure where). My guess is that R2 compares the two routes to 6.6.6.6/32, that one received from R3 and the other received from R4. It concludes that the route sent by R4 is the better (because it has the highest LOCAL_PREF) and propagates it to R1. Am I correct?

    Thanks in advance for any clarification.

    • Roger Perkin

      May 26, 2015 at 7:12 am

      Exactly, R1 only has one way out and that is via R2. BGP will only advertise the best route onto R1 – This could get a lot more complicated if you wanted, but for this example let’s keep it simple.

      • Helcio

        May 27, 2015 at 12:23 am

        Thank you so much, Roger.

  5. AK

    November 22, 2015 at 10:56 am

    Nice and easy to grasp clarification of the local reference attribute. Thank you very much

  6. SUdhakar Sharma

    September 5, 2019 at 11:11 am

    very well explained in simple language …

    • Roger Perkin

      October 9, 2019 at 11:31 pm

      Great glad it helped

  7. Abdullah

    October 27, 2019 at 6:12 pm

    Need to know which tool is being used here to simulate the environment.

    • Roger Perkin

      October 27, 2019 at 7:10 pm

      Hi this is GNS3, but I now use EVE-NG

  8. Ulrich Willems

    November 4, 2019 at 12:39 pm

    very good EXPLANATION. I like it when a ccie explains stuff in an easy way.

    • Roger Perkin

      November 20, 2019 at 9:55 am

      Thanks Ulrich

  9. Rafael

    November 22, 2019 at 3:00 pm

    thank you for your time to write this article! really a good stuff and very objective.

    Keep up doing this great job.

    • Roger Perkin

      November 25, 2019 at 12:14 pm

      Thanks Rafael,

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