#

Saturday, August 26, 2017

Most of the time for iGBP neighbors you will configure neighbor with a loopback address.
This is the better way to create the mesh connectivity between all iBGP neighbors.
This is sometimes can be seen where we have redundant paths to our iBGP / eBGP neighbors and if one of the physical links go down BGP neighbor relationship won’t go down..
To do this to eBGP peers we have to change the TTL value by a command and create the neighbor relationship between loopback interfaces.








For iBGP peers

R1(config)#router bgp 1
R1(config-router)#neighbor 2.2.2.2 remote-as 1

R2(config)#router bgp 1
R2(config-router)#neighbor 1.1.1.1 remote-as 1

Routing needed to reach loopbacks..

R1(config)#ip route 2.0.0.0 255.0.0.0 10.1.1.2
R2(config)#ip route 1.0.0.0 255.0.0.0 10.1.1.1

Now let's enter update source loopback command on R1 only;

R1(config-router)#neighbor 2.2.2.2 update-source lo0

New neighbor relationship will be formed. (if did't, clear bgp to reset neighbors)
So this means even with only 1 side, neighbor relationship can be formed. But the best practice is to do it from both sides.

The above command means, the source IP address of the BGP packets sent to R2 is the loopback of R1.. Then the correctly configured router (R1) always becomes the TCP client who starts the SYN witth the R2's loopback. So R2 replies to the source of the SYN with SYN/ACK and again R1 sends the ACK to complete TCP handshake..

For eBGP peers

You would have to enter another command to make it work for eBGP neighbors from both sides.
Assuming all other configurations working;

R1(config-router)#neighbor 2.2.2.2 ebgp-multihop 2
R2(config-router)#neighbor 1.1.1.1 ebgp-multihop 2

Now neighbors will come up. This is required because eBGP neighbors have packets with TTL value of '1' for security reasons. Above commands will change the TTL to 2.

Side Note:- You can set an eBGP peer with a not directly connected router which is far away from your location using this ebgp-multihop command. You will have to know the hop count from your router to the target router and give the multihop value larger than that.
Also you can simply disable the connected check for eBGP neighbors by the following command..

R1(config-router)#neighbor 2.2.2.2 disable-connected-check
R2(config-router)#neighbor 1.1.1.1 disable-connected-check

In a case you want to change the next hop address of BGP routes or specific BGP route learned from a specific neighbor, you will have to apply this configuration. Normally you would do this to set the next hop ip address to be a certain exit point from your AS.











Let's see how the BGP table looks like from R1 before configuring next hop commands..





From R1's perspective, 192.168.45.0 route is learned as 2 routes. Obviously they should have been learned from his 2 iBGP neighbors. Also you may notice that the next hop is in another AS.
If you want to make the next hop of the routes learned via R2 to be himself when they are advertised to R1, you will have to use the following command on R2;

R2(config)#router bgp 1
R2(config-router)#neighbor 1.1.1.1 next-hop-self

Now you can see the next hop is changed to 2.2.2.2 which is the router ID of R2..

This next hop 2.2.2.2 is actually not the BGP router ID of R2, it's the updating source interface of R2 to R1..

Note:- 

This does not change any thing on R2's BGP table or other iBGP neighbors..
Does not work with eBGP neighbors..
If you want to do this only for a specific route, you have to use a route map..

Friday, August 25, 2017

Router ID is the 8th (last) attribute in the list.. 
If all other attributes are equal finally it boils down to the Router ID..

Route with the lowest router ID is preferred..

Let's see an example..
















Basic BGP configuration is like the following..

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)#network 10.10.10.0 mask 255.255.255.0
R2(config-router)#network 20.20.20.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)#network 10.10.10.0 mask 255.255.255.0
R3(config-router)#network 20.20.20.0 mask 255.255.255.0

For both 10.10.10.0/24 and 20.20.20.0/24 networks, best routes are learnt via 192.168.12.2 by default.. Because all other attributes are equal, the lowest router-id has become the most preferred.









Note:- 

Don't misunderstand the next hop of the route with the neighbors router ID. You don't see the neighbor's router ID on the above output. Even if you look for a show ip bgp summary for neighbors, those are not the Router IDs of the neighbors you are seeing on the output..











Then what are the router ids of the neighbors??





Above are the real router IDs. We can manually change it too.
Let's change the R2's ID to a higher value..

