BGP community属性无敌详解文档(视频详解+配套文档)community属性是BGP众多路径属性中一个相对比较难理解的知识点,需要通过大量实验加深印象,为了帮助大家更清晰的了解这个路径属性,我特定编写了这份文档,希望对大家有所帮助。
本文档配套详解视频:1、community的基本概念可选传递,用于简化路由策略的执行。
可以将某些路由分配一个特定的COMMUNITY 属性,之后就可以基于COMMUNITY值而不是每条路由进行BGP属性的设置了。
COMMUNITY属性对邻居起作用,在设置后,同时需要向邻居发送(send community,默认是不会发送的)。
COMMUNITY属性是一组4个8位组的数值,RFC1997规定前2B表示AS号,后2B 表示基于管理目的设置的标示符,格式为AA:NN,而CISCO默认显示格式为NN:AA (CISCO IOS在显示community值时,默认是按10进制格式显示),可使用全局配置命令ip bgpcommunity new-format将CISCO默认格式改为RFC格式。
例如将AS12的某条路由COMM值改为10000,RFC采用十六进制表示COMMUNITY属性,而CISCO采用十进制。
RFC格式为12:10000,十六进制为0x 000C2710,再转换为十进制796432(这就是CISCO IOS默认显示的值)。
抓个包看一下:2、在route-map中设置community属性route-map test permit 10set community ?<1-4294967295> community numberaa:nn community number in aa:nn formatadditive Add to the existing community 设置commu值为附加,否则为覆盖 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)none No community attribute下边我们来看一下community的这几个众所周知值的本文为原创博文,no-advertiseno-exportlocal-as配置示例(使用route-map为路由分配community):在R1上为路由11.11.11.0/24分配community 100:11,并且传递给R2,那么R1上配置如下:ip prefix-list 11 permit 11.11.11.0/24route-map test permit 10match ip address prefix-list 11set community 100:11router bgp 100network 11.11.11.0 mask 255.255.255.0neighbor 10.1.12.2 remote-as 200neighbor 10.1.12.2 send-community // 默认community不发送,因此必须配置该命令neighbor 10.1.12.2 route-map test out注意community默认不发送,必须send-community。
另外一条路由前缀可以携带多个community形成一个列表,如果要针对特定路由在原有的community基础之上再增加一个community,则在route-map中set community时,增加additive关键字。
3、使用ip community-list匹配community值ip community-list ?<1-99> Community list number (standard)<100-500> Community list number (expanded)expanded Add an expanded community-list entrystandard Add a standard community-list entryip community-list 也像ACL那样,有标准和扩展之分,1-99为标准,100-199为扩展。
扩展的community-list 可以使用正则表达式匹配路由。
这里有一点需要注意,ip bgp-community new-format用于转换community在CISCO IOS中的显示格式,当在扩展的community-list列表中使用正则表达式的过滤结果会由于格式的选择不同而不同。
ip community-list示例1在上面实验的基础上,R1传递给R2的11.11.11.0/24路由,携带了community值100:11,这个值可以在R2上使用ip community-list进行匹配,从而可以进一步在route-map中用这个community-list去设置策略。
我们现在在R2上用community-list 去匹配100:11,通知添加一个no-export的community到该路由。
R2的配置如下:ip community-list 11 permit 100:11route-map test permit 10match community 11set community no-export additiverouter bgp 200neighbor 10.1.12.1 remote-as 100neighbor 10.1.23.3 remote-as 300neighbor 10.1.23.3 send-communityneighbor 10.1.23.3 route-map test outR3上show ip bgp 11.11.11.0BGP routing table entry for 11.11.11.0/24, version 5Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised to EBGP peer)Flag: 0x820Not advertised to any peer200 10010.1.23.2 from 10.1.23.2 (10.1.23.2)Origin IGP, localpref 100, valid, external, bestCommunity: 100:11 no-exportip community-list的示例2(逻辑关系):当11.11.11.0/24路由前缀携带的community属性为“100:11 no-export”,我们做如下测试:Ip community-list 11 permit 100:11匹配。
这种写法将匹配community中包含100:11的路由。
Ip community-list 11 permit 100:11 no-advertise不匹配。
这种写法要求community中同时包含100:11及no-advertise才匹配成立。
Ip community-list 11 permit 100:11Ip community-list 11 permit no-export (或将no-export换成no-adv)匹配。
这种写法只要community中包含100:11或no-export就匹配成立ip community-list的示例3(严格匹配community):注意我们实验环境的变化,12.12.12.0携带的community值为no-export,如果我们只希望匹配no-export community值(的路由),那么怎么写呢?如果是直接去匹配no-export,会连同11.11.11.0也一并匹配上了,所以就要使用到exact-match关键字了。
在R3上如果配置如下:Ip community-list 11 permit no-exportroute-map test permit 10match community 11 exact-match // 严格匹配如果不加exact-match关键字,则该community-list将匹配11及12路由,加了之后,则只匹配community为no-export的路由,不能多,不能少。
4、在community列表中删除特定的community值前面已经说了,一条路由,允许携带多个community值,构成一个community列表,那么如果想删除某个或者某几个community值,例如:12:11 12:1111 no-export 这个comm列表,要删除其中的no-export,则可ip community-list 1 permit no-export // 匹配要删除的commu值route-map test permit 10set comm-list 1 delete // 用这条命令删除如果要删除多个community(而不是所有),则可在一个community-list中写多条,如ip community-list 1 permit no-exportip community-list 1 permit 12:1111然后再用set comm-list 1 delete去删除,注意上面community-list的写法,要用多行,在同一行写多个commu如ip community-list 1 permit no-export 12:1111则不生效。
R3收到两条路由,分别携带的community属性如上,现在,我们只想删除11路由的no-export属性。
ip community-list 11 permit 100:11 no-export //这条用来匹配11路由ip community-list standard del permit no-export //这条用来删除no-export属性,是个命令列表route-map test permit 10match community 11set metric 1111set comm-list del deleteroute-map test permit 20router bgp 300neighbor 10.1.23.2 remote-as 200neighbor 10.1.23.2 route-map test in如果想把11路由的100:11及no-export 两个community值都删除,则修改del 这条community-list即可:ip community-list standard del permit no-exportip community-list standard del permit 100:11。