1、当本地出口路由器,有多条外出自治系统的链路时,应用权重(Weight)属性能够决定数据流从本地路由器哪条出口链路流出本地自治系统.
2、权重(Weight)属性为 Cisco 私有属性。
由于实验条件限制,所有连接统一用串行接口,但这里假设R1和R4的连接是100Mbps的快速以太网。
网络图:
配置各路由器IP地址等基本信息,测试互连可达。
配置各路由器的BGP协议,使用show ip bgp确认协议工作正常。
建议GP配置顺序为R1、R2、R3、R4,以方便实验(实验要求R1到150段网络的路径要经过R2),按顺序配置的原因,主要是因为,在本实验中R1到达150.150.1.0/24网络的两条路径,在BGP中,会认为是两条等价的,但BGP又不用于负载均衡,因此从R1出发,会优先从R2到达目标。
原因是BGP的选路规则:1、最行收到的路由优先于后收到的路由。2、优先选择BGP的Router-ID较低的路由。
查看R1的路由表:
R1#show ip route
Gateway of last resort is not set
C 192.168.4.0/24 is directly connected, Serial0/1
C 192.168.1.0/24 is directly connected, Serial0/0
B 192.168.2.0/24 [20/0] via 192.168.1.2, 00:00:43
B 192.168.3.0/24 [20/0] via 192.168.4.1, 00:00:12
150.150.0.0/24 is subnetted, 1 subnets
B 150.150.1.0 [20/0] via 192.168.1.2, 00:00:43 ---->走R2
查看R1的BGP数据库:
R1#show ip bgp
BGP table version is 6, local router ID is 192.168.4.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
* 150.150.1.0/24 192.168.4.1 0 64515 64514 i
*> 192.168.1.2 0 64513 64514 i
---->由于R2通告得比R4早,路由ID也比R4较小,所以R1去150网段优先选R2
*> 192.168.1.0 0.0.0.0 0 32768 i
* 192.168.1.2 0 0 64513 i
* 192.168.2.0 192.168.4.1 0 64515 64514 i
*> 192.168.1.2 0 0 64513 i
* 192.168.3.0 192.168.1.2 0 64513 64514 i
*> 192.168.4.1 0 0 64515 i
* 192.168.4.0 192.168.4.1 0 0 64515 i
*> 0.0.0.0 0 32768 i
查看R1邻居表:
R1#show ip bgp neighbors
BGP neighbor is 192.168.1.2, remote AS 64513, external link
BGP version 4, remote router ID 192.168.2.1
BGP state = Established, up for 00:07:40
Last read 00:00:40, last write 00:00:40, hold time is 180, keepalive interval is 60 seconds
……………………
BGP neighbor is 192.168.4.1, remote AS 64515, external link
BGP version 4, remote router ID 192.168.4.1 ---->路由ID,前一个比较小
BGP state = Established, up for 00:07:44
Last read 00:00:43, last write 00:00:43, hold time is 180, keepalive interval is 60 seconds
……………………
通过拓扑可以看出,64512到达150段网络的最佳路径应该是经过64515,而不是经过64513,因此BGP选择的是次佳路由。
可以在R1上配置权重属性来解决次佳路由问题:
R1(config)#router bgp 64512
R1(config-router)#neighbor 192.168.1.2 weight 50 ----->从R2来的路由权重是50
R1(config-router)#neighbor 192.168.4.1 weight 100 ----->从R4来的路由权重是100
R1(config-router)#end
R1#clear ip bgp * soft ----->加速收敛
为了确认权重值对路由的影响,查看R1的路由表和BGP数据库:
R1#show ip route
Gateway of last resort is not set
C 192.168.4.0/24 is directly connected, Serial0/1
C 192.168.1.0/24 is directly connected, Serial0/0
B 192.168.2.0/24 [20/0] via 192.168.4.1, 00:02:22
B 192.168.3.0/24 [20/0] via 192.168.4.1, 00:17:34
150.150.0.0/24 is subnetted, 1 subnets
B 150.150.1.0 [20/0] via 192.168.4.1, 00:02:22 ---->改为去往R4
R1#show ip bgp
BGP table version is 12, local router ID is 192.168.4.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
*> 150.150.1.0/24 192.168.4.1 100 64515 64514 i
* 192.168.1.2 50 64513 64514 i
*> 192.168.1.0 0.0.0.0 0 32768 i ---->直连网络,默认为32768,避免路由环路
* 192.168.1.2 0 50 64513 i
*> 192.168.2.0 192.168.4.1 100 64515 64514 i
* 192.168.1.2 0 50 64513 i
* 192.168.3.0 192.168.1.2 50 64513 64514 i
*> 192.168.4.1 0 100 64515 i
* 192.168.4.0 192.168.4.1 0 100 64515 i
*> 0.0.0.0 0 32768 i
BGP的选路规则之一:优先选择权重高的路由。因此64512数据流出本自治系统时均选择了走R4,但是这里又出现了另一个问题,从R1去往192.168.2.0/24的网络经过了R4,这又是一个次佳路由,单单使用以上方法不是完美的解决方案,所以使用路由映射表才是王道,一切控制尽在掌中。
在R1上配置路由映射表:
R1(config)#router bgp 64512
R1(config-router)#no neighbor 192.168.1.2 weight 50
R1(config-router)#no neighbor 192.168.4.1 weight 100 ------->删删删删删
R1(config-router)#exi
R1(config)#access 1 per 150.150.1.0 0.0.0.255 ------>划定要操作的网络范围
R1(config)#route-map set-weight per 10
R1(config-route-map)#match ip add 1
R1(config-route-map)#set weight 100 ----->设置权重100
R1(config-route-map)#exit
R1(config)#route-map set-weight 20 ----->下面没有操作,默认允许所有
R1(config-route-map)#exit
R1(config)#router bgp 64512
R1(config-router)#neighbor 192.168.4.1 route-map set-weight in ----->用在进方向
R1(config-router)#end
R1#clear ip bgp * soft
再查看R1的路由表和BGP数据库:
R1#show ip route
Gateway of last resort is not set
C 192.168.4.0/24 is directly connected, Serial0/1
C 192.168.1.0/24 is directly connected, Serial0/0
B 192.168.2.0/24 [20/0] via 192.168.1.2, 00:04:00 ---->这个走R2
B 192.168.3.0/24 [20/0] via 192.168.4.1, 00:03:59
150.150.0.0/24 is subnetted, 1 subnets
B 150.150.1.0 [20/0] via 192.168.4.1, 00:03:59 ---->这个走R4
R1#show ip bgp
BGP table version is 11, local router ID is 192.168.4.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
*> 150.150.1.0/24 192.168.4.1 100 64515 64514 i ----->仅有此路由的权重被配置为100
* 192.168.1.2 0 64513 64514 i
*> 192.168.1.0 0.0.0.0 0 32768 i
* 192.168.1.2 0 0 64513 i
* 192.168.2.0 192.168.4.1 0 64515 64514 i
*> 192.168.1.2 0 0 64513 i
*> 192.168.3.0 192.168.4.1 0 0 64515 i
* 192.168.1.2 0 64513 64514 i
*> 192.168.4.0 0.0.0.0 0 32768 i
* 192.168.4.1 0 0 64515 i
测试和跟踪:
R1#ping 150.150.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 150.150.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 28/60/96 ms
R1#traceroute 150.150.1.1
Type escape sequence to abort.
Tracing the route to 150.150.1.1
1 192.168.4.1 24 msec 44 msec 28 msec
2 192.168.3.1 [AS 64515] 44 msec * 28 msec
一切正常。