How to Configure BGP Local Preference Attribute

Hello sales2161

The “in” or “out” keywords are used like so. With the “in” keyword, the route map will be applied to routes received from the specified neighbor. In this case, any BGP routes learned from this neighbor will be given a Local Preference according to what the LOCALPREF route map has been configured with.

If the “out” keyword is used, then the route map will apply to all routes advertised to the neighbor. This means that routes that are advertised to the neighbor will be given a Local Preference according to what the LOCALPREF route map has been configured with.

I hope this has been helpful!

Laz

1 Like

Hi

Please see below BGP database and routing table has correct entries but still R4 is unable to ping 1.1.1.1. See the last line of the debug that has some indications but I can’t interpret.

R4(config)#do sh ip bgp
     Network          Next Hop            Metric LocPrf Weight Path
 *>i 1.1.1.0/24       2.2.2.2                  0    100      0 1 i
 * i                  3.3.3.3                  0    100      0 1 i

do sh ip rou bgp
      1.0.0.0/24 is subnetted, 1 subnets
B        1.1.1.0 [200/0] via 2.2.2.2, 00:05:59



R2:

router bgp 2
 bgp log-neighbor-changes
 neighbor 3.3.3.3 remote-as 2
 neighbor 3.3.3.3 update-source Loopback0
 neighbor 4.4.4.4 remote-as 2
 neighbor 4.4.4.4 update-source Loopback0
 neighbor 4.4.4.4 next-hop-self
 neighbor 192.168.12.1 remote-as 1

Debug on R2:

*May  2 00:47:29.756: IP: s=192.168.12.2 (local), d=192.168.12.1 (GigabitEthernet0/1), len 40, sending
*May  2 00:47:29.757: IP: s=192.168.12.2 (local), d=192.168.12.1 (GigabitEthernet0/1), len 40, sending full packet
*May  2 00:47:34.139: IP: s=192.168.12.2 (local), d=192.168.12.1 (GigabitEthernet0/1), len 59, sending
*May  2 00:47:34.139: IP: s=192.168.12.2 (local), d=192.168.12.1 (GigabitEthernet0/1), len 59, sending full packet
*May  2 00:47:34.341: IP: s=192.168.12.1 (GigabitEthernet0/1), d=192.168.12.2, len 40, rcvd 0
*May  2 00:47:34.341: IP: s=192.168.12.1 (GigabitEthernet0/1), d=192.168.12.2, len 40, input feature, packet consumed, MCI Check(109), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSE

Hello Card

The strange output at the end may be due to a cisco bug and may be unrelated. Take a look at this link.

As for your connectivity issue, make sure that OSPF is functioning and that you have full mesh adjacencies within your AS 2.

I hope this has been helpful!

Laz

sir
i want to ask why you used a OSPF in this topology what is the reason behind using OSPF in it

Hi Rene,
Do bgp update the neighbor only the paths which got installed in the routing table or will they update the neighbor with its alternate paths which is available in the bgp table(still not the best).

I am curious to know since when I applied the route-map setting the Local preference to 500 on R3, I can see R4 now only learns 1.1.1.0/24 from R3. I expected it learn from R2 as well as a valid route.

R4#sh ip bgp
BGP table version is 6, local router ID is 4.4.4.4
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
*>i1.1.1.0/24       3.3.3.3                  0    500      0 1 i
R4#sh ip bgp 1.1.1.0
BGP routing table entry for 1.1.1.0/24, version 6
Paths: (1 available, best #1, table Default-IP-Routing-Table)
  Not advertised to any peer
  1
    3.3.3.3 (metric 2) from 3.3.3.3 (3.3.3.3)
      Origin IGP, metric 0, localpref 500, valid, internal, best
R4#

R3#sh run | s bgp
router bgp 2
 no synchronization
 bgp log-neighbor-changes
 neighbor 2.2.2.2 remote-as 2
 neighbor 2.2.2.2 update-source Loopback0
 neighbor 2.2.2.2 next-hop-self
 neighbor 4.4.4.4 remote-as 2
 neighbor 4.4.4.4 update-source Loopback0
 neighbor 4.4.4.4 next-hop-self
 neighbor 192.168.13.1 remote-as 1
 neighbor 192.168.13.1 route-map LOCALPREF in
 no auto-summary

R3#sh run | s route-map    
 neighbor 192.168.13.1 route-map LOCALPREF in
route-map LOCALPREF permit 10
 set local-preference 500

R2#sh ip bgp
BGP table version is 3, local router ID is 2.2.2.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
*>i1.1.1.0/24       3.3.3.3                  0    500      0 1 i
*                   192.168.12.1             0             0 1 i
R2#sh ip route bgp
     1.0.0.0/24 is subnetted, 1 subnets
B       1.1.1.0 [200/0] via 3.3.3.3, 00:14:46
R2#

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-router)#
*Mar  1 01:22:36.131: %BGP-5-ADJCHANGE: neighbor 2.2.2.2 Down User reset
*Mar  1 01:22:36.135: %BGP-5-ADJCHANGE: neighbor 4.4.4.4 Down User reset
*Mar  1 01:22:36.139: %BGP-5-ADJCHANGE: neighbor 192.168.13.1 Down User reset
*Mar  1 01:22:36.635: %BGP-5-ADJCHANGE: neighbor 4.4.4.4 Up 
*Mar  1 01:22:36.639: %BGP-5-ADJCHANGE: neighbor 192.168.13.1 Up 
*Mar  1 01:22:36.755: %BGP-5-ADJCHANGE: neighbor 2.2.2.2 Up 
R3(config-router)#