R2(config)#router bgp 2
R2(config-router)#bgp router-id 40.40.40.40









Now you can see that the route from R3 is chosen because now the router id is lower in R3 than R2.

Note:- 

Following is the BGP router ID selection preference of a router..
(1) Use the address configured by the bgp router-id command
(2) Use the Loopback interface address with the highest IP address
(3) Use the highest IP address of the interface
(4) If no interface exists, set the router-ID to 0.0.0.0

Path type is the 7th attribute in the list..

External paths are preferred over internal paths..

Let's see an example..

















Basic BGP configuration..

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

R2(config)#router bgp 2
R2(config-router)#bgp router-id 2.2.2.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

R3(config)#router bgp 2
R3(config-router)#bgp router-id 3.3.3.3
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)#network 10.10.10.0 mask 255.255.255.0
R3(config-router)#network 20.20.20.0 mask 255.255.255.0

Basic routing (static) on R2 & R3 to reach their loopbacks..

R2(config)#ip route 3.3.3.0 255.255.255.0 192.168.23.3
R3(config)#ip route 2.2.2.0 255.255.255.0 192.168.23.2

Let's see the R2's BGP table..









According to the default behavior, It has now chosen the internal path as the best route.
Note that this is not because of the Local Preference which overrules the Path Type attribute, Even though it is not showing in the show ip bgp output, Local Preference is 100 for both the routes.












To understand this hidden Local Preference of eBGP routes, please go here.

Let's change the local preference to 0 to all the routes coming from R3, which then will be equal for both the eBGP and iBGP neighbors to R2..

R3(config)#router bgp 2
R3(config-router)#bgp default local-preference 0

Now you will see that the external path is preferred over the internal path because all other attributes are equal..

MED is the sixth BGP attribute in the list.. Though the abbreviation  stands for Multi-Exit Discriminator it simply means the metric of BGP..
(1) Can use to choose the best path for inbound traffic which means influence routing in eBGP neighbors..
(2) The lowest MED is the preferred path..
(3) Propagated to iBGP neighbors in one AS only and will be propagated to neighboring AS only if the eBGP neighbor is directly connected to the route originating router or advertised using a route-map..
(4) MED values are compared for the prefixes coming from the same AS only by default..

MED can be used to advertise to your neighbors how they should enter your AS like we did in AS-Path prepending. Go here to find how AS-Path do same kind of thing..

Following example and this post is for the default behavior of Cisco IOS for the routes learned via the same AS. For an example where the same route is learned by 2 different ASes please go here.

Let's see an example..










Basic routing (EIGRP) configurations in AS-1

R1(config)#router eigrp 10
R1(config-router)#network 192.168.12.0
R1(config-router)#network 192.168.13.0
R1(config-router)#network 1.0.0.0

R2(config)#router eigrp 10
R2(config-router)#network 192.168.12.0
R2(config-router)#network 2.0.0.0

R3(config)#router eigrp 10
R3(config-router)#network 192.168.13.0
R3(config-router)#network 3.0.0.0

Basic routing (static) on R1 to reach the R2-R4 & R3-R4 links

R1(config)#ip route 192.168.24.0 255.255.255.0 192.168.12.2
R1(config)#ip route 192.168.34.0 255.255.255.0 192.168.13.3

Basic BGP configurations

R1(config)#router bgp 1
R1(config-router)#neighbor 2.2.2.2 remote-as 1
R1(config-router)#neighbor 2.2.2.2 update-source Loopback0
R1(config-router)#neighbor 3.3.3.3 remote-as 1
R1(config-router)#neighbor 3.3.3.3 update-source Loopback0

R2(config)#router bgp 1
R2(config-router)#neighbor 1.1.1.1 remote-as 1
R2(config-router)#neighbor 1.1.1.1 update-source lo0
R2(config-router)#neighbor 3.3.3.3 remote-as 1        
R2(config-router)#neighbor 3.3.3.3 update-source lo0
R2(config-router)#neighbor 192.168.24.4 remote-as 2

R3(config)#router bgp 1
R3(config-router)#neighbor 1.1.1.1 remote-as 1
R3(config-router)#neighbor 1.1.1.1 update-source lo0
R3(config-router)#neighbor 2.2.2.2 remote-as 1       
R3(config-router)#neighbor 2.2.2.2 update-source lo0
R3(config-router)#neighbor 192.168.34.4 remote-as 2

