How to Configure BGP Local Preference Attribute

BGP attribute local preference is the second BGP attribute and it can be used to choose the exit path for an autonomous system. Here are the details:

  • Local preference is the second BGP attribute.
  • You can use local preference to choose the outbound external BGP path.
  • Local preference is sent to all internal BGP routers in your autonomous system.
  • Not exchanged between external BGP routers.
  • Local preference is a well-known and discretionary BGP attribute.
  • Default value is 100.
  • The path with the highest local preference is preferred

Let me show you an example:

bgp local preference example

You can use local preference to configure your autonomous system to select a certain exit point. Instead of configuring weight on each router you can use local preference because it is exchanged on all internal BGP routers. By increasing the local preference to 800 we can make AS 1 send all traffic towards AS 2.

A well-known discretionary BGP attribute must be recognized by all BGP routers per RFC but its presence in a BGP update is optional.

Now let me show you how to configure local preference, here is the topology that we will use:

bgp local preference lab

In the picture above we have two autonomous systems. R1 will advertise network 1.1.1.0/24 towards AS 2 and R4 will have to make a choice when it wants to reach this network. It can go through router R2 or R3, we’ll see how local preference influence this.

R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 remote-as 2
R1(config-router)#neighbor 192.168.13.3 remote-as 2
R1(config-router)#network 1.1.1.0 mask 255.255.255.0

This is the configuration of R4, nothing spectacular here.

R2(config)#interface loopback 0
R2(config-if)#ip address 2.2.2.2 255.255.255.0

R2(config)#router ospf 1
R2(config-router)#network 192.168.24.0 0.0.0.255 area 0
R2(config-router)#network 2.2.2.0 0.0.0.255 area 0
R3(config)#interface loopback 0
R3(config-if)#ip address 3.3.3.3 255.255.255.0

R3(config)#router ospf 1
R3(config-router)#network 192.168.34.0 0.0.0.255 area 0
R3(config-router)#network 3.3.3.0 0.0.0.255 area 0
R4(config)#interface loopback 0
R4(config-if)#ip address 4.4.4.4 255.255.255.0
R4(config)#router ospf 1
R4(config-router)#network 192.168.24.0 0.0.0.255 area 0
R4(config-router)#network 192.168.34.0 0.0.0.255 area 0
R4(config-router)#network 4.4.4.0 0.0.0.255 area 0

I’ll configure OSPF within AS2 to prepare it for IBGP.

R3(config)#router bgp 2
R3(config-router)#neighbor 192.168.13.1 remote-as 1
R3(config-router)#neighbor 2.2.2.2 remote-as 2
R3(config-router)#neighbor 2.2.2.2 update-source loopback0
R3(config-router)#neighbor 4.4.4.4 remote-as 2
R3(config-router)#neighbor 4.4.4.4 update-source loopback0
R3(config-router)#neighbor 4.4.4.4 next-hop-self
R2(config)#router bgp 2
R2(config-router)#neighbor 192.168.12.1 remote-as 1
R2(config-router)#neighbor 3.3.3.3 remote-as 2
R2(config-router)#neighbor 3.3.3.3 update-source loopback0
R2(config-router)#neighbor 4.4.4.4 remote-as 2
R2(config-router)#neighbor 4.4.4.4 update-source loopback0
R2(config-router)#neighbor 4.4.4.4 next-hop-self
R4(config)#router bgp 2
R4(config-router)#neighbor 2.2.2.2 remote-as 2
R4(config-router)#neighbor 2.2.2.2 update-source loopback 0
R4(config-router)#neighbor 3.3.3.3 remote-as 2
R4(config-router)#neighbor 3.3.3.3 update-source loopback 0

And above you can see the BGP configurations.

Now let’s find out what path R4 will use to reach network 1.1.1.0/24:

We're Sorry, Full Content Access is for Members Only...

If you like to keep on reading, Become a Member Now! Here is why:

  • Learn any CCNA, CCNP and CCIE R&S Topic. Explained As Simple As Possible.
  • Try for Just $1. The Best Dollar You've Ever Spent on Your Cisco Career!
  • Full Access to our 655 Lessons. More Lessons Added Every Week!
  • Content created by Rene Molenaar (CCIE #41726)

561 Sign Ups in the last 30 days

satisfaction-guaranteed
100% Satisfaction Guaranteed!
You may cancel your monthly membership at any time.
No Questions Asked!

Forum Replies

  1. Hi Rene,

    I always get confused with the in and out direction. Would you please explain more about the when i should use direction in and when i should use out?

    Thank you in advance.

  2. Hussein,
    I assume you are referring to this:
    R3(config-router)#neighbor 192.168.13.1 route-map LOCALPREF in

    If you switched the route-map LOCALPREF in to be route-map LOCALPREF out, then the route-map would no longer be doing anything. Essentially, this would cause R3 no longer to advertise a non-default Local Preference to R4.

    The neighbor where the route-map statement being applied, is R1. R1 is in a different ASN than R3. As you may recall, the Local-Preference attribute is only sent to iBGP neighbors, so attempting to set the Local Preference attribute

    ... Continue reading in our forum

  3. Let me rephrase it , I am trying to figure out why R2 stops sending updates about 1.1.1.0/24 that it receives from R1(EBGP update) to both R4 and R3 when I apply the Route-map on R3.

    R2#show ip bgp  neighbors 4.4.4.4 advertised-routes 
    
    Total number of prefixes 0 
    R2#show ip bgp  neighbors 3.3.3.3 advertised-routes 
    
    Total number of prefixes 0 
    R2#
    

    If I remove the rm, it starts updating

    R3(config)#router bgp 2
    R3(config-router)#no  neighbor 192.168.13.1 route-map LOCALPREF in
    R3(config-router)#do clear ip bgp *
    R3(config-router)#
    R3(config-router)#
    R3(config
    ... Continue reading in our forum

79 more replies! Ask a question or join the discussion by visiting our Community Forum