BGP中COMMUNITY属性

COMMUNITY——可选传递属性

一种标记,用于简化路由策略的执行

可以将某些路由分配一个特定的community属性,之后就可以基于该community值而不是每条路由进行BGP属性设置

community属性就可以理解成在IGP内打TAG的意思,只不过在BGP中是community

community值会一直传递下去,如果不做策略,永远不会丢失。

 

community属性在cisco路由器有两种表现形式:


1.png 

 

Cisco路由器默认表现形式是十进制的形式,例如图片中:796432

RFC格式:AANN的形式

很明显RFCAANN的格式更直观对吧    AA可以表示AS号,NN可以表示序列号

而且两种格式在正则表达式中的应用也会有所不同,因为这是完全两种不一样的值,正则表达式的写法也就不一样

R1(config)#ip bgp-community new-format

用上边的命令修改格式

 

 

Community属性配置方法:

R1(config)#ip community-list standard COMMUNITY permit 10010

全局配置用community-list匹配community值,permit 10010就是去permit一个带100:10的community值的路由。

 

Route-map中去配置community属性

match一个community列表后打一问号回有一个可选项,这个叫严格匹,communitymatch时有严格匹配和宽松匹配两种模式,严格匹配就是去严格的执行community-list所permit的那些community值,具体的在下边实验体现,我会专门跟据这个严格匹配做一个实验

R1(config)#route-map test permit 10

R1(config-route-map)#match community COMMUNITY  ?

  exact-match  Do exact matching of communities                严格匹配最后有讲到

        

Route-map中去set那个community属性时,打个问号会有很多可选项,下边实验我们一一的介绍这些可选项的使用方法

R1(config-route-map)#set community ?                         set  community

  <1-4294967295>  community number

  aa:nn           community number in aa:nn format

  additive         Add to the existing community

  local-AS         Do not send outside local AS (well-known community)

  no-advertise     Do not advertise to any peer (well-known community)

  no-export       Do not export to next AS (well-known community)

  none           No community attribute

  internet         Internet (well-known community)

 

 

additive:再原有的community属性上,再增加一个community值,后边要加上additive关键字,如果不加,就会覆盖掉先前的community值。这个关键字是整个community属性我个人觉得是最重要的一个关键字了

Internet:默认所有路由都属于该可选项,可以匹配路由表中所有的路由前缀,给他们标记community值。(正常情况我们是先用ACLprefix-list(前缀列表)匹配出想要的路由,然后调用它为它标记community值,如果你不先用ACL去抓路由,想把路由表中所有路由前缀一并标记community值,就可以set这个可选项

local-AS:不传出本AS自治系统,如果定义了联邦可以在联邦内传递。(联邦就是在一个AS自治系统内定义多个小AS自治系统)

no-advertise:不将路由传递任何BGP邻居

no-export:不传递给任何EBGP邻居(联邦EBGP邻居除外)

none:不携带任何的Community

 

全篇的IP地址规划:192.168.xy.z    其中x是较小设备编号,y是较大设备编号,z是本设备编号  例如:R1---R2   R1的IP:192.168.12.1   R2的IP:192.168.12.2   所有路由器均有loopback0接口 R1是1.1.1.1/32 类推

全篇不再赘述IP地址规划,邻居可以根据拓扑可以看出哪些是EBGP,哪些是IBGP邻居,也不再赘述

 

 2.png

 

需求:1. R1路由器向EBGP邻居R2通告了两条路由前缀,我们为172.16.1.0/24路由前缀标记一个community属性值

2.R2路由器利用标记了community属性值的路由针对邻居R4做路由策略,为了方便实验效果,在R2针对标记community属性值修改local-preference属性(因为local-preference属性它默认值是100,我们调整成200

 

R1(config)#ip prefix-list 10 permit 172.16.1.0/24                        抓取172.16.1.0/24路由,注意我只抓了这一个路由并没有172.16.2.0/24路由

R1(config)#route-map test permit 10                                             创建Route-map,取名test

R1(config-route-map)#match ip address prefix-list 10                 match那个前缀列表

R1(config-route-map)#set community 100:10                               分配一个100:10的 community属性值

R1(config)#route-map test permit 20                                              Router-map隐含deny,所以写一条空的Router-map语句,空Router-map等同于permit any。你如果不写,那么其他路由将会被最后隐 R1(config-route-map)#exit                       含的deny 所匹配

R1(config)#router bgp 100

R1(config-router)#network 172.16.1.0 mask 255.255.255.0 

R1(config-router)#network 172.16.2.0 mask 255.255.255.0

R1(config-router)#neighbor 192.168.12.2 route-map test out            针对邻居应用Router-map

R1(config-router)#neighbor 192.168.12.2 send-community               Send-community属性,你不send邻居它是收不到任何community值。比如,R1上边为X路由标记100:10,你假设不去send,那                                                        R2路由器,它不是说看不到这条路由,而是看不到这个100:10的community值。你要传递给邻居,你就要send一下这个属性

R2#show ip bgp 172.16.1.0                                                                         R2路由器查看172.16.1.0/24路由详细信息

BGP routing table entry for 172.16.1.0/24, version 9

Paths: (1 available, best #1, table Default-IP-Routing-Table)

Flag: 0x8A0

  Advertised to update-groups:

        2

  100

    192.168.12.1 from 192.168.12.1 (1.1.1.1)

      Origin IGP, metric 0, localpref 100, valid, external, best

      Community: 100:10                                                                              最后有一个Community: 100:10的信息

 

 

R2(config)#ip community-list standard COMMUNITY permit 100:10                 创建 community-list抓取Community属性路由,匹配Community属性使用community-list匹配的

R2(config)#route-map test permit 10                                                                   创建Route-map,取名test

R2(config-route-map)#match community COMMUNITY                                                           match那个community-list列表

R2(config-route-map)#set local-preference 200                                                                          修改local-preference属性值为200

R2(config)#route-map test permit 20                                                                                             Router-map隐含deny,所以写一条空的

R2(config-route-map)#exit

R2(config)#router bgp 200

R2(config-router)#neighbor 4.4.4.4 route-map Community out         针对邻居应用Router-map语句

R2(config-router)#neighbor 4.4.4.4 send-community                          Send-community属性,使得该属性生效

 

R4#show ip bgp                                             R4看有没有生效

BGP table version is 10, local router ID is 4.4.4.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

*>i172.16.1.0/24    2.2.2.2                  0    200      0 100 i

*>i172.16.2.0/24    2.2.2.2                  0    100      0 100 i

R4路由器关于172.16.1.0/24local-preference属性生效了,172.16.1.0/24local-preference属性还是默认值100



3.png

 

需求:R2路由器已经通过上边实验有了一个10010community值,然后在原有的community值上在添加一个新的20023community

 

Additive可选项使用规则: 再原有的community属性上,再增加一个community

R2(config)#ip community-list standard COMMUNITY permit 100:10

R2(config)#route-map test permit 10

R2(config-route-map)#match community COMMUNITY

R2(config-route-map)#set community 20023 additive      再原有的community属性上,再增加一个community值,后边要加上additive关键字,如果不加,就会覆盖掉先前的10010值

R2(config)#route-map test permit 20                           写一个空的Route-map,放行其他的路由

R2(config-route-map)#exit

R2(config)#router bgp 23

R2(config-router)#neighbor 4.4.4.4 route-map COMMUNITY out              针对邻居调用Route-map

 

R4#show ip bgp 172.16.1.0

BGP routing table entry for 172.16.1.0/24, version 6

Paths: (1 available, best #1, table Default-IP-Routing-Table)

  Advertised to update-groups:

        2    3

  (23) 100

    2.2.2.2 (metric 156160) from 2.2.2.2 (2.2.2.2)

      Origin IGP, metric 0, localpref 200, valid, confed-external, best

      Community: 100:10 200:23                Community后边多了一个20023的属性值,说明成功了

 

4.png


上图定义了联邦,AS号标识的很清楚BGP的邻居关系

需求:在R2上部署no-advertise关键字,让R4路由器在收到带有no-advertise关键字时,不将路由传递给任何BGP邻居

 

no-advertise可选项使用规则:

R2(config)#ip community-list standard COMMUNITY permit 100:10

R2(config)#route-map test permit 10

R2(config-route-map)#match community COMMUNITY

R2(config-route-map)#set community no-advertise additive            additive关键字要加,不加先前10010200:23 两个  community属性值就会丢失了

R2(config)#route-map test permit 20                                                    写一个空的Route-map,放行其他的路由

R2(config-route-map)#exit

R2(config)#router bgp 23

R2(config-router)#neighbor 4.4.4.4 route-map test out                  针对邻居调用Route-map

 

 

R4#show ip bgp 172.16.1.0                                      R4路由器观察现象

BGP routing table entry for 172.16.1.0/24, version 17

Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to any peer)

Flag: 0x820

  Not advertised to any peer

  (23) 100

    2.2.2.2 (metric 156160) from 2.2.2.2 (2.2.2.2)

      Origin IGP, metric 0, localpref 200, valid, confed-external, best

      Community: 100:10 200:23 no-advertise                  多了一个no-advertise可选参数,并且先前200:23都还在,因为加了additive关键字

 

R5#show ip bgp

BGP table version is 26, local router ID is 5.5.5.5

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

*>i172.16.2.0/24        2.2.2.2            0    100      0 (23) 100 i    

 

R6#show ip bgp

BGP table version is 26, local router ID is 5.5.5.5

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

*>i172.16.2.0/24       192.168.46.4         0     100  0 (23) 100 i

 

由于R4收到了一个带no-advertise关键字的community 值路由,R4将不会在将该路由传递给任何邻居,可以看到R5路由表丢失了172.16.1.0/24路由,R6同样也没有该路由前缀信息



5.png


环境:R1R2是EBGP邻居            R2R4是联邦EBGP           R4R5是联邦EBGP                      R4R6EBGP

需求:在R2上部署no-export关键字,让R4在收到该属性不传递给任何EBGP邻居(联邦EBGP除外)

 

no-export可选项使用规则:

R2(config)#ip community-list standard COMMUNITY permit 100:10

R2(config)#route-map test permit 10

R2(config-route-map)#match community COMMUNITY

R2(config-route-map)#set community no-export                     additive 加上additive关键字要加,不加先前10010200:23 两个  community属性值就会丢失了

R2(config)#route-map test permit 20                          写一个空的Route-map,放行其他的路由

R2(config-route-map)#exit

R2(config)#router bgp 23

R2(config-router)#neighbor 4.4.4.4 route-map test out

 

R5#show ip bgp

BGP table version is 33, local router ID is 5.5.5.5

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

*>i172.16.1.0/24    2.2.2.2                  0    200      0 (23) 100 i

*>i172.16.2.0/24    2.2.2.2                  0    100      0 (23) 100 i

R5作为R4的联邦EBGP邻居,不会丢失172.16.1.0/24路由和172.16.2.0/24路由

 

R6#show ip bgp

BGP table version is 29, local router ID is 6.6.6.6

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

*> 172.16.2.0/24    192.168.46.4            0     100    100  i

R6作为R4EBGP邻居,丢失了172.16.1.0/24路由

 

4.png


需求:R2上使用none关键字,在向邻居发送路由时不携带任何的Community

            注意:R2关于172.16.1.0/24先前实验中有一个10010community值,是R1传递过来的

 

none可选项使用规则:

R2(config)#ip community-list standard COMMUNITY permit 100:10

R2(config)#route-map test permit 10

R2(config-route-map)# match community COMMUNITY

R2(config-route-map)#set community 200:23 additive      加上additive关键字

R2(config-route-map)#set community none                        Set none属性,使得R2在传输该路由前缀时不携带任何community

R2(config-route-map)#set local-preference 200

R2(config)#route-map test permit 20                                  写一个空的Route-map,放行其他的路由

R2(config-route-map)#exit

R2(config)#router bgp 23

R2(config-router)#neighbor 4.4.4.4 route-map test out

 

R4#show ip bgp 172.16.1.0

BGP routing table entry for 172.16.1.0/24, version 29

Paths: (1 available, best #1, table Default-IP-Routing-Table)

Flag: 0x880

  Advertised to update-groups:

        2    3

  (23) 100

    2.2.2.2 (metric 156160) from 2.2.2.2 (2.2.2.2)

      Origin IGP, metric 0, localpref 200, valid, confed-external, best

      Community: 100:10

R2明明也为172.16.1.0/24路由标记了一个20023Community值,但是R4丢失了20023Community值,但是并未丢失10010Community值,因为R2使用了additive关键字, 100:10CommunityR1路由器配置的所以不会丢失 。通过实验可以看出R2在向R4传递路由时候是没有携带任何的Community值。

 

4.png


需求:R2部署Loopbackkcal-AS关键字该属性只能在本AS内传递,定义了联邦则联邦EBGP邻居也能收到,但是无法传出本AS,就是大AS自治系统

 

Loopbackkcal-AS可选项使用规则:

R2(config)#ip community-list standard COMMUNITY permit 100:10

R2(config)#route-map test permit 10

R2(config-route-map)# match community COMMUNITY

R2(config-route-map)#set community 200:23 additive                 加上additive关键字

R2(config-route-map)#set community local-AS                              set那个local-AS可选项

R2(config-route-map)#set local-preference 200

R2(config-route-map)#exit

R2(config)#route-map test permit 20                                                  写一个空的Route-map,放行其他的路由

R2(config-route-map)#exit

R2(config)#router bgp 23

R2(config-router)#neighbor 4.4.4.4 route-map test out

  

R4#show ip bgp                                            

BGP table version is 10, local router ID is 4.4.4.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

*>i172.16.1.0/24    2.2.2.2                  0    200      0 100 i

*>i172.16.2.0/24    2.2.2.2                  0    100      0 100 i

R4作为R2的联邦EBGP邻居,虽然它们小AS号不同,但是它们同属一个大AS自治系统,说白了还是一家人嘛

 

R6#show ip bgp

BGP table version is 38, local router ID is 6.6.6.6

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

*> 172.16.2.0/24    192.168.46.4             0    200   100    i

R6作为其他AS自主系统,丢失了172.16.1.0/24路由

 

6.png


需求:R1路由器5loopback接口,假设R1还有很多很多loopback接口,只想对172.16.1.0/24路由标记10010 community值,剩下全部标记10020 community值。

Internet给我的感觉特别像空的Route-map,因为空的Route-mappermit any的意思,any不就是匹配所有路由么? Internet也是匹配所有路由。。。  还是挺绕的

 

Internet可选项使用规则:匹配路由表中所有路由前缀,一并标记community值。

R1(config)#ip prefix-list 10 permit 172.16.1.0/24                             抓取路由

R1(config)#route-map test permit 10

R1(config-route-map)#match ip address prefix-list 10

R1(config-route-map)#set community 100:10                                set一个community10010

R1(config-route-map)#exit

R1(config)#route-map test permit 20                                              创建Route-map,取名test

R1(config-route-map)#set community internet 100:100              匹配路由表中所有路由前缀

R1(config-route-map)#exit                                                                 这个时候就不用写空的Route-map

 

R2(config)#ip community-list standard COMMUNITY permit 100100

R2(config)#route-map test permit 10

R2(config-route-map)#match community COMMUNITY

R2(config-route-map)#set community 200:23 additive  

R2(config-route-map)#set metric 2000                                       为了实验效果我们修改BGPMED属性

R2(config)#route-map test permit 20                                           写一个空的Route-map,放行其他的路由

R2(config-route-map)#exit

R2(config)#router bgp 200

R2(config-router)#neighbor 4.4.4.4 route-map test out

 

R4#show ip bgp

BGP table version is 35, local router ID is 4.4.4.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

*> 172.16.1.0/24    2.2.2.2               0          100      0  100 i

*> 172.16.2.0/24    2.2.2.2               2000    100     0  100 i

*> 172.16.3.0/24    2.2.2.2               2000    100     0  100 i

*> 172.16.4.0/24    2.2.2.2               2000    100     0  100 i

 

 

上边一共做了六个实验,分别把Route-map中去set community属性的几个可选参数全部做了一遍

下边讲community-list在匹配的时候匹配规则,就是当一个路由携带多个community值的时候,你怎么写community-list列表才能去匹配住那个路由

 

 R1(config)#ip community-list standard name permit 100:10 100:10 local-AS ?        community-list在匹配的时候它可以在一行匹配Ncommunity值和下边的参数

  <1-4294967295>  community number

  aa:nn           community number

  internet        Internet (well-known community)

  local-AS        Do not send outside local AS (well-known community)

  no-advertise    Do not advertise to any peer (well-known community)

  no-export       Do not export to next AS (well-known community)

 

7.png


环境:R1在将172.16.1.0/24路由通过给R2路由器时为该路由分配了1001010011两个个community

但是R2它要基于community值简化配置,它的community-list要怎么写?

 

community-list匹配community属性规则:


R1(config)#ip prefix-list 10 permit 172.16.1.0/24

R1(config)#route-map test permit 10  

R1(config-route-map)#match ip address prefix-list 10 

R1(config-route-map)#set community 100:10 100:11            分配了两个community 分别是100:10和100:11,注意下边红色的字体

R1(config-route-map)#exit

R1(config)#route-map test permit 20

R1(config-route-map)#exit

 

R2(config)#ip community-list standard COMMUNITY permit 100:10 10020          注意R2的community-list写法一行同时写了两个,但是10020然而并不是R1 set10011

R2(config)#route-map test permit 10

R2(config-route-map)#match community COMMUNITY

R2(config-route-map)#set community additive             

R2(config-route-map)#set local-preference 200          为了看效果,修改下local-preference属性

R2(config)#route-map test permit 20                             写一个空的Route-map,放行其它的路由

R2(config-route-map)#exit

R2(config)#router bgp 200

R2(config-router)#neighbor 3.3.3.3 route-map test out

 

R3#show ip bgp           

BGP table version is 41, local router ID is 6.6.6.6

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

*> 172.16.1.0/24       2.2.2.2            0      100      0     100 i

*> 172.16.2.0/24       2.2.2.2            0      100     0     100 i

可以看到刚才R2设置的local-preference属性并未生效,因为local-preference属性它默认值是100

由上可以看出community-list匹配规则是当要匹配的路由前缀携带多个community-list值时,

如果写在一行只有全部的community值匹配正确,才能匹配上。

 

但是如果你是下边的写法:

R2(config)#ip community-list standard COMMUNITY permit 100:10         注意R2community-list写法一行只写了一个

R2(config)#route-map test permit 10

R2(config-route-map)#match community COMMUNITY

R2(config-route-map)#set community additive             

R2(config-route-map)#set local-preference 200          为了看效果,修改下local-preference属性

R2(config)#route-map test permit 20                             写一个空的Route-map,放行其它的路由

R2(config-route-map)#exit

R2(config)#router bgp 200

R2(config-router)#neighbor 3.3.3.3 route-map test out

 

R3#show ip bgp           

BGP table version is 41, local router ID is 6.6.6.6

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

*> 172.16.1.0/24       2.2.2.2            0      200      0     100 i

*> 172.16.2.0/24       2.2.2.2            0      100     0     100 i

 R2local-preference属性生效了


总结:community-list写在一行写多个community值的时候是一个且的关系,就是这一行的community值全部匹配上,这个community-list才能成真。

 

 

上边就是community-list的匹配规则

下边讲Route-mapmatch那个community列表时的宽松和严格模式的规则

 

 8.png


环境:R1R2通告了两条路由,分别是loopback1loopback2接口,并附带上两个不通的community值,具体附带什么看配置。    最关键的配置在R2路由器

 

R1(config)#ip prefix-list 10 permit 172.16.1.0/24

R1(config)#ip prefix-list 20 permit 172.16.2.0/24

R1(config)#route-map test permit 10

R1(config-route-map)#match ip address prefix-list 10

R1(config-route-map)#set community 100:10              loopback1路由set的是10010的值

R1(config-route-map)#exit

R1(config)#route-map test permit 20

R1(config-route-map)#match ip address prefix-list 20

R1(config-route-map)#set community 100:10 10020               loopback2路由set了两个值

R1(config-route-map)#exit

R1(config)#route-map test permit 30                                                写一个空Route-map

R1(config-route-map)#exit

R1(config)#router bgp 100

R1(config-router)#neighbor 192.168.12.2  route-map test out


 

R2(config)#ip community-list standard COMMUNITY permit 100:10                注意我community-list的我只permit了一个10010community

R2(config)#route-map test permit 10

R2(config-route-map)#match community COMMUNITY

R2(config-route-map)#set local-preference 200                   修改下local-preference属性200待会看效果

R2(config)#route-map test permit 20

R2(config-route-map)#exit

R2(config)#router bgp 200

R2(config-router)#neighbor 3.3.3.3 route-map test out

 

R3#show ip bgp           

BGP table version is 41, local router ID is 6.6.6.6

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

*> 172.16.1.0/24       2.2.2.2            0      200      0     100 i

*> 172.16.2.0/24       2.2.2.2            0      200     0     100 i

你会发现两条路由都被修改了local-preference属性值,因为R2community-list的时候只匹配了10010这个community值,但是两条路由都包含10010这个community值,所以都被修改了local-preference属性值。


下边我们在下边看下严格匹配的效果:

R2(config)#ip community-list standard COMMUNITY permit 100:10

R2(config)#route-map test permit 10

R2(config-route-map)#match community COMMUNITY exact-match          严格匹配关键字

R2(config-route-map)#set local-preference 200                                                       修改下local-preference属性200待会看效果

R2(config)#route-map test permit 20

R2(config-route-map)#exit

R2(config)#router bgp 200

R2(config-router)#neighbor 3.3.3.3 route-map test out

 

 

R3#show ip bgp           

BGP table version is 41, local router ID is 6.6.6.6

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

*> 172.16.1.0/24       2.2.2.2            0      200      0     100 i

*> 172.16.2.0/24       2.2.2.2            0      100     0     100 i

 

只有172.16.1.0/24被修改了local-preference属性值,这一次172.16.2.0/24并没有修改

你一旦在match的时候加上exact-match严格匹配关键字,它一定会严格的按照你community-list列表上所以的community值进行匹配,多一点少一点都匹配不上。

在刚才的community-list列表上R2它只写了一个10010对吧?

但是这两条路由所携带的community值只有172.16.1.0/24的是10010,所以它被匹配上了,而172.16.2.0/24它不但有10010它还有一个10020community值,这个时候它就不能被匹配上。这个就是在你match的时候严格匹配的意思

 

9.png 

 

需求:R1在上边的配置对172.16.2.0/24配置了两个community值一个是10010还有一个是10020,现在R2路由器它想删除其中一个community值,让我们看下如何删除一个或多个community

 

删除单个community

R2(config)#ip community-list standard COMMUNITY permit 100:20         把要删的community值匹配出来

R2(config)#route-map test permit 10                                             创建Route-map

R2(config-route-map)#set comm-list community COMMUNITY                 直接set那个community列表

R2(config-route-map)#exit

R2(config)#router bgp 200

R2(config-router)#neighbor 3.3.3.3 route-map test out

 

R3#show ip bgp 172.16.2.0

BGP routing table entry for 172.16.1.0/24, version 38

Paths: (1 available, best #1, table Default-IP-Routing-Table)

  Advertised to update-groups:

        2    3

  (23) 100

    2.2.2.2 (metric 156160) from 2.2.2.2 (2.2.2.2)

      Origin IGP, metric 0, localpref 100, valid, confed-external, best

      Community: 100:10                                                                                                         只有一个100:10的值,100:20的成功被删除

 

9.png


需求:R1在上边的配置对172.16.2.0/24配置了两个community值一个是10010还有一个是10020,现在R2路由器它想删除两个个community值,让我们看下如何删除多个community


删除多个community

R2(config)#ip community-list standard COMMUNITY permit 100:10 把要删的community值匹配出来

R2(config)#ip community-list standard COMMUNITY permit 100:20 在写一个要community-list

R2(config)#route-map test permit 10                     创建Route-map

R2(config-route-map)#set comm-list community COMMUNITY         直接set那个community列表

R2(config-route-map)#exit

R2(config)#router bgp 200

R2(config-router)#neighbor 3.3.3.3 route-map test out

 

R3#show ip bgp 172.16.2.0

BGP routing table entry for 172.16.1.0/24, version 38

Paths: (1 available, best #1, table Default-IP-Routing-Table)

  Advertised to update-groups:

        2    3

  (23) 100

    2.2.2.2 (metric 156160) from 2.2.2.2 (2.2.2.2)

      Origin IGP, metric 0, localpref 100, valid, confed-external, best

可以看到R2成功的删除了多个community值,其实删除多个community值就是多写一个community-list列表

 

整个community属性就全部写完了,其实写这个还是挺累的,当中停了一次写着写着不知道要怎么表达,因为有些实验它需要以视频方式讲解更能去表达一个人的意思,用文字写,很啰嗦,尤其在这个快餐的时代,很少有人能够静下心来看完别人写的整篇文章。关键我也不是专业写这个的,有时候表达啊可能更愿意按照自己的想法。

但是更多的还是要自己去实践

 

BGP的环境下做路由策略,它很多中方式。我全篇都是针对邻居做的Route-map

你可以针对特定的路由做Route-map(就是network后边也能携带Route-map

重发布路由时也能携带Route-map

 

至于说的networkneighbor的区别就是,你如果是用network的方式那么所有接收到该路由的邻居都能够继承你所配置的属性,但是如果你想针对特定的邻居生效那你就直接再用neighbor的方式。具体还有跟据情况决定。


猜你喜欢

转载自blog.51cto.com/13595867/2132137