R4(config)#router bgp 2
R4(config-router)#neighbor 192.168.24.2 remote-as 1
R4(config-router)#neighbor 192.168.34.3 remote-as 1
R4(config-router)#neighbor 192.168.45.5 remote-as 2

R5(config)#router bgp 2
R5(config-router)#neighbor 192.168.45.4 remote-as 2

R5(config-router)#neighbor 192.168.56.6 remote-as 3

R6(config)#router bgp 3
R6(config-router)#neighbor 192.168.56.5 remote-as 2

Let's start with R1 advertising 2.2.2.0/24 into BGP process.. note that this subnet is not directly connected to R1, but learned via EIGRP process.

R1(config)#router bgp 1
R1(config-router)#network  2.2.2.0 mask 255.255.255.0






You can see even in the advertising router, the metric is set to 409600. From where does it came??

Ah there it is.. BGP took this value for it's metric directly from the routing table (EIGRP learned). Now it works like some kind of redistribution right?

Let's see what we can see on other routers..


















You will not see the route in R2 & R6.. Why?

R1 will not advertise the route to R2 because the next hop to the route from R1 is R2..
R6 has only one neighbor which is R5; and the route in BGP table of R5 is not taken as a best route because there is no route to the next hop 192.168.34.3 from R5. We can fix it with a static route..
Let's put 2 static routes on R5 to reach both the possible eBGP next hops (192.168.34.3 & 192.168.24.2)

R5(config)#ip route 192.168.34.0 255.255.255.0 192.168.45.4
R5(config)#ip route 192.168.24.0 255.255.255.0 192.168.45.4

Now you will see the route on R6..
Actually what I wanted to show you is that, look for the metric values ip BGP tables as it propagates to different AS.. You will notice that the MED is unchanged in iBGP neighbors and will not be advertised to eBGP neighbors. But this behavior is little bit different if the eBGP neighbor is directly connected to the advertising router.

Let's advertise 192.168.13.0/24 from R2;

R2(config-router)#network 192.168.13.0 mask 255.255.255.0








Now you can see that the metric is advertised to both iBGP & eBGP neighbors..
Also you will notice that the lowest metric route is chosen as the best route to 192.168.13.0 from R4..

Now let's increase the metric of 192.168.13.0/24 route by a route-map..

R3(config)#access-list 10 permit 192.168.13.0 0.0.0.255

R3(config)#route-map MED permit 10
R3(config-route-map)#match ip address 10
R3(config-route-map)#set metric 400000
R3(config-route-map)#route-map MED permit 20

R3(config)#router bgp 1
R3(config-router)#neighbor 192.168.34.4 route-map MED out 







Now you can see that the lowest metric route is chosen as the best route.. If you recall, this R3 is not originating this route. It is only passing the route to eBGP neighbor which it learned from it's iBGP neighbor. In default behavior this R3 is not advertising it's MED to R4. But the policy made R3 to advertise the metric to R4 forcefully..

According to the theory, R5 must get the best route with the MED & R6 should get the best route without MED because R5 is in same AS as R4 but R6 is in a different AS..
Let's take a look..








As expected it is working..

Note:-  

You can also use route-maps to set metrics both to inbound and outbound directions to both types of neighbors (iBGP & eBGP).

Monday, August 21, 2017

Origin code is the fifth BGP attribute in the list.. There are three origin codes you could see in the BGP table..

i - IGP for the networks you advertised using network command of BGP
e - EGP for an old routing protocol which is no longer used
? - Incomplete for the redistributed routes into BGP

Precedence comes like i > e > ? 
Because e is no longer seen,

i > ? , BGP advertised routes are preferred over redistributed routes..

Let's see an example..
















Basic BGP configuration is like the following..

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)#network 10.10.10.0 mask 255.255.255.0
R2(config-router)#network 20.20.20.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)#redistribute connected

Both 10.10.10.0/24 & 20.20.20.0/24 networks are advertised from R2 by the network command while same networks are redistributed to the BGP process by R3. Let's see the BGP table of R1..









You can see, for both the networks, R2's route has become the best route because of their origin code is 'i'.

Note:- 

Because I just redistributed all the connected routes in R3, you can see 192.168.13.0/24 is in BGP table and it is selected as the best route. But note the 'r' in front of the '>' mark. Which means a RIB failure. This is because 192.168.13.0/24 is connected to R1, it will not add the BGP route to routing table. You can verify it by looking the routing table of R1..




