一,基本概念

1、 路由协议的分类
(1)       IGP:rip、ospf、eigrp、isis等
(2)       EGP:分为EGP和BGP,BGP是基于EGP开发出来的。
2、 区分IGP和EGP:工作在一个AS内部的就是IGP,工作在AS之间的就是EGP。
(1)       AS(autonomous systems):由统一管理者管理的管理的范围就是一个AS。
(2)       例如:电信和网通
3、 AS号的范围
(1)       公有:0~64511
(2)       私有:64512~65535
(3)       查全世界的AS号的网址: http://bgp.potaroo.net
4、 BGP:Path-Vector Routing(路径矢量协议)
1.         BGP:AS-by-AS
2.         IGP:Hop-by-Hop
5、 BGP Characteristics
(1)       当一个数据包从一个AS穿越另一个AS的时候
(2)       当一个AS连接多个AS的时候
(3)       路由策略(选路)
(4)       在公网选用BGP的优点:
l 管理不方便
l 其他协议没办法支持那么多路由(在公网一般有十几万条)ospf支持1万条,isis也就2万条。
l 策略方面比IGP更多
l 扩展性大:可以传ipv4、ipv6和***v4等。
(5)       公网的虚拟路由器,映射了公网的所有路由。
l telnet route-server.ip.att.net
l 用show ip route summary可以查看公网有多少BGP路由
6、 在什么情况下不要用BGP
(1)    对BGP不熟悉的时候
(2)    不存在选路的时候
(3)    路由器的性能不够强的时候
7、 BGP的特征
(1)       用的协议是:tcp
(2)       端口:179
(3)       更新:触发更新(rip、ospf、isis是触发和周期更新,而eigrp是触发更新)
(4)       通过发keepalive报文维持邻居的状态,周期性的发keepalive报文,周期是60秒。如果180秒没有收到keepalive就认为邻居down了
8、 BGP与IGP的不同
(1)       在IGP中hello包上用来建邻居和keeplive的
(2)       在BGP中,建邻居用的是open报文,保持连接用的是keepalive报文
9、 IGP是用metrics或者cost来衡量路径的好坏,而BGP是用attribute(属性)。
10、              BGP设计是为了大型网络的。
 
二、BGP的三张表
1、表的名称和作用
(1)Neighbor table:用open报文建立邻居
(2)BGP table(forwarding database):会选出一条最优的路径放到路由表中。
(3)ip routeing table
2、BGP分IBGP和EBGP,IBGP的管理距离是200,EBGP是20
三、BGP的报文
 1、报文的名称和作用
(1)Open:用来建立邻居,报文中包括hold time和router id(router id手工指定,如果没有手工指定就是loopback口最大的ip地址,或者物理接口最大IP地址)
(2)keepalive:用来维持邻居关系
(3)Update:传输BGP路由,bgp的路由更新
(4)Notification:当错误发生的时候会发这个报文
 四、EBGP和IBGP的介绍
1、名词解释:
 (1)Peers = Neighbors
 (2)BGP speakers:运行BGP的路由器
2、External BGP:在不同AS之间建立的BGP邻居关系
3、Internal BGP:在同一AS之间建立的BGP邻居关系
五、路由黑洞解决方法:
1、物理线路FULL MESH
2、BGP邻居的FULL MESH
3、将BGP重分布到IGP中(只用于实验环境中)
4、最好的解决方法的MPLS
六、水平分割
 1、EBGP的水平分割:主要靠AS号,不接收本AS号的BGP路由。如下图:
因为一个AS里的A1路由器发给下一个AS里的A2路由器路由的时候,其中字段包含AS号和下一条地址等,当A2发给A3路由的时候,字段里就带两个AS号AS1和AS2,当A3再发给A1的时候,里面有和A1一样的AS号。这时候A1就不接收相同AS号的路由。 
 
 
2、IBGP的水平分割:从IBGP邻居学到的路由,不会再通告给其他的IBGP邻居。如下图,D从B学到的路由不会再通告给E.
七.BGP的基本配置
 1、实验拓扑如下:
    
 2、实验步骤:
   (1)基本配置:
      R1: interface loopback0
          ip add 1.1.1.1 255.255.255.0
          interface serial 0
           ip address 12.1.1.1 255.255.255.0
           no shut
           interface serial 1
           ip address 13.1.1.1 255.255.255.0
            no shut
            line con 0
             exec-time 0 0
             logging sysncharonous
 
R2:interface loopback0
     ip add 2.2.2.2 255.255.255.0
     interface serial 0
     ip address 12.1.1.2 255.255.255.0
      clockrate 1000000
      no shut
      interface serial 1
      ip address 24.1.1.2 255.255.255.0
      clockrate 1000000
      no shut
R3:interface loopback0
     ip add 3.3.3.3 255.255.255.0
     interface serial 0
     ip address 35.1.1.3 255.255.255.0
      clockrate 1000000
      no shut
      interface serial 1
      ip address 13.1.1.3 255.255.255.0
      clockrate 1000000
      no shut
R4:interface loopback0
     ip add 4.4.4.4 255.255.255.0
     interface serial 0
     ip address 461.1.4 255.255.255.0
      clockrate 1000000
      no shut
      interface serial 1
      ip address 24.1.1.4 255.255.255.0
      clockrate 1000000
      no shut
R5:interface loopback0
     ip add 5.5.5.5 255.255.255.0
     interface serial 0
     ip address 35.1.1.5 255.255.255.0
      clockrate 1000000
      no shut
(2)R2和R4建邻居
l R4的配置
R4(config)#router bgp 4
R4(config-router)#bgp router-id 4.4.4.4(建议和OSPF配成一样的)
    R4(config-router)#neighbor 24.1.1.2 remote-as 1(与对端建立邻居,在BGP中用这条命令建立邻居)
