首页 > CCNP实验报告 > CCNP实验---多种方法影响BGP路径选择

CCNP实验---多种方法影响BGP路径选择

2011年9月3日 02:08 发表评论 阅读评论

1、实验目的:修改attribute中的weigtht、local preference、AS-path以及MED属性值来满足BGP路径选择需求

2、实验环境:C3640-IK9O3S-M Version 12.4(10)

3、实验拓扑
BGP_attribute

4、实验描述

四个路由器运行BGP,R1与R2、R4与R3为IBGP关系,R1与R4、R2与R3为EBGP关系。四个路由器分别使用环回口建立子网,且让对方互相学习到路由信息,实现全拓扑互通。

按照正常配置,会发现R3到达R1的1.1.1.1/24网段有两种路径,第一种,R3->R4->R1,第二种,R3->R2->R1。根据BGP选路的11个原则(这里就不一一列出来了,需要的话到思科官方网站上查阅),匹配第7条---Prefer EBGP over IBGP paths,故R3会选择第二种路径,经过R2。

但是R3到达1.1.1.1/24网段使用R2作为下一跳并不是最佳路径选择,因为R3与R2是串行链路,而R1与R4是以太网线路,很明显我们应该选择带宽较大的R4作为下一跳。为了让R3选择R4作为下一跳,我们可以分别修改BGP attribute中的weigtht、local preference、AS-path以及MED值来达到目的。

5、实验步骤

A、R1基本配置

interface Loopback0
ip address 1.1.1.1 255.255.255.0
!
interface Serial0/0
ip address 12.0.0.1 255.255.255.0
!
interface FastEthernet1/0
ip address 14.0.0.1 255.255.255.0
!
router rip
version 2
network 1.0.0.0
network 12.0.0.0
!
router bgp 12
no synchronization
bgp router-id 1.1.1.1
bgp log-neighbor-changes
network 1.1.1.0 mask 255.255.255.0
neighbor 2.2.2.2 remote-as 12
neighbor 2.2.2.2 update-source Loopback0
neighbor 2.2.2.2 next-hop-self
neighbor 14.0.0.4 remote-as 34
no auto-summary

B、R2基本配置

interface Loopback0
ip address 2.2.2.2 255.255.255.0
!
interface Serial0/0
ip address 12.0.0.2 255.255.255.0
!
interface Serial0/1
ip address 23.0.0.2 255.255.255.0
!
router rip
version 2
network 2.0.0.0
network 12.0.0.0
no auto-summary
!
router bgp 12
no synchronization
bgp router-id 2.2.2.2
bgp log-neighbor-changes
network 2.2.2.0 mask 255.255.255.0
neighbor 1.1.1.1 remote-as 12
neighbor 1.1.1.1 update-source Loopback0
neighbor 1.1.1.1 next-hop-self
neighbor 23.0.0.3 remote-as 34
no auto-summary

C、R3基本配置

interface Loopback0
ip address 3.3.3.3 255.255.255.0
!
interface Serial0/0
ip address 34.0.0.3 255.255.255.0
!
interface Serial0/1
ip address 23.0.0.3 255.255.255.0
!
router rip
version 2
network 3.0.0.0
network 34.0.0.0
no auto-summary
!
router bgp 34
no synchronization
bgp router-id 3.3.3.3
bgp log-neighbor-changes
network 3.3.3.0 mask 255.255.255.0
neighbor 4.4.4.4 remote-as 34
neighbor 4.4.4.4 update-source Loopback0
neighbor 4.4.4.4 next-hop-self
neighbor 23.0.0.2 remote-as 12
no auto-summary

D、R4基本配置

interface Loopback0
ip address 4.4.4.4 255.255.255.0
!
interface Serial0/0
ip address 34.0.0.4 255.255.255.0
!
interface Serial0/1
no ip address
shutdown
serial restart-delay 0
!
interface FastEthernet1/0
ip address 14.0.0.4 255.255.255.0
!
router rip
version 2
network 4.0.0.0
network 34.0.0.0
no auto-summary
!
router bgp 34
no synchronization
bgp router-id 4.4.4.4
bgp log-neighbor-changes
network 4.4.4.0 mask 255.255.255.0
neighbor 3.3.3.3 remote-as 34
neighbor 3.3.3.3 update-source Loopback0
neighbor 3.3.3.3 next-hop-self
neighbor 14.0.0.1 remote-as 12
no auto-summary

E、查看R3路由信息

R3#sh ip ro

34.0.0.0/24 is subnetted, 1 subnets
C       34.0.0.0 is directly connected, Serial0/0
1.0.0.0/24 is subnetted, 1 subnets
B       1.1.1.0 [20/0] via 23.0.0.2, 00:01:24
2.0.0.0/24 is subnetted, 1 subnets
B       2.2.2.0 [20/0] via 23.0.0.2, 00:10:09
3.0.0.0/24 is subnetted, 1 subnets
C       3.3.3.0 is directly connected, Loopback0
4.0.0.0/24 is subnetted, 1 subnets
R       4.4.4.0 [120/1] via 34.0.0.4, 00:00:21, Serial0/0
23.0.0.0/24 is subnetted, 1 subnets
C       23.0.0.0 is directly connected, Serial0/1

R3#sh ip bgp

Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.0/24       23.0.0.2                               0 12 i
* i                 4.4.4.4                  0    100      0 12 i

* i2.2.2.0/24       4.4.4.4                  0    100      0 12 i
*>                  23.0.0.2                 0             0 12 i
*> 3.3.3.0/24       0.0.0.0                  0         32768 i
r>i4.4.4.0/24       4.4.4.4                  0    100      0 i

