BGP属性MED和本地优先级实验

今天复习BGP的2个属性:MED和本地优先级。把他们同时放在一个实验中,拓扑图如下:

 

 

R1与R2,R4是EBGP,R3与R2,R4是IBGP。AS200内部跑OSPF协议,R1与R3分别宣告回环的2个地址。

R1:

r1(config)#int f0/0
r1(config-if)#ip add 12.1.1.1 255.255.255.0
r1(config-if)#no shu
r1(config-if)#exit
r1(config)#int f1/0
r1(config-if)#ip add 14.1.1.1 255.255.255.0
r1(config-if)#no shu
r1(config-if)#exit
r1(config)#int loop0
r1(config-if)#ip add 1.1.1.1 255.255.255.0
r1(config-if)#exit
r1(config)#int loop1
r1(config-if)#ip add 11.11.1.1 255.255.255.0
r1(config-if)#exit
r1(config)#router bgp 100
r1(config-router)#neighbor 12.1.1.2 remote-as 200
r1(config-router)#neighbor 14.1.1.2 remote-as 200
r1(config-router)#network 1.1.1.0 mask 255.255.255.0
r1(config-router)#network 11.11.11.0 mask 255.255.255.0
r1(config-router)#exit

 

R2:
r2(config)#int f0/0
r2(config-if)#ip add 12.1.1.2 255.255.255.0
r2(config-if)#no shut
r2(config-if)#int f1/0
r2(config-if)#ip add 23.1.1.1 255.255.255.0
r2(config-if)#no shut
r2(config-if)#int loop0
r2(config-if)#ip add 2.2.2.2 255.255.255.0
r2(config-if)#exit
r2(config)#router ospf 10
r2(config-router)#router-id 2.2.2.2
r2(config-router)#network 0.0.0.0 0.0.0.0 area 0
r2(config-router)#exit
r2(config)#router bgp 200
r2(config-router)#neighbor 12.1.1.1 remote-as 100
r2(config-router)#neighbor 3.3.3.3 remote-as 200
r2(config-router)#neighbor 3.3.3.3 update-source loopback 0
r2(config-router)#no synchronization
r2(config-router)#no auto
r2(config-router)#neighbor 3.3.3.3 next-hop-self
R3:

r3(config)#int f1/0
r3(config-if)#ip add 23.1.1.2 255.255.255.0
r3(config-if)#no shu
r3(config-if)#exit
r3(config)#int f0/0
r3(config-if)#ip add 34.1.1.1 255.255.255.0
r3(config-if)#no shu
r3(config-if)#exit
r3(config)#int loop0
r3(config-if)#ip add 3.3.3.3 255.255.255.0
r3(config-if)#exit
r3(config)#int loop1
r3(config-if)#ip add 33.33.33.33 255.255.255.0
r3(config-if)#exit
r3(config)#router ospf 10
r3(config-router)#router-id 3.3.3.3
r3(config-router)#network 0.0.0.0 0.0.0.0 a 0
r3(config-router)#exit
r3(config)#router bgp 200
r3(config-router)#neighbor 2.2.2.2 remote-as 200
r3(config-router)#neighbor 2.2.2.2 update-source loopback 0
r3(config-router)#neighbor 4.4.4.4 remote-as 200
r3(config-router)#neighbor 4.4.4.4 update-source loopback 0
r3(config-router)#network 3.3.3.0 mask 255.255.255.0
r3(config-router)#network 33.33.33.0 mask 255.255.255.0
r3(config-router)#exit
R4:

r4(config)#int f0/0
r4(config-if)#ip add 34.1.1.2 255.255.255.0
r4(config-if)#no shut
r4(config-if)#int f1/0
r4(config-if)#ip add 14.1.1.2 255.255.255.0
r4(config-if)#no shut
r4(config-if)#int loop0
r4(config-if)#ip add 4.4.4.4 255.255.255.0
r4(config-if)#exit
r4(config)#router ospf 10
r4(config-router)#router-id 4.4.4.4
r4(config-router)#network 0.0.0.0 0.0.0.0 area 0
r4(config)#router bgp 200
r4(config-router)#no sy
r4(config-router)#no auto
r4(config-router)#neighbor 14.1.1.1 remote-as 100
r4(config-router)#neighbor 3.3.3.3 remote-as 200
r4(config-router)#neighbor 3.3.3.3 update-source loop0
r4(config-router)#neighbor 3.3.3.3 next-hop-self
r4(config-router)#end

