实验20-配置BGP路径选择-Manipulating BGP Path Selection

实验20 配置BGP 路径选择(CCIE实验50)
时间:2006年3月5日
时间花费 总计约120分钟
实验设备:2501 4台
实验拓扑:
 Manipulating BGP Path Selection

 

IP配置如下:

R1

R2

R3

R5

S0 10.1.1.1/30

S1 10.1.2.2/30

S0 10.1.1.2/30

E0 192.168.1.5/24

S1 10.1.2.1/30

E0 192.168.1.2/24

E0 192.168.1.3/24

 

Lo0 1.1.1.1/24

Lo1 2.2.2.2/24

 

 

 

 

需求:根据图示建立完成BGP配置,要求R1上loopback口的路由可以通告到AS2中的每台路由器,并测试通过local preference、MED、AS-path来进行路径选择

配置中涉及的知识参考文档BGP的路径选择


R2、R3、R5通过以太口建立AS200内的iBGP邻居。
R1采用network方式进行路由通告,R2 R3互相指neighbor以及与R5指neighbor的时候都是用了next-hop-self的方式,以便让R5可以学到R1通告出来的路由。

1.    通过local preference进行路径选择:
配置好BGP路由后在R5上可以看到:
r5#sh ip bgp
BGP table version is 5, local router ID is 5.5.5.5
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
*>i1.1.1.0/24       192.168.1.3              0    100      0 100 i
* i                 192.168.1.2              0    100      0 100 i
* i2.2.2.0/24       192.168.1.2              0    100      0 100 i
*>i                 192.168.1.3              0    100      0 100 i
这时候选择192.168.1.3只是因为R3的router-id相对较小:
r5#sh ip bgp neighbor
BGP neighbor is 192.168.1.2,  remote AS 200, internal link
  BGP version 4, remote router ID 10.1.2.2
…
BGP neighbor is 192.168.1.3,  remote AS 200, internal link
  BGP version 4, remote router ID 10.1.1.2
在R2上设置一个prefix-list来标记要修改的路由:
ip prefix-list change11 seq 5 permit 1.1.1.0/24
route-map change11-localpref permit 10
 match ip address prefix-list change11
 set local-preference 200 修改local preference到200(默认为100)
!
route-map change11-localpref permit 20
!
router bgp 200
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.1.2.1 remote-as 100
 neighbor 192.168.1.3 remote-as 200
 neighbor 192.168.1.3 next-hop-self
 neighbor 192.168.1.5 remote-as 200
 neighbor 192.168.1.5 next-hop-self
 neighbor 192.168.1.5 route-map change11-localpref out
当R2向R5通告的时候,会根据route-map修改1.1.1.0/24的local preference
修改后执行clear ip bgp * soft,在R5上可以看到:
r5#sh ip bgp
BGP table version is 6, local router ID is 5.5.5.5
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
* i1.1.1.0/24       192.168.1.3              0    100      0 100 i
*>i                 192.168.1.2              0    200      0 100 i
* i2.2.2.0/24       192.168.1.2              0    100      0 100 i
*>i                 192.168.1.3              0    100      0 100 i
在R3上看:
r3#sh ip bgp
BGP table version is 3, local router ID is 10.1.1.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
* i1.1.1.0/24       192.168.1.2              0    100      0 100 i
*>                  10.1.1.1                 0             0 100 i
* i2.2.2.0/24       192.168.1.2              0    100      0 100 i
*>                  10.1.1.1                 0             0 100 i
这是由于刚才的route-map是在出向作的,只针对R5,而由于水平分割的问题R5不会把收到的路由继续发送给R3。
在R2上进行修改
r2(config)#router b 200
r2(config-router)#no neighbor 192.168.1.5 route-map change11-localpref out
r2(config-router)#nei 10.1.2.1 route-map change11-localpref in 在从R1收到的路由(进入方向上)应用route-map
这时候在R3上可以看到:
r3#sh ip bgp
BGP table version is 4, local router ID is 10.1.1.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
*>i1.1.1.0/24       192.168.1.2              0    200      0 100 i 修改的localPrf生效
*                   10.1.1.1                 0             0 100 i
* i2.2.2.0/24       192.168.1.2              0    100      0 100 i
*>                  10.1.1.1                 0             0 100 i
在R5上可以看到:
r5#sh ip bgp
BGP table version is 8, local router ID is 5.5.5.5
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
*>i1.1.1.0/24       192.168.1.2              0    200      0 100 i
* i2.2.2.0/24       192.168.1.2              0    100      0 100 i
*>i                 192.168.1.3              0    100      0 100 i
R3没有向R5继续发送1.1.1.0/24的路由,这是因为R3认为这个路由并不是最佳的,不该发送给R5
r3#sh ip bgp nei 192.168.1.5 adv
BGP table version is 9, local router ID is 10.1.1.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
*> 2.2.2.0/24       10.1.1.1                 0             0 100 i
2.通过MED影响路径选择
MED是可以影响外部AS路径选择的。
在R1上作下面的配置:
r1:

router bgp 100
 no synchronization
 bgp log-neighbor-changes
 network 1.1.1.0 mask 255.255.255.0
 network 2.2.2.0 mask 255.255.255.0
 neighbor 10.1.1.2 remote-as 200
 neighbor 10.1.1.2 route-map set-11-med100 out
 neighbor 10.1.2.2 remote-as 200
 neighbor 10.1.2.2 route-map set-11-med out
 no auto-summary
ip prefix-list change11med seq 5 permit 1.1.1.0/24
!
route-map set-11-med permit 10
 match ip address prefix-list change11med
 set metric 50
!
route-map set-11-med permit 20
!
route-map set-11-med100 permit 10
 match ip address prefix-list change11med
 set metric 100
!
route-map set-11-med100 permit 20
在R2上可以看到
r2#sh ip bgp
BGP table version is 12, local router ID is 10.1.2.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
* i1.1.1.0/24       192.168.1.3            100    100      0 100 i
*>                  10.1.2.1                50             0 100 i
* i2.2.2.0/24       192.168.1.3              0    100      0 100 i
*>                  10.1.2.1                 0             0 100 i
在R3上可以看到:
r3#sh ip bgp
BGP table version is 11, local router ID is 10.1.1.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
*>i1.1.1.0/24       192.168.1.2             50    100      0 100 i
*                   10.1.1.1               100             0 100 i
* i2.2.2.0/24       192.168.1.2              0    100      0 100 i
*>                  10.1.1.1                 0             0 100 i
R5上可以看到:

r5#sh ip bgp
BGP table version is 17, local router ID is 5.5.5.5
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
*>i1.1.1.0/24       192.168.1.2             50    100      0 100 i
* i2.2.2.0/24       192.168.1.2              0    100      0 100 i
*>i                 192.168.1.3              0    100      0 100 i
可见,AS200中的所有路由器都会选择Metric低的路径,也就是说AS200到AS100的流量会通过R2送出。

3.通过AS-path影响选路
r1上作出下面的配置:
router bgp 100
 no synchronization
 bgp log-neighbor-changes
 network 1.1.1.0 mask 255.255.255.0
 network 2.2.2.0 mask 255.255.255.0
 neighbor 10.1.1.2 remote-as 200
 neighbor 10.1.1.2 route-map change-as out
 neighbor 10.1.2.2 remote-as 200
 neighbor 10.1.2.2 route-map change-as out
 no auto-summary

route-map change-as permit 10
 match ip address prefix-list change11med
 set as-path prepend 100 100 100
!
route-map change-as permit 20.

r2#sh ip bgp
BGP table version is 10, local router ID is 10.1.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i – internal,
          &nb
sp;   r RIB-failure, S Stale
Origin codes: i – IGP, e – EGP, ? – incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*>i1.1.1.0/24       192.168.1.3              0    100      0 100 i
*                   10.1.2.1                 0             0 100 100 100 100 i
* i2.2.2.0/24       192.168.1.3              0    100      0 100 i
*>                  10.1.2.1                 0             0 100 i

BGP是距离矢量路由协议,会优选as-path短的作为最佳路径。
修改R1上的route-map
route-map change-as permit 10
 match ip address prefix-list change11med
 set as-path prepend 100 300 400
!
在R3上可以看到:
r3#sh ip bgp nei 192.168.1.5 adv
BGP table version is 9, local router ID is 10.1.1.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
*> 1.1.1.0/24       10.1.1.1                 0             0 100 100 300 400 i
*> 2.2.2.0/24       10.1.1.1                 0             0 100 i
在R3上作针对AS300的路由过滤,过滤所有曾经穿越AS300的流量:
在R3上配置:
ip as-path access-list 1 deny _300_
ip as-path access-list 1 permit .*
router bgp 200
 no synchronization
 bgp log-neighbor-changes
 neighbor 10.1.1.1 remote-as 100
 neighbor 192.168.1.2 remote-as 200
 neighbor 192.168.1.2 next-hop-self
 neighbor 192.168.1.5 remote-as 200
 neighbor 192.168.1.5 next-hop-self
 neighbor 192.168.1.5 filter-list 1 out
 no auto-summary
!
r3#sh ip bgp nei 192.168.1.5 adv
BGP table version is 9, local router ID is 10.1.1.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
*> 1.1.1.0/24       10.1.1.1                 0             0 100 100 300 400 i
*> 2.2.2.0/24       10.1.1.1                 0             0 100 i
r3#clear ip bgp * soft 要求R3发送更新
r3#sh ip bgp nei 192.168.1.5 adv
BGP table version is 9, local router ID is 10.1.1.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
*> 2.2.2.0/24       10.1.1.1                 0             0 100 i
R3不再发送曾经穿越AS300的路由到R5

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理。