一、BGP的汇总    1、最实用的方法:用network加一条指向null0的静态路由做汇总:不通告明细,只通告汇总路由。只能在产生明细路由的路由器上做。
    2、标准方法:aggregate-address。优点:在任何地方都可以做。自动产生指向NULL0的路由。
      (1)R4(config-router)#aggregate-address 4.1.0.0 255.255.252.0 summary-only 
          只传汇总路由。在起源路由器上用这条命令。
      (2)R1(config-router)#aggregate-address 4.1.0.0 255.255.252.0 summary-only as-set
          在非起源路由器上用这条命令。加上as-set的原因:在非起源路由器上做汇总会丢失以前的AS path,产生的汇总路由会从这个做汇总的路由器所在的AS算起,这在某些情况下会有产生环路的风险。as set参数就是还原as path属性(好像还可以还原其他属性)。例如:在一个路由器上汇总两个AS传过来的明细路由,as-set参数会给路由条目打上这两个AS号{200,400} 13,大括号里的号码是随机的,当这条汇总路由通过其他路径传到明细路由器上时,由于as-path中有自己AS的号码,这条路由将被丢弃。(写下来就明白一点了,这个大括号里面的as号只是为了防环,并不参与选路。)
      (3)精确控制只汇总哪些精确路由条目
          R1(config)#ip prefix-list 2 permit 4.1.2.0/24
          R1(config)#ip prefix-list 3 permit 4.1.3.0/24
          R1(config)#route-map aaa permit 10
          R1(config-route-map)#match ip address prefix-list 2 3
          R1(config-route-map)#router bgp 123
          R1(config-router)#aggregate-address 4.1.0.0 255.255.252.0 suppress-map aaa  as-set
          R1(config-router)#do sh ip b
            BGP table version is 15, local router ID is 1.1.1.1
            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
            *>i4.1.0.0/24      2.2.2.2                  0    100      0 400 i
            *> 4.1.0.0/22      0.0.0.0                      100  32768 400 i
            *>i4.1.1.0/24      2.2.2.2                  0    100      0 400 i
            s>i4.1.2.0/24      2.2.2.2                  0    100      0 400 i
            s>i4.1.3.0/24      2.2.2.2                  0    100      0 400 i
            *>i5.1.1.0/24      3.3.3.3                  0    100      0 500 i
          R1(config-router)#
          可以看出以上BGP表中有两条路由被抑制了。
          注意:在这里ip prefix-list和route-map都只是匹配,动作在汇总中实施。相反的情况,在route-map中采取动作,在neighbor命令后挂上这个route-map,则是控制路由条目的传递,非汇总。
    3、自动汇总:一般关闭
二、BGP的属性
    1、分类:公认的或可选的;强制的与自觉的;传递的与非传递的;部分的
    2、特点:前三类是不可同选(废话)
    3、合法组合:
      (1)公认的:所有运行BGP的路由器都必须要识别并且要能够标识,还要能够传递给其他邻居
          A:公认强制:这些属性必须出现的路由描述中,而且必须被识别:as-path;next-hop;起源;
          B:公认自觉:在路由描述中可以出现也可以不出现,但必须被识别:本地优先级
      (2)可选的:不一定所有的路由器都支持,
          A:可选传递:可以不被识别,但须被传递。只有可选传递的属性才能被标记为部分(这个是什么意思?)
          B:可选非传递:不支持则删除该属性:MED