Friday, August 18, 2017

AS-Path is the 4th BGP attribute in the list..

(1) Can use to choose the best path for inbound traffic which means influence routing in eBGP neighbors..
(2) Route with the shortest AS-Path is better..

Normally this is the real attribute which is by default working on Internet.. However we can manipulate the traffic by prepending the AS path.. Which means we can add our own AS number multiple times so the AS-path becomes longer. From this method we can tell eBGP neighbors to send the traffic to specific routes from the path we need.

Let's see an example..

















Basic routing (EIGRP) configurations in AS-1

R1(config)#router eigrp 10
R1(config-router)#network 192.168.12.0
R1(config-router)#network 192.168.13.0
R1(config-router)#network 1.0.0.0

R2(config)#router eigrp 10
R2(config-router)#network 192.168.12.0
R2(config-router)#network 2.0.0.0

R3(config)#router eigrp 10
R3(config-router)#network 192.168.13.0
R3(config-router)#network 3.0.0.0

Basic routing (static) on R1 to reach the R2-R4 & R3-R4 links

R1(config)#ip route 192.168.24.0 255.255.255.0 192.168.12.2
R1(config)#ip route 192.168.34.0 255.255.255.0 192.168.13.3

Basic BGP configurations

R1(config)#router bgp 1
R1(config-router)#neighbor 2.2.2.2 remote-as 1
R1(config-router)#neighbor 2.2.2.2 update-source Loopback0
R1(config-router)#neighbor 3.3.3.3 remote-as 1
R1(config-router)#neighbor 3.3.3.3 update-source Loopback0

R2(config)#router bgp 1
R2(config-router)#neighbor 1.1.1.1 remote-as 1   
R2(config-router)#neighbor 1.1.1.1 update-source lo0
R2(config-router)#neighbor 3.3.3.3 remote-as 1           
R2(config-router)#neighbor 3.3.3.3 update-source lo0
R2(config-router)#neighbor 192.168.24.4 remote-as 2
R2(config-router)#network 192.168.12.0 mask 255.255.255.0
R2(config-router)#network 192.168.13.0 mask 255.255.255.0

R3(config)#router bgp 1
R3(config-router)#neighbor 1.1.1.1 remote-as 1
R3(config-router)#neighbor 1.1.1.1 update-source lo0
R3(config-router)#neighbor 2.2.2.2 remote-as 1       
R3(config-router)#neighbor 2.2.2.2 update-source lo0
R3(config-router)#neighbor 192.168.34.4 remote-as 2
R3(config-router)#network 192.168.12.0 mask 255.255.255.0
R3(config-router)#network 192.168.13.0 mask 255.255.255.0

R4(config)#router bgp 2
R4(config-router)#neighbor 192.168.24.2 remote-as 1
R4(config-router)#neighbor 192.168.34.3 remote-as 1

In red lines, you can see that I have advertised R1-R2 & R1-R3 links in both R2 & R3. This is possible since R2 and R3 has valid routes to those subnets in their routing tables.

Now let's see what R4 can see..










Because of the Metric values, the best path to 192.168.12.0 is chosen through R2 & the best path to 192.168.13.0 is chosen through R3..

This means that the routers in AS-2 sends traffic to R2 to reach 192.168.12.0 network and sends traffic to R3 to reach 192.168.13.0 network..








From AS-1, we can change the routing of AS-2 router (R4) by using route maps..

Here is how to change the routing path to 192.168.12.0 network..

R2(config)#access-list 10 permit 192.168.12.0 255.255.255.0

R2(config)#route-map AS-PATH-R2 permit 10
R2(config-route-map)#match ip address 10
R2(config-route-map)#set AS-path prepend 1 
R2(config-route-map)#route-map AS-PATH-R2 permit 20

R2(config-route-map)#router bgp 1
R2(config-router)#neighbor 192.168.24.4 route-map AS-PATH-R2 out 












Now you can see that the path is changed in R4. Notice that the Path is 1 1 i through R2 and it is 1 i through R3. We only added one "1" in the route map, the other 1 came from the default behavior. You can see even the Metric is large, path from R3 is preferred because AS-Path comes before Metric in BGP..

You can tweek the route to 192.168.13.0 from R3 using a route map too.

Note:- 

