MULTI_EXIT_DISC(多出口标识符)简称MED,MED用于影响相邻两个自治系统的路由决策,被称为外部度量值,其值越小越优先,Cisco中为metric,默认值为0,MED只能在AS之间传递,收到此属性的AS路由器不会再将其传递给任何其它的第三方AS,但会传递给他的iBGP邻居; 一条相同的BGP条目通过不同的EBGP邻居学到时,只有在AS号相同时才进行MED比较,当从不同的EBGP邻居收到相同的路由,但是AS号不一样时,是不会比较MED值的,如果路由器上配置了bgp always-compare-med,就会忽略AS号不一样,始终进行MED值的比较。
下面通过实验进行分析
图1 如上图,R1上通告三个网段192.168.1.0/24,192.168.2.0/24,192.168.3.0/24;修改MED值,使R3访问192.168.3.0/24走R4,访问192.168.1.0/24等两网段走R2,配置如下: 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| R1(config)#ip prefix-list med permit192.168.3.0/24
R1(config)#ip prefix-list med1 permit192.168.1.0/24
R1(config)#ip prefix-list med1 permit192.168.2.0/24
R1(config)#route-map R1-R2 permit 10
R1(config-route-map)#match ip address prefix-list med1
R1(config-route-map)#set metric 30
R1(config)#route-map R1-R2 permit 20
R1(config-route-map)# match ip address prefix-list med
R1(config-route-map)#set metric 50
R1(config)#route-map R1-R2 permit 30
R1(config)#route-map R1-R4 permit 10
R1(config-route-map)#match ip address prefix-list med
R1(config-route-map)#set metric 30
R1(config)#route-map R1-R4 permit 20
R1(config-route-map)#match ip address prefix-list med1
R1(config-route-map)#set metric 50
R1(config)#route-map R1-R4 permit 30
R1(config)#routerbgp 10
R1(config-router)#neighbor12.1.1.2 route-map R1-R2 out
R1(config-router)#neighbor14.1.1.2 route-map R1-R4 out
|
配置说明:R1发往R4的路由针对192.168.1.0/24、192.168.2.0/24两个网段设置metric值为50,192.168.3.0/24的metric值为20,其它的不变;而R1发往R2的路由针对192.168.3.0/24设置metric值为50,192.168.1.0/24、192.168.2.0/24两个网段设置metric值为20,其它的不变,现在R2和R4上查看路由情况;
R2#show ip bgp BGP table version is 43, local routerID is 2.2.2.2 Status codes: s suppressed, d damped,h history, * valid, > best, i - internal, r RIB-failure, S Stale, mmultipath, b backup-path, f RT-Filter, x best-external, aadditional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? -incomplete RPKI validation codes: V valid, Iinvalid, N Not found Network Next Hop Metric LocPrf Weight Path * i 1.1.1.1/32 4.4.4.4 0 100 0 10 i *> 12.1.1.1 0 0 10 i *> 192.168.1.0 12.1.1.1 30 0 10 i *> 192.168.2.0 12.1.1.1 30 0 10 i *>i192.168.3.0 4.4.4.4 30 100 0 10 i * 12.1.1.1 50 0 10 i 从R1收到的192.168.3.0/24的metric值为50,其值小于从R4传递过来的30,因此下一跳为R4; R4#show ip bgp BGP table version is 31, local routerID is 4.4.4.4 Status codes: s suppressed, d damped,h history, * valid, > best, i - internal, r RIB-failure, S Stale, m multipath, bbackup-path, f RT-Filter, x best-external, aadditional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? -incomplete RPKI validation codes: V valid, Iinvalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 1.1.1.1/32 14.1.1.1 0 0 10 i * i 2.2.2.2 0 100 0 10 i * 192.168.1.0 14.1.1.1 50 0 10 i *>i 2.2.2.2 30 100 0 10 i * 192.168.2.0 14.1.1.1 50 0 10 i *>i 2.2.2.2 30 100 0 10 i *> 192.168.3.0 14.1.1.1 30 0 10 i R4从R1收到的路由192.168.1.0/24、192.168.2.0/24的metric值为50,大于从R2传递过来的30,因此其下一跳为R2; R3#show ip bgp BGP table version is 47, local routerID is 3.3.3.3 Status codes: s suppressed, d damped,h history, * valid, > best, i - internal, r RIB-failure, S Stale, mmultipath, b backup-path, f RT-Filter, x best-external, aadditional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? -incomplete RPKI validation codes: V valid, Iinvalid, N Not found Network Next Hop Metric LocPrf Weight Path * i 1.1.1.1/32 34.1.1.2 0 100 0 10 i *>i 23.1.1.1 0 100 0 10 i *>i192.168.1.0 23.1.1.1 30 100 0 10 i *>i192.168.2.0 23.1.1.1 30 100 0 10 i *>i192.168.3.0 34.1.1.2 30 100 0 10 i R3的路由可知,R3去往192.168.1.0/24、192.168.2.0/24的路由走R2,去往192.168.4.0/24的路由走R4,并且其metric值为设置的30,而1.1.1.1/32并没修改其MED属性值,其metric的默认值为0。
图2 如图2,增加一个路由器R5,与R4之间是EBGP关系,现在R5上查看BGP路由情况: R5#show ip bgp BGP table version is 27, local routerID is 5.5.5.5 Status codes: s suppressed, d damped,h history, * valid, > best, i - internal, r RIB-failure, S Stale, mmultipath, b backup-path, f RT-Filter, x best-external, aadditional-path, c RIB-compressed, Origin codes: i - IGP, e - EGP, ? -incomplete RPKI validation codes: V valid, Iinvalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 1.1.1.1/32 45.1.1.1 0 100 10 i *> 192.168.1.0 45.1.1.1 0 100 10 i *> 192.168.2.0 45.1.1.1 0 100 10 i *> 192.168.3.0 45.1.1.1 0 100 10 i 从上可知R4通告192.168.1.0/24等网段至R5时,并没有将metric属性值传递过来;
小结:MED值越小越优先,默认值为0,MED值可在IBGP中传递,不会传递给第三方的AS号的路由器;
如图2所示,在R5上创建一个环回接口,地址网段为192.168.3.0/24,将上述在R1上配置的MED属性值先去掉,在R4上查看路由情况; R4#show ip bgp BGP table version is 26, local routerID is 4.4.4.4 Status codes: s suppressed, d damped,h history, * valid, > best, i - internal, r RIB-failure, S Stale, mmultipath, b backup-path, f RT-Filter, x best-external, a additional-path, cRIB-compressed, Origin codes: i - IGP, e - EGP, ? -incomplete RPKI validation codes: V valid, Iinvalid, N Not found Network Next Hop Metric LocPrf Weight Path
* 192.168.3.0 14.1.1.1 0 0 10 i * i 2.2.2.2 0 100 0 10 i *> 45.1.1.2 0 0 50 i 现在R4对192.168.3.0/24的路由优先走R5,现在在R5上针对192.168.3.0/24设置其med值为50,按照BGP选路原则,med值越小路由越优先;那么R4上查看到的192.168.3.0/24,将会选择R1作为下一跳,配置完成后,查看R4路由情况; 1
2
3
4
5
6
7
| R5(config)#ip prefix-list med permit192.168.3.0/24
R5(config)#route-map med permit 10
R5(config-route-map)#match ip addressprefix-list med
R5(config-route-map)#set metric 50
R5(config)#route-map med permit 20
R5(config)#router bgp 50
R5(config-router)#neighbor 45.1.1.1 route-map med out
|
R4#show ip bgp
Network Next Hop Metric LocPrf Weight Path * 192.168.3.0 14.1.1.1 0 0 10 i * i 2.2.2.2 0 100 0 10 i *> 45.1.1.2 50 0 50 i 从上可看出,从R5传递过来的路由的metric值为50,从R1传递过来的metric值为0,但并没有选择R1为下一跳,因为从R1和R5传递过来的路由的AS号不同,不会比较MED值,上述的选路为优先最老的EBGP邻居传递过来的路由。
小结:当从不同的EBGP邻居收到相同的路由,但是AS号不一样时,是不会比较MED值的。
现在R4上配置命令: R4(config-router)#bgp always-compare-med //表示AS号不同也比较MED值 配置上述命令后,再次观查R4路由的情况 R4#show ip bgp Network Next Hop Metric LocPrf Weight Path * 192.168.3.0 45.1.1.2 50 0 50 i *> 14.1.1.1 0 0 10 i *i 2.2.2.2 0 100 0 10 i 从上述输出可知,R4选择去往192.168.3.0/24的下一跳为R1,选择MED值较小的;
小结:通过命令可以忽略AS号的不同,并且进行MED值的比较。
|