注:根据BGP路由选择策略,由于默认weight、local preference、AS-path、MED都一样,所以R3会根据第7条路由策略---EBGP优先与IBGP。R3与R2是EBGP关系而与R4是EBGP,所以选择R4作为下一跳---23.0.0.2

F、使用route-map修改weight属性值

由于weight值只对本路由器有效。所以当R3收到从R4宣告1.1.1.0/24网络时,将weight值改为100(只要比默认值0大就可以),那么R3就会选择R4作为下一跳。

//定义ACL
R3(config)#access-list 1 permit 1.1.1.0 0.0.0.255

//定义route-map,将1.1.1.0/24路由的weight值设为100
R3(config)#route-map set_weight permit 10
R3(config-route-map)#match ip address 1
R3(config-route-map)#set weight 100
R3(config-route-map)#exit
//放过其它的流量
R3(config)#route-map set_weight permit 20
R3(config-route-map)#exit

//将route-map应用于R4对其宣告路由的入方向
R3(config)#router bgp 34
R3(config-router)#neighbor 4.4.4.4 route-map set_weight in

//软清BGP进程
R3#clear ip bgp * soft

注:weight属性是思科私有的,只能配置在本地路由器,不会宣告给任何其它BGP邻居。如果这条路由是本地产生的,weight默认值为32768,否则weight值为0。weight属性用于决定数据流从本地的哪个出口流出AS,选择高者。

G、使用route-map修改local preference属性值

R3收到R2和R4关于1.1.1.0/24 的local preference值都为100。由于local preference只会在同一个AS内传播(只会传播给IBGP邻居),则只需将R4将此路由告诉给R3时,local preference值设为200(选择local preference值高的)。

//定义ACL
R4(config)#access-list 1 permit 1.1.1.0 0.0.0.255

//定义route-map,将1.1.1.0/24路由local-preference值设为200
R4(config)#route-map set_lp permit 10
R4(config-route-map)#match ip address 1
R4(config-route-map)#set local-preference 200
R4(config-route-map)#exit
//放过其它的流量
R4(config)#route-map set_lp permit 20
R4(config-route-map)#exit

//将route-map应用于R1对其宣告路由的入方向
R4(config)#router bgp 34
R4(config-router)#neighbor 14.0.0.1 route-map set_lp in

//软清BGP进程
R4#clear ip bgp * soft

注:local preference属性只会传递给IBGP邻居,默认是100。用于影响数据流如何流出本地自治系统,选择高者

H、使用route-map修改AS-path属性值

R3收到R4和R2关于1.1.1.0/24路由时,AS-Path属性值都只有一个AS号。想要通过AS-Path来影响R3的关于该网络的下一跳,那么可以修改AS-Path值。让R2经过更多一个的AS号。由于AS-Path是用于防止环路的,所以建议R2增加的AS是自己的AS号。(手动添加的AS号是允许重复的)

//定义ACL
R2(config)#access-list 1 permit 1.1.1.0 0.0.0.255

//定义route-map,在1.1.1.0/24路由的AS-path属性上添加两个AS号使路径变长
R2(config)#route-map set_prepend permit 10
R2(config-route-map)#match ip address 1
R2(config-route-map)#set as-path prepend 12 12
R2(config-route-map)#exit
//放过其它的流量
R2(config)#route-map set_prepend permit 20
R2(config-route-map)#exit

//将route-map应用于向R3宣告路由的出方向
R2(config)#router bgp 12
R2(config-router)#neighbor 23.0.0.3 route-map set_prepend out

//软清BGP进程
R2#clear ip bgp * soft

注:在set as-path prepend后添加的AS号,最好是本地自治系统号,否则可能会产生无效路由。
当路由器将信息传给EBGP时会在as-path前面加上自己的AS号,传给IBGP则不加。优先选择AS-PATH最短的路径。

R3的bgp表

R3#sh ip bgp

Network          Next Hop            Metric LocPrf Weight Path
*  1.1.1.0/24       23.0.0.2                               0 12 12 12 i
*>i                 4.4.4.4                  0    100      0 12 i
* i2.2.2.0/24       4.4.4.4                  0    100      0 12 i
*>                  23.0.0.2                 0             0 12 i
*> 3.3.3.0/24       0.0.0.0                  0         32768 i
r>i4.4.4.0/24       4.4.4.4                  0    100      0 i

I、使用route-map修改MED属性值

R3收到原本R2与R4关于1.1.1.0/24网络的MED值都为0。由于MED是通过EBGP进行传播的,且R3会选择MED值小的到达该网络,所以只要将R2关于此网络的MED值设为100(比默认值0高),则R3会选择R4作为下一跳(选择MED值小的)。

//定义ACL
R2(config)#access-list 1 permit 1.1.1.0 0.0.0.255

//定义route-map,将1.1.1.0/24路由metric值设为100
R2(config)#route-map set_med permit 10
R2(config-route-map)#match ip address 1
R2(config-route-map)#set metric 100
R2(config-route-map)#exit
//放过其它的流量
R2(config)#route-map set_med permit 20
R2(config-route-map)#exit

//将route-map应用于向R3宣告路由的出方向
R2(config)#router bgp 12
R2(config-router)#neighbor 23.0.0.3 route-map set_med out

//软清BGP进程
R2#clear ip bgp * soft

注:MED属性只会传递给EBGP peer,也会传播到该peer所在的整个AS内,但是该peer不会将其传递给其它AS。MED属性值默认是0。影响其它的自治系统的数据流,如何流入本地自治系统。选择低者

R3#sh ip bgp
分类: CCNP实验报告 标签: ,
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.