配置团体属性,让 2.2.2.0 网络只被 R2 学习到
这里最合适的 community 属性应该是: no_advertise 因为它不会向任何 EBGP IBGP 邻居公布路由。
r1(config)#access-list 1 permit 2.2.2.0 0.0.0.255  / ACL 匹配该路由
 
r1(config)#route-map WY permit 10
r1(config-route-map)#match ip add 1
r1(config-route-map)#set community no-advertise  / 设定团体属性
r1(config)#route-map WY permit 20 / ACL 一样 route-map 最后也隐藏了一句 deny any ,所以在这里要允许所有,要不然其它两条路由会因为匹配不上而无法从 R1 传递出去。
r1(config)#router bgp 100
r1(config-router)#neighbor 12.0.0.2 route-map WY out  / 在进程下出方向调用 route-map
r1(config-router)#neighbor 12.0.0.2 send-community / R2 传递该社团属性
 
先在 R2 上进行查看;
r2#sh ip bgp
   Network          Next Hop            Metric LocPrf Weight Path
*> 2.2.2.0/24       12.0.0.1                 0             0 100 i
*> 22.22.22.0/24    12.0.0.1                 0             0 100 i
*> 222.222.222.0    12.0.0.1                 0             0 100 i
R2 可以学习到该路由
R3 上查看
r3#sh ip bgp
   Network          Next Hop            Metric LocPrf Weight Path
*>i22.22.22.0/24    23.0.0.2                 0    100      0 100 i
*>i222.222.222.0    23.0.0.2                 0    100      0 100 i
可以看到 R3 已经收不到 2.2.2.0 这个网络了,往后的路由器也无法收到了。所以社团属性
No_advertise 满足了只让 R2 学到该路由的需求。
 
  配置团体属性,让 22.22.22.0 网络只被 R2,R3 学习到
因为 R2,R3 处于联邦内同一个子 AS ,意思是该路由不能传递出这个子 AS ,所以可以用 community 属性: LOCAL_AS
 
r1(config)#access-list 2 permit 22.22.22.0 0.0.0.255
 
r1(config)#route-map WY permit 10
r1(config-route-map)#match ip add 2
r1(config-route-map)#set community local-AS
r1(config)#route-map WY permit 20
 
现在进行查看
r2#sh ip bgp
   Network          Next Hop            Metric LocPrf Weight Path
*> 2.2.2.0/24       12.0.0.1                 0             0 100 i
*> 22.22.22.0/24    12.0.0.1                 0             0 100 i
*> 222.222.222.0    12.0.0.1                 0             0 100 i
R2 可以学习到。
r3#sh ip bgp
   Network          Next Hop            Metric LocPrf Weight Path
*>i2.2.2.0/24       23.0.0.2                 0    100      0 100 i
*>i22.22.22.0/24    23.0.0.2                 0    100      0 100 i
*>i222.222.222.0    23.0.0.2                 0    100      0 100 i
R3 也可以学到
r4#sh ip bgp
   Network          Next Hop            Metric LocPrf Weight Path
*> 2.2.2.0/24       34.0.0.3                 0    100      0 (64512) 100 i
*> 22.22.22.0/24    34.0.0.3                 0    100      0 (64512) 100 i
*> 222.222.222.0    34.0.0.3                 0    100      0 (64512) 100 i
为什么 R4 依然可以学习到,难道属性没起作用吗?显然属性没有起作用,这是因为 R2 R3 传递该路由时没有让 R3 继承这个属性,所以 R4 依然可以学习到,现在必须在 R2 上配置让 R3 继承这个属性,这样 R3 R4 传递路由时团体属性才能生效。
r2(config)#router bgp 64512
r2(config-router)#neighbor 23.0.0.3 send-community
R2 上配置让 R3 继承该属性
r4#sh ip bgp
   Network          Next Hop            Metric LocPrf Weight Path
*> 2.2.2.0/24       34.0.0.3                 0    100      0 (64512) 100 i
*> 222.222.222.0    34.0.0.3                 0    100      0 (64512) 100 i
现在 R4 就收不到这条路由了, R5 当然也收不到, LOCAL_AS 团体属性满足了这个需求。
 
  配置团体属性,让 222.222.222.0 网络只被 R2,R3,R4 学习到
这个需求意思是让这条路由不传到联邦外(大 AS 之外),所以要用 NO_EXPORT 属性
 
r1(config)#access-list 3 permit 222.222.222.0 0.0.0.255
 
r1(config)#route-map WY permit 10
r1(config-route-map)#match ip add 3
r1(config-route-map)#set community no-export
r1(config)#route-map WY permit 20
 
为了让 R4 能继承到该属性,必须在 R1,R2,R3 都配置 send-community 以便让该属性进行传递。在配置了传递属性之后,现在进行查看
r4#sh ip bgp
   Network          Next Hop            Metric LocPrf Weight Path
*> 2.2.2.0/24       34.0.0.3                 0    100      0 (64512) 100 i
*> 22.22.22.0/24    34.0.0.3                 0    100      0 (64512) 100 i
*> 222.222.222.0    34.0.0.3                 0    100      0 (64512) 100 i
R4 可以收到
 
r5#sh ip bgp
   Network          Next Hop            Metric LocPrf Weight Path
*> 2.2.2.0/24       45.0.0.4                               0 234 100 i
*> 22.22.22.0/24    45.0.0.4                               0 234 100 i
R5 已经学习不到 222.222.222.0 了。需求满足。
 
但上面的做法有一个明显的缺点就是要在 R1,R2,R3 上配置传递该属性,比较麻烦。
 
现在用另一种比较简单的方法。
R4 上直接进行配置。
r4(config)#access-list 1 permit 222.222.222.0 0.0.0.255
 
r4(config)#route-map WY permit 10
r4(config-route-map)#match ip add 1
r4(config-route-map)#set community no-export
r4(config)#route-map WY permit 20
 
r4(config)#router bgp 64513
r4(config-router)#neighbor 34.0.0.3 route-map WY in
指定 R3 R4 传递路由时应用该 route-map ,所以是 in 方向的。