实验目的:
1、理解MED属性能够影响,其它的自治系统的数据流如何流入本地自治系统。
2、掌握基于route-map的MED配置方法。
实验拓扑:
接口ip配置、路由协议基础配置详见
优快云https://mp.youkuaiyun.com/mp_blog/creation/editor/125133896查看R3和R4的路由表
R3#show ip route
Gateway of last resort is not set
34.0.0.0/24 is subnetted, 1 subnets
C 34.34.34.0 is directly connected, FastEthernet0/0
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 23.23.23.2, 00:01:33
2.0.0.0/24 is subnetted, 1 subnets
B 2.2.2.0 [20/0] via 23.23.23.2, 00:01:33
23.0.0.0/24 is subnetted, 1 subnets
C 23.23.23.0 is directly connected, FastEthernet0/1
12.0.0.0/24 is subnetted, 1 subnets
B 12.12.12.0 [20/0] via 23.23.23.2, 00:01:33
14.0.0.0/24 is subnetted, 1 subnets
B 14.14.14.0 [200/0] via 34.34.34.4, 00:01:35
R4#show ip route
Gateway of last resort is not set
34.0.0.0/24 is subnetted, 1 subnets
C 34.34.34.0 is directly connected, FastEthernet0/0
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 14.14.14.1, 00:02:06
2.0.0.0/24 is subnetted, 1 subnets
B 2.2.2.0 [20/0] via 14.14.14.1, 00:02:06
23.0.0.0/24 is subnetted, 1 subnets
B 23.23.23.0 [200/0] via 34.34.34.3, 00:01:51
12.0.0.0/24 is subnetted, 1 subnets
B 12.12.12.0 [20/0] via 14.14.14.1, 00:02:06
14.0.0.0/24 is subnetted, 1 subnets
C 14.14.14.0 is directly connected, FastEthernet0/1
根据路由表可以看出,R3路由器到达R1的1.1.1.0/24子网,选择了14.14.14.0/24网络。在本例中,我们更希望R3选择23.23.23.0/24网络。为了实现这一目的,可以在R1与R2上配置MED属性,因为MED属性可以实现:影响其它的自治系统的数据流,如何流入本地自治系统。
根据MED的属性值越低的哪条路由,会被优先选择的特性。而且MED值默认为0。因此,可以在R2上配置其向R2通告的1.1.1.0/24的网络路由的MED值高于默认值即可。如果不主动修改R1的MED默认值的话。
为了能够观察到MED的配置前后路由变化,需要先查看R3与R4的BGP数据库表:
R3#show ip bgp
BGP table version is 7, local router ID is 34.34.34.3
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 34.34.34.4 0 100 0 12 i
*> 23.23.23.2 0 12 i
* i2.2.2.0/24 34.34.34.4 0 100 0 12 i
*> 23.23.23.2 0 0 12 i
…………………………
R4#show ip bgp
BGP table version is 8, local router ID is 34.34.34.4
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 23.23.23.2 0 100 0 12 i
*> 14.14.14.1 0 0 12 i
* i2.2.2.0/24 23.23.23.2 0 100 0 12 i
*> 14.14.14.1 0 12 i
……………………
在R2上实施MED的策略配置。
R2(config)#access-list 1 permit 1.1.1.0 0.0.0.255
//使用ACL指出需要修改的MED的路由。
R2(config)#route-map set_med permit 10
R2(config-route-map)#match ip address 1
//用于匹配查询ACL 1所指出的路由条目。
R2(config-route-map)#set metric 100
//对于匹配成功的路由条目,将其MED值设为100
R2(config)#route-map set_med permit 20
//配置对于其它的路由采用默认的方式进行宣告。即不做任何修改。
R2(config)#router bgp 12
R2(config-router)#neighbor 23.23.23.3 route-map set_med out
//针对对等体23.23.23.3进行策略路由。
//方向out,是指出从R2向R1发出的路由进行策略设置。
加快bgp收敛
R2#clear ip bgp * soft out
查看R3与R4的BGP数据库信息。
R3#show ip bgp
BGP table version is 1, local router ID is 34.34.34.3
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 34.34.34.4 0 100 0 12 i
*> 23.23.23.2 0 12 i
//由于BGP会选择较低的MED值的路由,因此R2选择下一跳为23.23.23.2
* i2.2.2.0/24 34.34.34.4 0 100 0 12 i
*> 23.23.23.2 0 0 12 I
…………………………
R4#show ip bgp
BGP table version is 9, local router ID is 34.34.34.4
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 14.14.14.1 0 0 12 i
//由于MED属性为不可传递,因此,其并没有影响到R4的BGP的路由协议。
*> 2.2.2.0/24 14.14.14.1 0 12 i
………………………………
为了确切的判断出R3到达1.1.1.0/24的网络路由,使用的是最佳路由,在R4路由器上配置下一跳属性。配置如下:
R4(config)#router bgp 34
R4(config-router)#neighbor 34.34.34.3 next-hop-self
在R3路由器上查看BGP的数据库和路由表:
R3#show ip bgp
BGP table version is 1, local router ID is 34.34.34.3
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 23.23.23.2 0 12 i
* i 34.34.34.4 0 100 0 12 i
*> 2.2.2.0/24 23.23.23.2 0 0 12 i
* i 34.34.34.4 0 100 0 12 i
……………………
R3#show ip route
Gateway of last resort is not set
34.0.0.0/24 is subnetted, 1 subnets
C 34.34.34.0 is directly connected, FastEthernet0/0
1.0.0.0/24 is subnetted, 1 subnets
B 1.1.1.0 [20/0] via 23.23.23.2, 00:01:11
2.0.0.0/24 is subnetted, 1 subnets
B 2.2.2.0 [20/0] via 23.23.23.2, 00:01:11
23.0.0.0/24 is subnetted, 1 subnets
C 23.23.23.0 is directly connected, FastEthernet0/1
12.0.0.0/24 is subnetted, 1 subnets
B 12.12.12.0 [20/0] via 23.23.23.2, 00:01:11
14.0.0.0/24 is subnetted, 1 subnets
B 14.14.14.0 [200/0] via 34.34.34.4, 00:01:12
使用tracert命令确认路由信息:
R3#traceroute 1.1.1.1
Type escape sequence to abort.
Tracing the route to 1.1.1.1
1 23.23.23.2 20 msec 8 msec 12 msec
2 12.12.12.1 [AS 12] 24 msec 20 msec 28 msec