设为首页 收藏本站
查看: 1191|回复: 0

[经验分享] BGP 的MED路径属性分析

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-12-12 08:43:06 | 显示全部楼层 |阅读模式
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值的比较。
    下面通过实验进行分析
QQ截图20141212084023.jpg
图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。
QQ截图20141212084038.jpg
图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值的比较。



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-37916-1-1.html 上篇帖子: 查看数据包在internet网的那个设备被丢弃 下篇帖子: Cisco IP SLA和EEM:数据中心多出口优化设计方案
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表