This is pointless to be used with iBGP neighbors because they do not update the AS path..
The AS number use to prepend must be the router's AS number. Cannot use any arbitrary number..
Also this can be used both inbound & outbound routing updates to an eBGP neighbor..

Thursday, August 17, 2017

Origination is the 3rd BGP attribute in the list..

Routers will prefer a route if it’s locally originated, its next hop IP address is 0.0.0.0 in the BGP table..

Let's see an example..

Basic BGP configuration..

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

R2(config)#router bgp 2
R2(config-router)#network 10.10.10.0 mask 255.255.255.0
R2(config-router)#network 20.20.20.0 mask 255.255.255.0
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 192.168.12.1 remote-as 1

R3(config)#router bgp 2
R3(config-router)#bgp log-neighbor-changes
R3(config-router)#network 10.10.10.0 mask 255.255.255.0
R3(config-router)#network 20.20.20.0 mask 255.255.255.0
R3(config-router)#neighbor 1.1.1.1 remote-as 2
R3(config-router)#neighbor 1.1.1.1 update-source Loopback0

Basic routing (static) on R2 & R3 to reach their loopbacks..

R2(config)#ip route 3.3.3.0 255.255.255.0 192.168.23.3
R3(config)#ip route 1.1.1.0 255.255.255.0 192.168.23.2








You can see on R2, the next hop 0.0.0.0 routes are always preferred. On R3, you cannot see the 10.10.10.0/24 & 20.20.20.0/24 routes which were originated on R1 because R2 is only advertising the best routes to R3. Because R2 takes it's locally originated routes as the best routes in R2's BGP table, it does not even advertise the routes learnt from R1..

Note:- 

The true reason above routes are chosen as the best routes is the Weight because these are Cisco routers. In Cisco routers, the Weight comes the 1st attribute to make the decision..

Local Preference is the 2nd BGP attribute in the list.. Because Weight is a Cisco proprietary, Local Preference becomes the most well known attribute in the industry..

(1) Can use to choose the best path for outbound traffic..
(2) Local Preference is sent to all iBGP peers only..
(3) Path with the highest Local Preference is preferred, default is 100..

Let's see an example..

Basic routing (EIGRP) configurations in AS-1

R1(config)#router eigrp 10
R1(config-router)#network 192.168.12.0
R1(config-router)#network 192.168.13.0
R1(config-router)#network 1.0.0.0

R2(config)#router eigrp 10
R2(config-router)#network 192.168.12.0
R2(config-router)#network 2.0.0.0

R3(config)#router eigrp 10
R3(config-router)#network 192.168.13.0
R3(config-router)#network 3.0.0.0

Basic routing (static) on R1 to reach the R2-R4 & R3-R4 links

R1(config)#ip route 192.168.24.0 255.255.255.0 192.168.12.2
R1(config)#ip route 192.168.34.0 255.255.255.0 192.168.13.3

Basic BGP configurations

R1(config)#router bgp 1
R1(config-router)#neighbor 2.2.2.2 remote-as 1
R1(config-router)#neighbor 2.2.2.2 update-source Loopback0
R1(config-router)#neighbor 3.3.3.3 remote-as 1
R1(config-router)#neighbor 3.3.3.3 update-source Loopback0

R2(config)#router bgp 1
R2(config-router)#neighbor 1.1.1.1 remote-as 1  
R2(config-router)#neighbor 1.1.1.1 update-source lo0
R2(config-router)#neighbor 3.3.3.3 remote-as 1          
R2(config-router)#neighbor 3.3.3.3 update-source lo0
R2(config-router)#neighbor 192.168.24.4 remote-as 2

R3(config)#router bgp 1
R3(config-router)#neighbor 1.1.1.1 remote-as 1
R3(config-router)#neighbor 1.1.1.1 update-source lo0
R3(config-router)#neighbor 2.2.2.2 remote-as 1      
R3(config-router)#neighbor 2.2.2.2 update-source lo0
R3(config-router)#neighbor 192.168.34.4 remote-as 2

R4(config)#router bgp 2
R4(config-router)#neighbor 192.168.24.2 remote-as 1
R4(config-router)#neighbor 192.168.34.3 remote-as 1
R4(config-router)#network 4.4.4.0 mask 255.255.255.0
R4(config-router)#network 5.5.5.0 mask 255.255.255.0







Now by default you can see that the path through R2 is preferred to reach R4's networks..

