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

[经验分享] BGP community 属性

[复制链接]
累计签到:2 天
连续签到:1 天
发表于 2016-1-29 08:45:01 | 显示全部楼层 |阅读模式
BGP communities  属性
BGP 的community 属性属于可选可传递属性,不支持该属性的路由器会原封不动的将community 值传递给下游BGP邻居(前提是配置了传递community 属性)。
BGP 的community 属性可以简化网络中路由器对相同路由条目的匹配工作,如果在一个大型网络中所有路由器上都需要匹配相同的路由条目,如果用ACL或者前缀列表进行匹配,则工作量比较大,所以可以在一台路由器上为相应的路由条目打上community 属性值,在其他路由器上可以通过匹配community 属性值的方式间接地来匹配路由条目,从而简化了路由条目的匹配工作。

Community 属性的类别:
可以分为私有community 属性值和众所周知的community 属性值。
私有的community 属性值通常用4字节的数字来表示(可以为一个32位的数,也可以是两个16位的数字,如100:1)
在CISCO 的路由器中,默认是以32位的数字显示,如果要转换成两个16位的数字,则需用通过命令进行转换((config)#ip bgp-community new-format),会同时转换BGP表中的显示格式和配置文件中的显示格式。
ip bgp-community new-format 命令仅对本路由器有效,对邻居路由器无效。

众所周知的community 属性值主要有:
no-advertise   : 不通告给任何BGP邻居(最严格)。
no-export     : 不通告给任何EBGP邻居,如果存在BGP联邦,则会在联邦内的EBGP邻居之间传递。
local-AS      :仅在AS 内传递,如果存在BGP联邦,
internet      :表示所有路由,可以通过匹配Internet 属性来匹配所有的路由条目
当路由器接受到一条带有众所周知community 属性值的路由条目时,必须要做出相应的动作(根据community 属性值不同而不同)

也可以分为标准的community 属性值和扩展的community 属性值。
扩展的community 属性值一般在MPLS VPN 网络中才会涉及到。

注:
一条路由前缀可以携带多个community 值,可以同时携带私有community值和众所周知的community值。
在任何一台BGP 路由器上可以覆盖、追加、删除community 值。
BGP 的community 属性值不会自动传递给邻居,必须为特定的邻居配置传递。
(config-router)#neighbor 192.168.12.2 send-community   ##为特定的邻居发送路由时传递community 属性。

配置:
l        为路由条目添加community 属性值
1、        使用ACL或者前缀列表匹配需要添加community 属性值的路由条目,尽量使用前缀列表匹配。
(config)#ip prefix-list  1  permit  1.1.1.1/32
2、        定义一个route-map ,匹配到相应的路由条目,并且追加或者覆盖community 属性值。
(config)#route-map 1 permit 10
(config-route-map)# match ip address prefix-list 1   ##匹配需要添加community 属性的路由条目
(config-route-map)# set community 126:1   ##为匹配到的路由条目打上一个私有的community 属性值
(config-route-map)# set community  no-advertise   ##为匹配到的路由前缀打上一个众所周知的community属性值
(config-route-map)# set community 126:1   no-advertise  ##为匹配到的路由前缀打上一个私有的和一个众所周知的community值。
3、在BGP中定义在发送或者接收路由时添加communti 属性值。
(config-router)#neighbor 192.168.12.2 route-map 1  out      ##为BGP邻居配置策略,在发送BGP路由时应用route-map 1 的策略,也就是为相应的路由前缀打上community 值。
(config-router)# neighbor 192.168.12.2  send-community      ##为邻居发送BGP路由时,携带community 属性值
4、查看带有community 属性值得BGP 路由
R2#show ip bgp community      ##查看带有community 属性值的BGP条目
BGP table version is 8, local router ID is 192.168.23.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.1/32       192.168.12.1             0    100      0 i                                  ##说明当前的路由前缀携带了community 值
5、查看BGP路由条目中的communtiy 值
R2#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 8
Paths: (1 available, best #1, table Default-IP-Routing-Table)
  Advertised to update-groups:
     2         
  Local
    192.168.12.1 from 192.168.12.1 (192.168.26.2)
      Origin IGP, metric 0, localpref 100, valid, internal, best
      Community: 126:1     ##路由条目中携带的community 值。

R2#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 8
Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to any peer)
Flag: 0x880
  Not advertised to any peer
  100
    192.168.12.1 from 192.168.12.1 (1.1.1.3)
      Origin IGP, metric 0, localpref 100, valid, external, best
      Community: 100:1 1000:1 no-advertise       ##当前路由前缀中携带了3个community 属性值

l        在其他BGP路由器上追加community 值
1、        通过ACL、前缀列表、或者commun-list 列表匹配到要追加community 值的路由条目
(config)#ip prefix-list 1 permit 1.1.1.1/32    ##通过前缀匹配路由条目
(config)#ip community-list 1 permit 126:1   ##通过community-list 匹配路由条目,因为1.1.1.1/32的路由条目中已经携带了126:1的community 值,所以可以通过匹配communit 值来间接的匹配路由条目。
2、        定义route-map 并追加community 值。
(config)#route-map 1 permit 10    ##创建一个route-map
(config-route-map)#match ip address prefix-list 1    ##通过ip 前缀匹配路由条目
(config-route-map)#match community 1    ##也可以通过community-list 来匹配路由条目。
(config-route-map)# set community 100:1 additive  ##追加上一个community 值,其中关键字additive 就是追加的意思,如果没有该关键字,将会覆盖掉路由条目中的community 值。
注:在route-map 中可以使用前缀列表或者community-list 来匹配路由条目,如果同时配置了前缀列表和community-list,则两个列表中都满足的才算匹配,也就是两个条件是and 关系。
3、        将定义好的route-map 关联到相应的邻居。
略……………………

l        在BGP路由器上删除community 值
1、        通过IP前缀列表、ACL或者community-list 值匹配相应的路由条目。
(config)#ip community-list 1 permit 100:1    ##定义一个community-list,来匹配那些BGP路由条目中携带community 值为100:1的路由条目。
2、        定义一个community-list 值,用来定义需要删除的community 值。
(config)#ip community-list 2 permit 100:1  
3、        定义route-map
(config)#route-map 1 permit 10
(config-route-map)#match community 1
(config-route-map)#set comm-list 2 delete   #定义要删除的community值
4、        为相应的邻居关联route-map

l        通过community 值来匹配相应的路由,并完成相应的策略。
Community 属性值最大的用途就是简化路由条目的匹配工作。
1、使用community-list 来匹配相应的路由条目。
(config)#ip community-list  1  permit  100:1      ##匹配community 属性值中包含100:1的路由
4、        定义route-map
(config)#route-map  1     ##创建一个route-map
(config-route-map)#match  community  1   ##通过定义好的community-list 1 匹配到相应的路由条目。
(config-route-map)#set  weight  2000    ##将匹配到的路由条目的weight 更改为2000
5、        为相应的邻居关联route-map
(config-router)#neighbor 192.168.34.3  route-map  1  in  ##从邻居192.168.34.3接收路由时应用route-map
6、        查看结果
R4#show ip bgp 1.1.1.1
BGP routing table entry for 1.1.1.1/32, version 25
Paths: (1 available, best #1, table Default-IP-Routing-Table)
  Not advertised to any peer
  300 126
    192.168.34.3 from 192.168.34.3 (192.168.37.3)
      Origin IGP, localpref 100, weight 2000, valid, external, best
      Community: 126:1

l        通过community-list 匹配路由条目时的注意事项:
(config)#ip community-list 1 permit 100:1 not-adv
匹配community 属性值中至少同时包含100:1 和not-adv 的路由,也就是两个条件是且(and)的关系。
(config)#ip community-list 1 perimt 100:1
(config)#ip community-list 1 permit not-adv
匹配community 属性值中包含100:1或者包含not-adv 的路由,两个条件是或(or)的关系。

当一条路由条目中携带了多个community 属性值,默认情况下只要匹配到其中的一个community 值就能匹配到相应的路由,但这样的匹配结果不够精确,为了精确匹配到相应的路由,在route-map 中指定community-list 时,可以添加上exact-match 关键字,也就是严格匹配。
为了更清楚的说明以上内容,举个简单的例子,路由器上收到了两条BGP路由分别为:1.1.1.1/32 和1.1.1.2/32,其中1.1.1.1/32携带了一个community 值,为100:1,而1.1.1.2/32携带了两个community 值,分别为:100:1 ,200:2。现在的要求是:在路由器上只允许携带了100:1 的路由进入BGP表。
1.1.1.1/32  community:100:1
1.1.1.2/32  community:100:1  200:2
IP community-list  1  permit 100:1
Route-map  1
Match  community  1
(config-router)#neighbor  192.168.1.1  route-map  1  in

通过以上配置后,1.1.1.1/32和1.1.1.2/32 都能进入BGP表,原因是在匹配的时候没有严格匹配。

案例一
1.1.1.1/32  community:100:1
1.1.1.2/32  community:100:1  100:2
IP community-list  1  permit 100:1
Route-map  1
Match  community  1
(config-router)#neighbor  192.168.1.1  route-map  1  in
通过以上配置后,1.1.1.1/32和1.1.1.2/32 都能进入BGP表,原因是在匹配的时候没有严格匹配。

案例二
1.1.1.1/32  community:100:1
1.1.1.2/32  community:100:1  100:2
IP community-list  1  permit 100:1
Route-map  1
Match  community  1   exact-match
(config-router)#neighbor  192.168.1.1  route-map  1  in
通过以上配置,只有1.1.1.1/32的路由可以进去BGP表,因为进行了严格匹配。

案例三
1.1.1.1/32  community:100:1
1.1.1.2/32  community:100:1  100:2
IP community-list  1  permit 100:1  100:2
Route-map  1
Match  community  1
(config-router)#neighbor  192.168.1.1  route-map  1  in
通过以上配置,只会有1.1.1.2/32的路由可以进入BGP表,因为同一条community-list 中的多个值是and关系,需要同时匹配,才算匹配。

案例四
1.1.1.1/32  community:100:1
1.1.1.2/32  community:100:1  100:2
ip community-list 1 permit 100:1
ip community-list 1 permit 100:2
Route-map  1
Match  community  1
(config-router)#neighbor  192.168.1.1  route-map  1  in
通过以上配置,1.1.1.1/32和1.1.1.2/32的路由都可以进入BGP表

案例五
1.1.1.1/32  community:100:1
1.1.1.2/32  community:100:1  100:2
ip community-list standard comm permit 100:1
ip community-list standard comm permit 100:2
Route-map  1
Match  community  comm     exact-match
(config-router)#neighbor  192.168.1.1  route-map  1  in
通过以上配置,1.1.1.1/32可以进入BGP表,因为1.1.1.2/32的路由不能严格匹配。


案例六
1.1.1.1/32  community:100:1
1.1.1.2/32  community:100:1  100:2
ip community-list 1 permit 100:1
ip community-list 2 permit 100:2
route-map 1 permit 10
match community 1 2
(config-router)#neighbor  192.168.1.1  route-map  1  in
通过以上配置,1.1.1.1/32和1.1.1.2/32的路由都可以进入BGP表

案例七
1.1.1.1/32  community:100:1
1.1.1.2/32  community:100:1  100:2
ip community-list standard comm permit 100:1
ip community-list standard comm2 permit 100:2
route-map 1 permit 10
match community  comm  comm2  exact-match
(config-router)#neighbor  192.168.1.1  route-map  1  in
通过那个配置,只有1.1.1.1/32的路由可以进入BGP表




运维网声明 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-170907-1-1.html 上篇帖子: cisco ASA ios升级或恢复 下篇帖子: cisco sdm登录 SSH配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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