先了解一下weight属性的一些概念。
1 weight属性是cisco的私有属性,是一种选路属性,用来选择一条最优路径。
2 weight属性只对本地路由器有效。该属性不会被传递。
3 weight值的取值范围是0-65535。对于本路由器产生的路由,weight的默认值=32768;对于所有学到的路由,weight的默认值=0。
4 对于到同一目的地的多条路径来说,weight值越高的路径越优先
配置BGP
RTA#sh run | b r b
router bgp 100
no synchronization
neighbor 12.0.0.1 remote-as 4
neighbor 23.0.0.3 remote-as 300
no auto-summary
RTE#sh run | b r b
router bgp 4
no synchronization
network 175.10.0.0 /将该网络宣告进BGP中。
neighbor 12.0.0.2 remote-as 100
neighbor 14.0.0.4 remote-as 200
no auto-summary
RTB#sh run | b r b
router bgp 200
no synchronization
neighbor 14.0.0.1 remote-as 4
neighbor 34.0.0.3 remote-as 300
no auto-summary
RTC#sh run | b r b
router bgp 300
no synchronization
neighbor 23.0.0.2 remote-as 100
neighbor 34.0.0.4 remote-as 200
no auto-summary
在RTC上进行查看
RTC#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
* 175.10.0.0 34.0.0.4 0 200 4 i
*> 23.0.0.2 0 100 4 i
这时可以看到RTC选择RTA作为到达目标的下一跳。现在要做的就是在RTC上修改weight值,让RTC选择RTB作为到达目标的下一跳。
在RTC上直接修改weight值
RTC(config)#router bgp 300
RTC(config-router)#neighbor 23.0.0.2 weight 100
RTC(config-router)#neighbor 34.0.0.4 weight 200
将RTB发来的路由的weight值修改的大于RTA的。
RTC#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
* 175.10.0.0 23.0.0.2 100 100 4 i
*> 34.0.0.4 200 200 4 i
这时可以看到RTC现在选择RTB作为下一跳到达目标网络 175.10.0.0
RTC#sh ip route
34.0.0.0/24 is subnetted, 1 subnets
C 34.0.0.0 is directly connected, Serial2/2
B 175.10.0.0/16 [20/0] via 34.0.0.4, 00:11:24
23.0.0.0/24 is subnetted, 1 subnets
C 23.0.0.0 is directly connected, Serial2/1
查看路由表也可以看到,RTC到达175.10.0.0网络的下一跳是34.0.0.4(RTB)
这也证明了到同一目标网络的多条路径,weight值越大,则该路径越优先
也可以用AS列表和route-map来修改weight。
首先建立一个AS列表
RTC(config)#ip as-path access-list 1 permit ^100
这条语句的含义是匹配所有AS路径 的字符串开始是100的路由条目。
然后建立route-map
RTC(config)#route-map WEIGHT permit 10
RTC(config-route-map)#match as-path 1 /匹配AS列表1
RTC(config-route-map)#set weight 100 /设定weight=100
这条语句的意义是将匹配上AS列表1的路由的weight设为100
RTC(config)#route-map WEIGHT permit 20
RTC(config-route-map)#set weight 200
这条语句的意义是所有其它的路由的weight设为200
最后在BGP进程中调用该route-map
RTC(config)#router bgp 300
RTC(config-router)#neighbor 23.0.0.2 route-map WEIGHT in
RTC(config-router)#neighbor 34.0.0.4 route-map WEIGHT in
RTC#sh ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 175.10.0.0 34.0.0.4 200 200 4 i
* 23.0.0.2 100 100 4 i
可以看到这时RTC选择了RTB作为到达目标网络的下一跳,因为这条路由的weight值比较大。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/36438/showart_302312.html