R2#show ip bgp  neighbors 4.4.4.4 advertised-routes 
BGP table version is 6, local router ID is 2.2.2.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
*> 1.1.1.0/24       192.168.12.1             0             0 1 i

Total number of prefixes 1 
R2#show ip bgp  neighbors 3.3.3.3 advertised-routes 
BGP table version is 6, local router ID is 2.2.2.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
*> 1.1.1.0/24       192.168.12.1             0             0 1 i

Total number of prefixes 1 
R2#

Hello Harshit

All routing that occurs within an AS will most often use an IGP like OSPF, EIGRP, or ISIS for routing between routers. BGP requires that all routers within an AS are able to reach each other in order for BGP to function. The routing protocol within an AS doesn’t have to be OSPF, it’s just that in this example, Rene choose to use it. You could do the same lab using EIGRP for the internal routing protocol as well.

I hope this has been helpful!

Laz

thanks now it is clear @lagapides

1 Like

I have one more question i have read about all 3 attributes
1> weight attribute - the reason of using this is you can change in the edge router of your AS network we can decide from which link our traffic will go after setting weight
2> local prefrences - the reason of using this that it will shar the local prefrence with all other neighbor BGP router it will tell that from which link your traffic will go out for this purpose we use ROUTE MAP IN command
3> but i am confused in AS path and prepending attribute that for which purpose we use it for outbound traffic or inbound traffic ? it will effect which traffice like -: traffic is coming from which ISP if have 2 ISP and another one that traffic will go through which link which traffic will go out from internal AS to OUTER external AS link

si r please solve this problem

I am little bit confused on it when we use this attribute at which purpose

sir another thing is that i am confused in INBOUND and OUTBOUND command
still i usderstand that meaning is that -
1> INBOUND - means when our AS traffic will go through internal AS to external AS so basically it is telling that this is command is used for the purpose of how to send internal traffic .
2> OUTBOUND - means it will effect the traffic which enters in our AS through another AS link

My question is that how inbound and outbound commands work sir kindly requesting you please tell with some example so that it can be clear

Hello Madhu

What is happening here is the initiation of the BGP split-horizon rule. This rule states that a BGP router that receives a BGP route via an iBGP peer shall not advertise that route to another router that is an iBGP peer. So, what is happening here is that R2 receives information from R3 that it has a route to 1.1.1.0/24 with an increased local preference. Thus, because R2 has received this information, it will no longer advertise its route to 1.1.1.0/24 due to the split horizon rule. Since the local preference prefers R3’s route, R2 will remain quiet. If the local preference changes and R2’s route has a higher local preference, then it’s information is more relevant, it will begin advertising, and R3 will then stop advertising the route due to the split horizon rule.

More about this rule can be found here:

I hope this has been helpful!

Laz

1 Like

Hello Harshit

AS Path Prepending allows us to try to influence how incoming traffic is routed. If we have two ISPs, we can advertise prepended AS’es to a particular route via one of our two BGP routers, such that the ISP sees a longer path to get to our advertised addresses. In this way we influence incoming traffic. You can find out more about this at the following lesson:

It depends on the context. If we are applying a route map, such as in the Local Preference lesson, then the in keyword states that an routes being advertised by a BGP peer that come IN to the local router should have their local preference changed according to some rule. When we are talking about user traffic inbound and outbound, then we are referring to something else entirely. That is, we are referring to the route that traffic takes according to specific routing rules in the routing table. The context of what we are talking about is very important to understand the terms.

I hope this has been helpful!

Laz

Thanks Laz, It makes Sense. So from this I also understand that, a BGP router will only send the best path to its neighbors, thats why in this situation, R2 is not updating R4 about the ebgp path it received from R1. Is it correct ? (I already got the point why its not advertizing the ibgp path it learned from R3 due to IBGP split horizon rule.)

Thanks,

Hello Madhu

Yes that is correct!

Laz

Hi Rene,

can you please clear why we use neighbor 4.4.4.4 next-hop-self command only for R3 and R2, not for R4?

In iBGP the routers internally will not share the routes that they had learned from EBGP, how will they know that the Local Preference Attribute has been updated by R2 as we are doing change on R3.

Local preference Attribute will be always need to be configure on AS which has iBGP configured on it?