上面配置了EBGP,IBGP,ospf等 观看R1和R3的BGP 路由

r1#show ip bgp
BGP table version is 5, local router ID is 11.11.11.11
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.0/24       0.0.0.0                  0         32768 i
*  3.3.3.0/24       14.1.1.2                               0 200 i
*>                  12.1.1.2                               0 200 i
*> 11.11.11.0/24    0.0.0.0                  0         32768 i
*  33.33.33.0/24    14.1.1.2                               0 200 i
*>                  12.1.1.2                               0 200 i

r3#show ip bgp
BGP table version is 5, local router ID is 33.33.33.33
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*>i1.1.1.0/24       2.2.2.2                  0    100      0 100 i
* i                 4.4.4.4                  0    100      0 100 i
*> 3.3.3.0/24       0.0.0.0                  0         32768 i
*>i11.11.11.0/24    2.2.2.2                  0    100      0 100 i
* i                 4.4.4.4                  0    100      0 100 i
*> 33.33.33.0/24    0.0.0.0                  0         32768 i

从BGP表中我们可以看到R1学到的3.3.3.0/24和33.33.33.0/24的下一跳都是R2,R3学到的1.1.1.0/24和11.11.11.0/24的下一跳也是R2。现在我们通过修改med和本地优先级,使得R1学到33.33.33.0/24下一跳是R4,R3学到11.11.11.0/24下一跳也是R4,配置如下:

r4(config)#access-list 10 permit 11.11.11.0 0.0.0.255
r4(config)#route-map local permit 10
r4(config-route-map)#match ip add 10
r4(config-route-map)#set local-preference 400
r4(config-route-map)#exit
r4(config)#route-map local permit 20
r4(config-route-map)#exit
r4(config)#router bgp 200
r4(config-router)#neighbor 3.3.3.3 route-map local out
r4(config-router)#exit
r4(config)#access-list 20 permit 33.33.33.0 0.0.0.255
r4(config)#route-map med permit 10
r4(config-route-map)#match ip add 20
r4(config-route-map)#set metric 100
r4(config-route-map)#exit
r4(config)#route-map med permit 20
r4(config-route-map)#set metric 300
r4(config-route-map)#exit
r4(config)#router bgp 200
r4(config-router)#neighbor 14.1.1.1 route-map med out

r2(config)#access-list 20 permit 33.33.33.0 0.0.0.255
r2(config)#route-map med permit 10
r2(config-route-map)#match ip add 20
r2(config-route-map)#set metric 200
r2(config-route-map)#exit
r2(config)#route-map med permit 20
r2(config-route-map)#exit
r2(config)#router bgp 200
r2(config-router)#neighbor 12.1.1.1 route-map med out

配置好后我们使用clear ip bgp *来强制重起BGP。现在在来观看R1和R3的bgp表

r1#show ip bgp
BGP table version is 5, local router ID is 11.11.11.11
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 1.1.1.0/24       0.0.0.0                  0         32768 i
*> 3.3.3.0/24       12.1.1.2                               0 200 i
*                   14.1.1.2               300             0 200 i
*> 11.11.11.0/24    0.0.0.0                  0         32768 i
*  33.33.33.0/24    12.1.1.2               200             0 200 i
*>                  14.1.1.2               100             0 200 i

r3#show ip bgp
BGP table version is 23, local router ID is 33.33.33.33
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
* i1.1.1.0/24       4.4.4.4                  0    100      0 100 i
*>i                 2.2.2.2                  0    100      0 100 i
*> 3.3.3.0/24       0.0.0.0                  0         32768 i
*>i11.11.11.0/24    4.4.4.4                  0    400      0 100 i
* i                 2.2.2.2                  0    100      0 100 i
*> 33.33.33.0/24    0.0.0.0                  0         32768 i

与第一次的输出对比一下可以看到,11.11.11.0/24和33.33.33.0/24的路径选择发生了变化,选择了从R4走的路由,这样的话写进路由表里的路由的下一跳就是R4了,不在是R2了。

你可能感兴趣的:(属性,休闲,实验,BGP,MED)