实验拓扑图
基本配置如图所示
要求:R5上利用loopback口建立多个分段ip,利用bgp选路原则让单网段数据通过R6转发,双网段数据通过R7转发
分段ip为:192.168.1.0/24
192.168.2.0/24
192.168.3.0/24
192.168.4.0/24
实验配置:
首先,在R6,R7,R8上跑ospf协议
R6:
R6(config)#router ospf 100
R6(config-router)# router-id 6.6.6.6
R6(config-router)# network 6.6.6.6 0.0.0.0 area 0
R6(config-router)# network 10.1.68.0 0.0.0.3 area 0
R7:
R7(config)#router ospf 100
R7(config-router)# router-id 7.7.7.7
R7(config-router)# network 7.7.7.7 0.0.0.0 area 0
R7(config-router)# network 10.1.78.0 0.0.0.3 area 0
R8:
R8(config)#router ospf 100
R8(config)# router-id 8.8.8.8
R8(config)# network 8.8.8.8 0.0.0.0 area 0
R8(config)# network 10.1.68.0 0.0.0.3 area 0
R8(config)# network 10.1.78.0 0.0.0.3 area 0
然后,整体跑bgp协议
R5:
R5(config)#router bgp 20
R5(config-router)#bgp router-id 5.5.5.5
R5(config-router)#neighbor 10.1.56.2 remote-as 10
R5(config-router)#neighbor 10.1.57.2 remote-as 10
R5(config-router)#network 5.5.5.5 mask 255.255.255.255
R5(config-router)#network 192.168.1.1 mask 255.255.255.255
R5(config-router)#network 192.168.2.1 mask 255.255.255.255
R5(config-router)#network 192.168.3.1 mask 255.255.255.255
R5(config-router)#network 192.168.4.1 mask 255.255.255.255
R6:
R6(config)#router bgp 10
R6(config-router)#bgp router-id 6.6.6.6
R6(config-router)# neighbor 8.8.8.8 remote-as 10
R6(config-router)# neighbor 8.8.8.8 update-source Loopback 0
R6(config-router)# neighbor 8.8.8.8 next-hop-self
R6(config-router)# neighbor 10.1.56.1 remote-as 20
R7:
R7(config)#router bgp 10
R7(config-router)#bgp router-id 7.7.7.7
R7(config-router)# neighbor 8.8.8.8 remote-as 10
R7(config-router)# neighbor 8.8.8.8 update-source Loopback 0
R7(config-router)# neighbor 8.8.8.8 next-hop-self
R7(config-router)# neighbor 10.1.57.1 remote-as 20
R8:
R8(config)#router bgp 10
R8(config-router)# bgp router-id 8.8.8.8
R8(config-router)# neighbor 6.6.6.6 remote-as 10
R8(config-router)# neighbor 6.6.6.6 update-source Loopback 0
R8(config-router)# neighbor 7.7.7.7 remote-as 10
R8(config-router)# neighbor 7.7.7.7 update-source Loopback 0
R8(config-router)# network 8.8.8.8 mask 255.255.255.255
最后,配置weight分流
R8:
R8(config)#access-list 10 permit 192.168.1.0 0.0.254.255 //匹配单数网段的IP
R8(config)#access-list 20 permit 192.168.2.0 0.0.254.255 //匹配双数网段的IP
R8(config)#route-map dans permit 10
R8(config-route-map)# match ip address 10
R8(config-route-map)# set weight 10 //设置单数条目权重
R8(config)#route-map dans permit 20 //用于允许其他所有
R8(config)#route-map ous permit 10
R8(config-route-map)# match ip address 20
R8(config-route-map)# set weight 10 //设置双数条目权重
R8(config)#route-map ous permit 20 //用于允许其他所有
R8(config)#router bgp 10
R8(config-router)# neighbor 7.7.7.7 route-map ous in //调用,在R7发送入口方向
R8(config-router)# neighbor 6.6.6.6 route-map dans in //调用,在R6发送入口方向
结果验证: