Friday, February 21, 2020

How to Configure BGP Weight Attribute

Weight is a Cisco proprietary BGP attributes that can be used to select a certain path. Here’s what you need to know about weight:
  • Weight is the first BGP attribute in the list.
  • Cisco proprietary so you won’t find it on other vendor routers.
  • Weight is not exchanged between BGP routers.
  • Weight is only local on the router.
  • The path with the highest weight is preferred.
Let me give you an example for BGP weight:
BGP Weight Prefer Path
R1 in AS 1 can reach AS 3 through AS 2 or AS 4. If we want to ensure AS 2 is always used as the best path you can change the weight. In my example, the weight for the path to AS 2 is set to 500 and higher than the weight of 400 for AS 4. Let’s see what this looks like on real Cisco routers, this is the topology that I will use:
Bgp Weight Attribute Lab Topology
Above we have a simple scenario with two autonomous systems. R2 and R3 both have network 2.2.2.0/24 configured on their loopback0 interface and I’ll advertise that in BGP.
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
R2(config)#router bgp 2
R2(config-router)#neighbor 192.168.12.1 remote-as 1
R2(config-router)#neighbor 192.168.23.3 remote-as 2
R2(config-router)#network 2.2.2.0 mask 255.255.255.0
R3(config)#router bgp 2
R3(config-router)#neighbor 192.168.13.1 remote-as 1
R3(config-router)#neighbor 192.168.23.2 remote-as 2
R3(config-router)#network 2.2.2.0 mask 255.255.255.0
Above you’ll find the configuration for BGP, now let’s take a detailed look at R1:
R1#show ip bgp 
BGP table version is 2, local router ID is 192.168.13.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
*> 2.2.2.0/24       192.168.12.2             0             0 2 i
*                   192.168.13.3             0             0 2 i
Router R1 decided to use 192.168.12.2 as the next hop. All the BGP attributes are the same so it came down to the router ID to select a winner. Now let’s change this behavior using the weight attribute…
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.13.3 weight 500
You can configure weight per neighbor using the weight command. All prefixes from this neighbor will have a weight of 500.
R1#clear ip bgp *
Sometimes BGP behaves like an oil tanker so to speed things up in your lab, reset it.
R1#show ip bgp   
BGP table version is 2, local router ID is 192.168.13.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
*  2.2.2.0/24       192.168.12.2             0             0 2 i
*>                  192.168.13.3             0           500 2 i
Now you can see that 192.168.13.3 has been selected as the next hop because the weight is now 500.
What if I want to set the weight to 500 for just a couple of prefixes from AS 2?
R2(config)#interface loopback 1
R2(config-if)#ip address 22.22.22.22 255.255.255.0

R2(config)#router bgp 2
R2(config-router)#network 22.22.22.0 mask 255.255.255.0
R3(config)#interface loopback 1
R3(config-if)#ip address 22.22.22.22 255.255.255.0

R3(config)#router bgp 2
R3(config-router)#network 22.22.22.0 mask 255.255.255.0
I’ll create a new loopback interface on router R2 and R3 and I’ll advertise network 22.22.22.0/24 in BGP. Here’s what router R1 now looks like:
R1#show ip bgp 
BGP table version is 5, local router ID is 192.168.13.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
*  2.2.2.0/24       192.168.12.2             0             0 2 i
*>                  192.168.13.3             0           500 2 i
*> 22.22.22.0/24    192.168.13.3             0           500 2 i
*                   192.168.12.2             0             0 2 i
As you can see above router R1 will use 192.168.13.3 as the next hop for both prefixes. What if I want to change the weight for just 1 prefix? Route-maps to the rescue!
R1(config)#router bgp 1
R1(config-router)#no neighbor 192.168.13.3 weight 500
First we’ll get rid of the command above.
R1(config)#route-map SETWEIGHT permit 10
R1(config-route-map)#match ip address 1
R1(config-route-map)#set weight 400
R1(config-route-map)#exit
R1(config)#route-map SETWEIGHT permit 20
R1(config-route-map)#set weight 0
R1(config-route-map)#exit
R1(config)#access-list 1 permit 22.22.22.0 0.0.0.255
Here’s the route-map that I will use. If the prefixes match access-list 1 we will set the weight to 400.
R1(config-router)#neighbor 192.168.13.3 route-map SETWEIGHT in
To complete the configuration we have to apply it to our neighbor in AS 2. Using a route-map gives you a lot of control!
R1#clear ip bgp *
This will speed things up…
R1#show ip bgp 
BGP table version is 3, local router ID is 192.168.13.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
*  2.2.2.0/24       192.168.13.3             0             0 2 i
*>                  192.168.12.2             0             0 2 i
*> 22.22.22.0/24    192.168.13.3             0           400 2 i
*                   192.168.12.2             0             0 2 i
See how the weight changed for network 22.22.22.0/24 ? Use route-maps to influence the BGP attributes per neighbor/prefix.
hostname R1
!
interface fastEthernet0/0
 ip address 192.168.12.1 255.255.255.0
!
interface fastEthernet1/0
 ip address 192.168.13.1 255.255.255.0
!
router bgp 1
 neighbor 192.168.12.2 remote-as 2
 neighbor 192.168.13.3 remote-as 2
 neighbor 192.168.13.3 route-map SETWEIGHT in
!
route-map SETWEIGHT permit 10
 match ip address 1
 set weight 400
!
route-map SETWEIGHT permit 20
 set weight 0
!
access-list 1 permit 22.22.22.0 0.0.0.255
!
end
hostname R2
!
interface Loopback 0
 ip address 2.2.2.2 255.255.255.0
!
interface Loopback 1
 ip address 22.22.22.22 255.255.255.0
!
interface fastEthernet1/0
 ip address 192.168.12.2 255.255.255.0
!
interface fastEthernet2/0
 ip address 192.168.23.2 255.255.255.0
!
router bgp 2
 neighbor 192.168.12.1 remote-as 1
 neighbor 192.168.23.3 remote-as 2
 network 2.2.2.0 mask 255.255.255.0
 network 22.22.22.0 mask 255.255.255.0
!
end
hostname R3
!
interface Loopback 0
 ip address 2.2.2.2 255.255.255.0
!
interface loopback 1
 ip address 22.22.22.22 255.255.255.0
!
interface fastEthernet0/0
 ip address 192.168.13.3 255.255.255.0
!
interface fastEthernet1/0
 ip address 192.168.23.3 255.255.255.0
!
router bgp 2
 neighbor 192.168.13.1 remote-as 1
 neighbor 192.168.23.2 remote-as 2
 network 2.2.2.0 mask 255.255.255.0
 network 22.22.22.0 mask 255.255.255.0
!
end
And that’s the end of it. I hope this has been helpful for you to understand the BGP weight attribute! If you have any questions just leave a comment.

No comments:

Post a Comment