l R2的配置
R2(config)#router bgp 1
R2(config-router)#bgp router-id 2.2.2.2(建议和OSPF配成一样的)
    R2(config-router)#neighbor 24.1.1.4 remote-as 4
(3)R2和R3建立IBGP邻居()
     首先配置IGP(OSPF)互通路由
l R2的配置
R2(config)#router ospf 110
R2(config-router)#router-id 2.2.2.2
R2(config-router)#network 12.1.1.0 0.0.0.255 area 0
         R2(config-router)#network 2.2.2.0 0.0.0.255 area 0
l R1的配置
R1(config)#router ospf 110
R1(config-router)#router-id 1.1.1.1
R1(config-router)#network 12.1.1.0 0.0.0.255 area 0
R1(config-router)#network 13.1.1.0 0.0.0.255 area 0
         R2(config-router)#network 1.1.1..0 0.0.0.255 area 0
l R3的配置
R3(config)#router ospf 110
R3(config-router)#router-id 3.3.3.3
R3(config-router)#network 13.1.1.0 0.0.0.255 area 0
         R3(config-router)#network 3.3.3.0 0.0.0.255 area 0
     建立IBGP邻居用R2和R3的环回口
l R2的配置
R2(config)#router bgp 1
    R2(config-router)#neighbor 3.3.3.3. remote-as 1
    R2(config-router)#neighbor 3.3.3.3 update-source loopback 0(我和R3建立邻居的时候,回来的时候是loopback口,不然无法用环回口建立邻居)
l R3的配置
R3(config)#router bgp 1
    R3(config-router)#neighbor 2.2.2.2 remote-as 1
    R3(config-router)#neighbor 2.2.2.2 update-source loopback 0(建议两边都做,但一边做也可以)
(4)如果R3和R5是如下图所示,要用环回口建立邻居,能保证冗余备份
这是建立邻居关系最麻烦的一种,默认发出来的TTL=1,到了对端就不能再传了,所以这里要涉及到ebgp-multihop(多跳),配置为大于等于2才能到达对端的环回口。配置静态路由的为了能跑让不同的AS有路由。
l 如上图的R3和R5建立邻居如下:
l R3的配置
 R3(config)#router bgp 1
R3(config-router)#neighbor 5.5.5.5 remote-as 5
R3(config-router)#neighbor 5.5.5.5 update-source loopback 0
R3(config-router)#neighbor 5.5.5.5 ebgp-multihop 2(ebgp的最大跳数是2,默认回车是最大的255)
R3(config)#ip route 5.5.5.5 255.255.255.255 serial 0
l R5的配置
R5(config)#router bgp 5
R3(config-router)#neighbor 3.3.3.3 remote-as 1
R3(config-router)#neighbor 3.3.3.3 update-source loopback 0
R3(config-router)#neighbor 3.3.3.3 ebgp-multihop 2
R5(config)#ip route 3.3.3.3 255.255.255.255 serial 0
 
   (5)宣告路由:
l R4的配置
R4(config)#router bgp 4
R4(config-router)#network 4.4.4.0 mask 255.255.255.0(BGP的network可以通告本地路由表所有的路由,而IGP是只通告本接口的路由)
    (6)当R4的路由传到R5上的时候,还是不能通信,必须R1和R2、R3都建立BGP邻居才可以,配置如下,用peer group技术,如下:
R1(config)#router bgp 1
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#neighbor WOLF peer-group(定义一个模板,给peer group启的名字)
R1(config-router)#neighbor WOLF remote-as 1(模板的命令,与1建立邻居关系)
R1(config-router)#neighbor WOLF update-source loopback 0(模板的命令,更新源是环回口)
R1(config-router)#neighbor 2.2.2.2 peer-group WOLF(调用peer-group的模板)
R1(config-router)#neighbor 3.3.3.3 peer-group WOLF(调用peer-group的模板)
 
R2(config)#router bgp 1
R2(config-router)#neighbor 1.1.1.1 remote-as 1
R2(config-router)#neighbor 1.1.1.1 update-source loopback 0
R2(config-router)#neighbor 1.1.1.1 next-hop-self
 
R3(config)#router bgp 1
R3(config-router)#neighbor 1.1.1.1 remote-as 1
R3(config-router)#neighbor 1.1.1.1 update-source loopback 0
 
    (7)想要R5和R4互通,需要把R5的路由通告出来
          R5(config)#router bgp 5
          R5(config-router)#network 5.5.5.0 mastk 255.255.255.0
         
          R3(config-router)#neighbor 1.1.1.1 next-hop-self
 R3(config-router)#neighbor 2.2.2.2 next-hop-self
     (8)用R5 ping R4测试
          R5#ping 4.4.4.4 source 5.5.5.5 (否则源地址是R5的S0接口了,没有宣告路由,所以不同)
 
 
3、查看命令:
 (1)查看邻居信息的简表:show ip bgp summary 
    
如果看到state/PfxRcd下面是数字就代表邻居建立起来了,数字代表学到了多少路由
(2)查看邻居详细列表:show ip bgp neighbor
(3)查看链接的端口:show tcp brief
(4)查看BGP表:show ip bgp
    
l *号代表这条路由可用
l >号代表最好的路由,没有标识>号的路由,认为不是最优的,所有不放进路由表,也不会给其他BGP邻居传
l BGP路由优化的条件:
1.         同步:(解放方法:从IGP学到或者关掉同步no syn(在12.2(8)以上的版本开启BGP后会自动生产的)同步是针对IBGP说的,EBGP传过来的路由都优化}
2.         下一条:用静态或IGP学/ next-hop-self(就是我给你发的路由下一条指向我,如上图在R2的配置:
R2(config-router)#neighbor 3.3.3.3 next-hop-self