BGP协议的原理及应用
一、BGP特征
① 传输协议:TCP,端口号179
② BGP是外部路由协议,用来在AS之间传递路由信息
③ 是一种增强的路径矢量路由协议
④ 拥有可靠的路由更新机制
⑤ 具备丰富的Metric度量方法
⑥ 无环路协议设计
⑦ 为路由条目附带多种属性信息
⑧ 支持CIDR(无类别域间选路)
⑨ 丰富的路由过滤和路由策略
⑩ 无需周期性更新
⑪ 路由更新时只发增量路由
⑫ 周期性发送KeepAlive报文以保持TCP连通性
二、BGP报文
Open报文
Update报文
Notification报文
Router-refresh
KeepAlive
三、BGP状态机
Idle状态
Connect状态
Active状态
OpenSent状态
OpenConfirm状态
Established状态
四、BGP数据库
IP路由表(IP-RIB) IBGP
BGP路由表(Loc-RIB) EBGP
五、BGP对等体配置:对等体交互原则
①从IBGP对等体获得的BGP路由,BGP设备只传递给它的EBGP对等体
②从EBGP对等体获得的BGP路由,BGP设备只传递给它所有EBGP和IBGP对等体(对等体是IBGP只能传一跳,对等体是EBGP则不限制)
③当存在多条到达同一目的地址的有效路由时,BGP设备只将最优路由发布给对等体
④路由更新时,BGP设备只发送更新的BGP路由
⑤所有对等体发送的路由,BGP设备都会接收
⑥所有EBGP对等体在传递过程中下一跳改变
⑦所有IBGP对等体在传递过程中下一跳不变
⑧默认EBGP传递时,TTL值为1
⑨默认IBGP传递时,TTL值为255
六、更新源建立邻居关系
1、BGP直连网段建立邻居
2、BGP环回口建立邻居
①EBGP区域命令
Peer 3.3.3.3 as-number 100 指向对端BGP
Peer 3.3.3.3 connect-interface loop back 0 建立邻居接口
Peer 3.3.3.3 ebgp-max-hop 255 修改多跳,默认1跳
设置静态路由下一跳
②IBGP区域命令
Peer 1.1.1.1 as-number 100 指向对端BGP
Peer 1.1.1.1 connect-interface loop back 0 建立邻居接口
Peer 1.1.1.1 next-hop-local 下一跳指向自己,此命令只在AS边缘路由器设置
1、BGP直连网段建立邻居
AR1配置信息
<Huawei>undo terminal monitor
<Huawei>system-view
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]sysname R1
[R1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 12.1.1.1 24
[R1-GigabitEthernet0/0/0]undo shutdown
[R1-GigabitEthernet0/0/0]int loop 0
[R1-LoopBack0]ip add 1.1.1.1 32
[R1-LoopBack0]quit
[R1]ospf 1
[R1-ospf-1]area 0
[R1-ospf-1-area-0.0.0.0]network 1.1.1.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network 12.1.1.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0]quit
[R1-ospf-1]quit
[R1]bgp 100
[R1-bgp]router
[R1-bgp]router-id 1.1.1.1
[R1-bgp]peer 12.1.1.2 as-number 100
[R1-bgp]network 1.1.1.1 32
[R1-bgp]network 12.1.1.0 24
[R1-bgp]display ip rou
AR2配置信息
<Huawei>undo terminal monitor
<Huawei>system-view
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]sysname R2
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 12.1.1.2 24
[R2-GigabitEthernet0/0/0]undo shutdown
[R2-GigabitEthernet0/0/0]int g0/0/1
[R2-GigabitEthernet0/0/1]ip add 23.1.1.2 24
[R2-GigabitEthernet0/0/1]undo shutdown
[R2-GigabitEthernet0/0/1]int loop 0
[R2-LoopBack0]ip add 2.2.2.2 32
[R2-LoopBack0]quit
[R2]ospf 1
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 12.1.1.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]quit
[R2-ospf-1]quit
[R2]bgp 100
[R2-bgp]router-id 2.2.2.2
[R2-bgp]peer 12.1.1.1 as-number 100
[R2-bgp]peer 23.1.1.3 as-number 200
[R2-bgp]network 2.2.2.2 32
[R2-bgp]network 12.1.1.0 24
[R2-bgp]network 23.1.1.0 24
[R2-bgp]quit
AR3配置信息
<Huawei>undo terminal monitor
<Huawei>system-view
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]sysname R3
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ip add 23.1.1.3 24
[R3-GigabitEthernet0/0/0]undo shutdown
[R3-GigabitEthernet0/0/0]int loop 0
[R3-LoopBack0]ip add 3.3.3.3 32
[R3-LoopBack0]quit
[R3]bgp 200
[R3-bgp]router-id 3.3.3.3
[R3-bgp]peer 23.1.1.2 as-number 100
[R3-bgp]quit
[R3]bgp 200
[R3-bgp]network 3.3.3.3 32
[R3-bgp]network 23.1.1.0 24
[R3-bgp]quit
2、BGP环回口建立邻居
AR5配置信息
<Huawei>undo terminal monitor
<Huawei>system-view
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]sysname R5
[R5]int g0/0/0
[R5-GigabitEthernet0/0/0]ip add 45.1.1.5 24
[R5-GigabitEthernet0/0/0]undo shutdown
[R5-GigabitEthernet0/0/0]int loop 0
[R5-LoopBack0]ip add 5.5.5.5 32
[R5-LoopBack0]quit
[R5]bgp 300
[R5-bgp]router-id 5.5.5.5
[R5-bgp]peer 4.4.4.4 as-number 100
[R5-bgp]peer 4.4.4.4 connect-interface loop 0
[R5-bgp]peer 4.4.4.4 ebgp-max-hop 255
[R5-bgp]quit
[R5]ip route-static 4.4.4.4 32 45.1.1.4
[R5]bgp 300
[R5-bgp]network 5.5.5.5 32
[R5-bgp]network 45.1.1.0 24
[R5-bgp]quit
AR4配置信息
<Huawei>undo terminal monitor
<Huawei>system-view
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]sysname R4
[R4]int g0/0/1
[R4-GigabitEthernet0/0/1]ip add 45.1.1.4 24
[R4-GigabitEthernet0/0/1]undo shutdown
[R4-GigabitEthernet0/0/1]int g0/0/0
[R4-GigabitEthernet0/0/0]ip add 14.1.1.4 24
[R4-GigabitEthernet0/0/0]undo shutdown
[R4-GigabitEthernet0/0/0]int loop 0
[R4-LoopBack0]ip add 4.4.4.4 32
[R4-LoopBack0]quit
[R4]ospf 1 router-id 4.4.4.4
[R4-ospf-1]area 0
[R4-ospf-1-area-0.0.0.0]network 4.4.4.4 0.0.0.0
[R4-ospf-1-area-0.0.0.0]network 14.1.1.0 0.0.0.255
[R4-ospf-1-area-0.0.0.0]quit
[R4-ospf-1]quit
[R4]bgp 100
[R4-bgp]router-id 4.4.4.4
[R4-bgp]peer 5.5.5.5 as-number 300
[R4-bgp]peer 5.5.5.5 connect-interface loop 0
[R4-bgp]peer 5.5.5.5 ebgp-max-hop 255
[R4-bgp]peer 1.1.1.1 as-number 100
[R4-bgp]peer 1.1.1.1 connect-interface loop 0
[R4-bgp]peer 1.1.1.1 next-hop-local
[R4-bgp]peer 2.2.2.2 as-number 100
[R4-bgp]peer 2.2.2.2 connect-interface loop 0
[R4-bgp]peer 2.2.2.2 next-hop-local
[R4-bgp]network 4.4.4.4 32
[R4-bgp]network 45.1.1.0 24
[R4-bgp]network 14.1.1.0 24
[R4-bgp]network 5.5.5.5 32
[R4-bgp]network 1.1.1.1 32
[R4-bgp]network 2.2.2.2 32
AR1配置信息
<Huawei>undo terminal monitor
<Huawei>system-view
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]sysname R2
[R2]sysname R1
[R1]int g0/0/1
[R1-GigabitEthernet0/0/1]ip add 14.1.1.1 24
[R1-GigabitEthernet0/0/1]undo shutdown
[R1-GigabitEthernet0/0/1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 12.1.1.1 24
[R1-GigabitEthernet0/0/0]undo shutdown
[R1-GigabitEthernet0/0/0]int loop 0
[R1-LoopBack0]ip add 1.1.1.1 32
[R1-LoopBack0]quit
[R1]ospf 1 router-id 1.1.1.1
[R1-ospf-1-area-0.0.0.0]network 1.1.1.1 0.0.0.0
[R1-ospf-1-area-0.0.0.0]network 14.1.1.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0]network 12.1.1.0 0.0.0.255
[R1-ospf-1-area-0.0.0.0]quit
[R1-ospf-1]q
[R1]bgp 100
[R1-bgp]router-id 1.1.1.1
[R1-bgp]peer 4.4.4.4 as-number 100
[R1-bgp]peer 4.4.4.4 connect-interface loop 0
[R1-bgp]peer 2.2.2.2 as-number 100
[R1-bgp]peer 2.2.2.2 connect-interface loop 0
[R1-bgp]network 1.1.1.1 32
[R1-bgp]network 14.1.1.0 24
[R1-bgp]network 12.1.1.0 24
AR2配置信息
<Huawei>undo terminal monitor
<Huawei>system-view
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]sysname R2
[R2]int g0/0/0
[R2-GigabitEthernet0/0/0]ip add 12.1.1.2 24
[R2-GigabitEthernet0/0/0]undo shutdown
[R2-GigabitEthernet0/0/0]int g0/0/1
[R2-GigabitEthernet0/0/1]ip add 23.1.1.2 24
[R2-GigabitEthernet0/0/1]undo shutdown
[R2-GigabitEthernet0/0/1]int loop 0
[R2-LoopBack0]ip add 2.2.2.2 32
[R2-LoopBack0]quit
[R2]ospf 1 router-id 2.2.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 12.1.1.0 0.0.0.255
[R2-ospf-1-area-0.0.0.0]quit
[R2-ospf-1]quit
[R2]bgp 100
[R2-bgp]router-id 2.2.2.2
[R2-bgp]peer 4.4.4.4 as-number 100
[R2-bgp]peer 4.4.4.4 connect-interface loop 0
[R2-bgp]peer 4.4.4.4 next-hop-local
[R2-bgp]peer 1.1.1.1 as-number 100
[R2-bgp]peer 1.1.1.1 connect-interface loop 0
[R2-bgp]peer 1.1.1.1 next-hop-local
[R2-bgp]peer 3.3.3.3 as-number 200
[R2-bgp]peer 3.3.3.3 connect-interface loop 0
[R2-bgp]peer 3.3.3.3 ebgp-max-hop 255
[R2-bgp]quit
[R2]ip route-static 3.3.3.3 32 23.1.1.3
[R2]bgp 100
[R2-bgp]network 2.2.2.2 32
[R2-bgp]network 12.1.1.0 24
[R2-bgp]network 23.1.1.0 24
[R2-bgp]network 3.3.3.3 32
[R2-bgp]network 4.4.4.4 32
AR3配置信息
<Huawei>undo terminal monitor
<Huawei>system-view
[Huawei]user-interface console 0
[Huawei-ui-console0]idle-timeout 0 0
[Huawei-ui-console0]sysname R3
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ip add 23.1.1.3 24
[R3-GigabitEthernet0/0/0]undo shutdown
[R3-GigabitEthernet0/0/0]int loop 0
[R3-LoopBack0]ip add 3.3.3.3 32
[R3-LoopBack0]quit
[R3]bgp 200
[R3-bgp]router-id 3.3.3.3
[R3-bgp]peer 2.2.2.2 as-number 100
[R3-bgp]peer 2.2.2.2 connect-interface loop 0
[R3-bgp]peer 2.2.2.2 ebgp-max-hop 255
[R3-bgp]quit
[R3]ip route-static 2.2.2.2 32 23.1.1.2
[R3]bgp 200
[R3-bgp]network 3.3.3.3 32
[R3-bgp]network 23.1.1.0 24
[R3-bgp]quit