三、BGP的团体属性
    1、性质:可选传递属性,如别的路由器不识别则直接传递,如识别才按照这个属性进行过滤
    2、目的:对路由条目设置相应属性,使得其在BGP域中自动进行过滤,在一台路由器上完成过滤,减少配置任务
    3、本质:打标记
    4、配置
      拓扑:R4、R2、R1、R3、R5五台路由串连,R4属于AS400,R2、R1、R3属于大AS123,R2、R1属于小AS65100,R3属于小AS65200,R5属于AS500.在R4上起四个环回口,通告进BGP(路由能够传递的前提已经做好)
      要求:R2能收到四条路由,R1收到3条,R3收到2条,R5收到1条,要求用BGP团体属性。
      配置示例一:
      (1)匹配路由条目
            R4(config)#ip prefix-list 0 permit 4.1.0.0/24
            R4(config)#ip prefix-list 1 permit 4.1.1.0/24
            R4(config)#ip prefix-list 2 permit 4.1.2.0/24
            R4(config)#ip prefix-list 3 permit 4.1.3.0/24
      (2)设置条目属性
            R4(config)#route-map comm permit 10
            R4(config-route-map)#match ip address prefix-list 0
            R4(config-route-map)#set community no-advertise          这个属性在下一跳生效后不再向其他路由器宣告
            R4(config)#route-map comm permit 20
            R4(config-route-map)#match ip address prefix-list 1
            R4(config-route-map)#set community local-AS              这个属性在下一跳生效后将只在小AS65100内传递
            R4(config)#route-map comm permit 30
            R4(config-route-map)#match ip address prefix-list 2
            R4(config-route-map)#set community no-export            这个属性在下一跳生效后将只在大AS123内传递
            R4(config)#route-map comm permit 40
            R4(config-route-map)#match ip address prefix-list 3
            R4(config-route-map)#set community none                  这个让它正常传递,也可以只per 40其他为空
      (3)在BGP进程里调用
            R4(config)#router bgp 400
            R4(config-router)#neighbor 202.100.0.2 route-map comm out出站方向,在下一跳起作用
      (4)让路由器发送这些团体属性(可选传递属性,识别方能起作用,要在每个路由上做)
            R4(config-router)#neighbor 202.100.0.2 send-community
            不打这条命令的话查看R1的BGP路由条目:
            R1#sh ip bgp 4.1.1.0
              BGP routing table entry for 4.1.1.0/24, version 4
              Paths: (1 available, best #1, table Default-IP-Routing-Table)
              Advertised to update-groups:
                      2       
                400
              2.2.2.2 (metric 1) from 2.2.2.2 (2.2.2.2)
              Origin IGP, metric 0, localpref 100, valid, confed-internal, best
            在R2打上这条命令
              R2(config)#router bgp 65100
              R2(config-router)#neighbor 1.1.1.1 send-community
            查看R1BGP条目:
              R1#sh ip bgp 4.1.1.0
                BGP routing table entry for 4.1.1.0/24, version 8
                Paths: (1 available, best #1, table Default-IP-Routing-Table, not advertised outside local AS)
                  Flag: 0x880
                  Not advertised to any peer
                  400
                2.2.2.2 (metric 1) from 2.2.2.2 (2.2.2.2)
                Origin IGP, metric 0, localpref 100, valid, confed-internal, best
                Community: local-AS
                R1#
            最后一行显示的就是团体属性。注意每台路由器上针对相应邻居都得打上send-community(不过在这个实验中好像只需要在前面三台路由器上做就可以了,因为4.1.2.0传到R3就不再传了,4.1.3.0没有团体属性)
      配置示例二:
        (1)匹配路由条目
            R4(config)#ip prefix-list 0 permit 4.1.0.0/24
            R4(config)#ip prefix-list 1 permit 4.1.1.0/24
            R4(config)#ip prefix-list 2 permit 4.1.2.0/24
            R4(config)#ip prefix-list 3 permit 4.1.3.0/24
        (2)设置条目团体属性并调用发送
            R4(config)#route-map comm permit 10
            R4(config-route-map)#match ip address prefix-list 0
            R4(config-route-map)#set community 1234       
            R4(config)#route-map comm permit 20
            R4(config-route-map)#match ip address prefix-list 1
            R4(config-route-map)#set community 400:5678              前面的400通常为AS号,后面的随便,vpn里会有类似形式
            R4(config)#route-map comm permit 30
            R4(config-router)#nei 202.100.0.2 route-map ano out
            R4(config-router)#neighbor 202.100.0.2 send-community
        (3) 在其他路由上再次设置团体属性
            R2(config)#ip community-list 1 permit 1234              匹配团体列表
            R2(config)#ip community-list 2 permit 400:5678           
            R2(config)#route-map ano permit 10
            R2(config-route-map)#match community 1                  调用团体列表1
            R2(config-route-map)#set metric 600
            R2(config)#route-map ano permit 20
            R2(config-route-map)#match community 2
            R2(config-route-map)#set local-preference 50            再次设置团体属性
            R2(config)#route-map ano permit 30
        (3)再次在在BGP进程里调用
            R2(config-router)#nei 1.1.1.1 route-map ano out
        (4)再次让路由器发送这些团体属性
            R2(config-router)#neighbor 1.1.1.1 send-community
            R1#sh ip b
              BGP table version is 22, local router ID is 1.1.1.1
            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
            *>i4.1.0.0/24      2.2.2.2                600    100      0 400 i
            *>i4.1.1.0/24      2.2.2.2                  0    50      0 400 i
            *>i4.1.2.0/24      2.2.2.2                  0    100      0 400 i
            *>i4.1.3.0/24      2.2.2.2                  0    100      0 400 i
            *> 5.1.1.0/24      3.3.3.3                  0    100      0 (65200) 500 i
            可以看出,相应条目的metric和本地优先级都改过来了