Give preference to all the routes coming from one router?

If you want to give higher preference to all routes from R3;

R3(config-router)#bgp default local-preference 300








Now you can see the best path is changed with the Local Preference..

We only add a configuration line to R3, let's see the R2's BGP table..






You can see that the Local Preference is 300, but the routes are not given the preference. This is because the next hop is directly connected.. Unless otherwise, the routes advertised from R3 will be given preference by all the iBGP neighbors in AS-1..

Let's look at the R3's BGP table..









Well here is some thing to remember.. Local Preference is not been added to the configured router's BGP table. The router will only advertise it to it's iBGP neighbors..

Give preference to some routes coming from one router?

Now If you want to give preference only to some routes learned from one router you have to use a route-map.
Let's say that R4's 4.4.4.0/24 route to be preferred through R2 on iBGP peers in AS-1..
Here is how to do it..

R2(config)#access-list 10 permit 4.4.4.0 0.0.0.255

R2(config)#route-map SET_LP permit 10
R2(config-route-map)#match ip address 10
R2(config-route-map)#set local-preference 400
R2(config-route-map)#route-map SET_LP permit 20

R2(config-route-map)#router bgp 1
R2(config-router)#neighbor 192.168.24.4 route-map SET_LP in









Now you can see the preference 400 is advertised with the 4.4.4.0/24 route to the iBGP neighbors of R2. Let's see R2's BGP table now..












Well you can see the 4.4.4.0/24 route is given the 400 preference even in the R2's (the router which the route-map is configured) BGP table.. But you saw if the preference is given under BGP commands, it is not added to it's BGP table.. This is because the policy is applied inbound to the traffic and the other case really applied to the outbound to neighbors..

Give preference to some routes advertised to some neighbors?

This can be achieved through route maps too. We applied the route map on R2 to an eBGP neighbor in bound. How about applying it to an iBGP neighbor outbound..

R2(config-router)#neighbor 1.1.1.1 route-map SET_LP out









Here you can see the preference value is not added to R3's & R2's BGP tables. Because the route map is applied outbound, R2 does not update the preference values itself..

To know something interestin please go here.

Weight is the 1st attribute in the list.. It is the 1st thing which will be considered by a router to identify the best route. But because it is Cisco proprietary, you will not see it often.

(1) Can use to choose the best path for outbound traffic..
(2) Weight is not exchanged between routers, only local to the router..
(3) The path with the highest weight is preferred, default is 0..

Because weight is local to the router, we cannot use it with the routes we advertise to other neighbors. Route maps will be only applied to in bound traffic.. Let's see an example..


Basic BGP configuration is like the following..

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)#network 10.10.10.0 mask 255.255.255.0
R2(config-router)#network 20.20.20.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)#network 10.10.10.0 mask 255.255.255.0
R3(config-router)#network 20.20.20.0 mask 255.255.255.0

For both 10.10.10.0/24 and 20.20.20.0/24 networks, best routes are learnt via 192.168.12.2 by default.. Because all other attributes are equal, the lowest router-id has become the most preferred..







Let's change this by changing the Weight of the routes.

Give higher weight to all the routes coming from one router?

If I want to make all the routes learning from R3 to be preferred, I would simply change the weight of the neighbor command for R3 on R1..

R1(config-router)#neighbor 192.168.13.3 weight 500

Hit clear ip bgp * to reset BGP neighbors and see the BGP table again..









Now you can see all the routes learnt via R3 is preferred now..

Give higher weight to some routes coming from one router?

Let's say I want to change only 20.20.20.0/24 to be weighted to 500. I would have to use a route map.. If you want to learn about route-maps, go here.

Let's clear the previous neighbor command and start again..

R1(config)#access-list 10 permit 20.20.20.0 0.0.0.255

R1(config)#route-map SET_WEIGHT permit 10
R1(config-route-map)#match ip address 10
R1(config-route-map)#set weight 500
R1(config)#route-map SET_WEIGHT permit 20

R1(config-router)#neighbor 192.168.13.3 route-map SET_WEIGHT in










Note:- 

The last line of the route map configuration route-map SET_WEIGHT permit 20 is necessary because the route map is applied to a BGP neighbor to filter routes. Without that line, only matching routes will be allowed, all other routes from that neighbor will be not advertised..

Also note that the default weight for a locally originated route is 32768..