Last question, previous in Weight Attribute we had used Route-Map inbound on our R1 and in this we are again using inbound route-map on R3, is don’t need to be outboud as now traffic will come from R1, if not can you please help to clear that?

Thanks

Hello Navraj

Only routers that have eBGP peers require the next-hop-self configuration. This is because when they share BGP routes with other AS’es it is necessary for them to advertise themselves as the next hop and not the original BGP router that advertised the route. In this case, when R2 or R3 inform R4 of the 1.1.1.0/24 network, they won’t provide a next hop address of R1 but of R2 or R3 respectively, so that R4 can reach the next hop address and successfully route traffic.

Actually, routers will share what they learn from eBGP. If you take a look at the BGP table of R4 you will see that the network 1.1.1.0/24 is in the BGP table, and his was leaned via eBGP from R1 which is in another AS. In the same way, the LocalPref attribute is learned and shared between iBGP routers.

The local preference attribute is configured under a specific AS. If there are other routers in that AS, they will receive this information via iBGP.

When we talk about route maps adjusting local preference and weight, and when we specify “in” or “out” we must keep in mind what is coming “in” or going “out”. Route maps in these cases are always applied to the BGP UPDATES that are being exchanged and not the user traffic. When an update comes IN from a neighbor and it goes through a route map, the attributes of the update are changed before being stored in the BGP table, regardless of what direction user traffic is taking. If an update is being sent OUT to a neighbor, the attributes changed by an outbound route map are changed before the BGP update is sent out, so the neighbor receives an update with modified attributes.

I hope this has been helpful!

Laz

Rather than creating a full mesh in AS 2, I decided to make R4 a route reflector, with R2 and R3 configured as route reflector clients. I was expecting both R2 and R3 to learn of 2 possible BGP routes to reach the 1.1.1.0/24 prefix, but this turns out not to be the case. Hope you can provide some clarification as to why this is observed.

Simulating with IOU image in GNS3.

R4:
router bgp 2
 bgp log-neighbor-changes
 neighbor 2.2.2.2 remote-as 2
 neighbor 2.2.2.2 update-source Loopback0
 neighbor 3.3.3.3 remote-as 2
 neighbor 3.3.3.3 update-source Loopback0
 neighbor 3.3.3.3 route-reflector-client

 Network          Next Hop            Metric LocPrf Weight Path
* i 1.1.1.0/24       3.3.3.3                  0    100      0 1 i
*>i                  2.2.2.2                  0    100      0 1 i


R3:
router bgp 2
bgp log-neighbor-changes
neighbor 4.4.4.4 remote-as 2
neighbor 4.4.4.4 update-source Loopback0
neighbor 4.4.4.4 next-hop-self
neighbor 192.168.13.1 remote-as 1

Network          Next Hop            Metric LocPrf Weight Path
 * i 1.1.1.0/24       2.2.2.2                  0    100      0 1 i
 *>                   192.168.13.1             0             0 1 i


R2:
router bgp 2
 bgp log-neighbor-changes
 neighbor 4.4.4.4 remote-as 2
 neighbor 4.4.4.4 update-source Loopback0
 neighbor 4.4.4.4 next-hop-self
 neighbor 192.168.12.1 remote-as 1
     
Network          Next Hop            Metric LocPrf Weight Path
*>  1.1.1.0/24       192.168.12.1             0             0 1 i

Hello Ronald

I believe the problem is that on R4 you have made only R3 a route reflector client. You need to make R2 a route reflector client as well using the command:

neighbor 2.2.2.2 route-reflector-client

I hope this has been helpful!

Laz

R3(config)#route-map LOCALPREF permit 10
R3(config-route-map)#set local-preference 700

R3(config)#router bgp 2
R3(config-router)#neighbor 192.168.13.1 route-map LOCALPREF in

What if put ‘OUT’ or when we use ‘OUT’

Thanks

Hello Sims

With the above configuration using the “IN” keyword, any BGP routes that are recieved from that neighbor will have a local preference set to 700. In other words, if the 192.168.13.1 neighbor sends R3 a prefix to 1.1.1.0/24, R3 will set the LOCALPREF to 700 before installing it in its BGP table.

If you used the “OUT” keyword, then this route-map will be applied to prefixes that are sent from R3 to the 192.168.13.1 neighbor. For example, if R3 sends the 2.2.2.0/24 prefix to the 192.168.13.1 neighbor, it will adjust the LOCALPREF of that prefix to 700 before sending it to its neighbor.

Remember that the “IN” and “OUT” keywords apply to the exchange of BGP information and not to the actual user traffic that is being exchanged.

I hope this has been helpful!

Laz

Hi,

R2(config)#router bgp 2
R2(config-router)#neighbor 4.4.4.4 remote-as 2
R2(config-router)#neighbor 4.4.4.4 update-source loopback 0

why bgp does not form neighbourship if I am not adding “neighbor 4.4.4.4 update-source loopback 0”
Thanks