BGP基本配置

一、知识补充

1、BGP

BGP是Border Gateway Protocol(边界网关协议)的缩写。它是用于在互联网中交换路由信息的一种协议。BGP被广泛应用于大规模的自治系统(AS)之间,用于实现跨网络的路由选择和交换。

BGP的主要功能是在不同的自治系统之间传递路由信息,帮助确定最佳的路径来转发数据包。它使用一系列的路由策略和属性来选择和优化路由,以确保数据能够有效地从源地址到目的地址进行传输。

BGP协议具有以下特点:

  1. 可靠性:BGP通过使用TCP协议建立可靠的连接来交换路由信息,并确保路由的稳定性和可达性。
  2. 可扩展性:BGP支持大规模网络的路由交换,能够处理成千上万个路由器和自治系统之间的复杂路由关系。
  3. 灵活性:BGP允许网络管理员根据自己的需求配置路由策略,以实现特定的路由选择和控制机制。
  4. 多路径选择:BGP可以同时维护多条到达相同目的地的路由路径,并根据各种属性选择最佳路径。

2、IBGP水平分割原则

IBGP水平分割原则

在AS内部,也有可能环路的

在R1、R2、R3、R4内部运行IBGP协议,R1将1.1.1.1传递给R2,R2传递给R3,R3传递R4,R4传递给R1,这样在AS100内部就形成了环路。

AS内部防环

设计了IBGP的水平分割原则,一个路由器从它的IBGP邻居学习到的路由,不会再传递给下一个IBGP邻居

R1通过EBGP学习到了RA的路由,R2通过IBGP学习到了R1的路由,但是R2不能把从R1学到的路由传递给R3。因为R1、R2、R3在同一个AS内,基于IBGP水平分割原则:一个路由器从它学到的IBGP邻居学到的路由,不能再传给下一个IBGP邻居。IBGP水平分割在AS内虽然防止了环路,但是带来新问题,就是路由无法传递

一般把边界路由器配置成路由反射器,以防止BGP路由黑洞,防止水平分割

二、配置需求及拓扑图

  • loopback 0地址为x.x.x.x/32(x为设备号)
  • R2、R3间运行OSPF协议,进程号为1,归属区域0,需要发布loopback地址。
  • R2、R3间部署IBGP,AS号为100,使用Loopback接口建立邻居关系。
  • R1和R2间运行EBGP,R1使用AS号为200,R2的AS号为100,使用互联接口建立邻居关系
  • R3和R4间运行EBGP,R4使用AS号为300,R3的AS号为100,使用互联接口建立邻居关系
  • 实现全网互通

三、配置步骤

1、OSPF配置

R2

tex 复制代码
R2(config)#router ospf 1
R2(config-router)#router-id 2.2.2.2
Change router-id and update OSPF process! [yes/no]:y 
R2(config-router)#network 102.1.1.0 0.0.0.255 area 0
R2(config-router)#network 2.2.2.2 0.0.0.0 area 0
R2(config-router)#exit

R3

tex 复制代码
R3(config)#router ospf 1 
R3(config-router)#router-id 3.3.3.3    
Change router-id and update OSPF process! [yes/no]:y
R3(config-router)#network 3.3.3.3 0.0.0.0 area 0
R3(config-router)#network 102.1.1.0 0.0.0.255 area 0
R3(config-router)#exit
验证-查看邻居关系的建立

2、BGP配置

R1

tex 复制代码
R1(config)#router bgp 200
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#neighbor 101.1.1.2 remote-as 100       
R1(config-router)#exit

R3

tex 复制代码
R2(config)#router bgp 100
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#neighbor 101.1.1.1 remote-as 200
R2(config-router)#neighbor 3.3.3.3 remote-as 100
R2(config-router)#neighbor 3.3.3.3 update-source loopback 0
R2(config-router)#exit

R3

tex 复制代码
R3(config)#router bgp 100
R3(config-router)#bgp router-id 3.3.3.3
R3(config-router)#neighbor 103.1.1.2 remote-as 300
R3(config-router)#neighbor 2.2.2.2 remote-as 100
R3(config-router)#neighbor 2.2.2.2 update-source loopback 0
R3(config-router)#exit

R4

tex 复制代码
R4(config)#router bgp 300
R4(config-router)#bgp router-id 4.4.4.4
R4(config-router)#neighbor 103.1.1.1 remote-as 100
R4(config-router)#exit
验证-R2上查看BGP的邻居

3、路由引入

宣告网段的两种方式

  • BGP中引入直连路由
  • BGP中Network宣告接口

这里使用引入直连路由

R1

tex 复制代码
R1(config)#router bgp 200 
R1(config-router)#redistribute connected 
R1(config-router)#exit

R2

tex 复制代码
R2(config)#router bgp 100
R2(config-router)#redistribute connected 
R2(config-router)#exit

R3

tex 复制代码
R3(config)#router bgp 100 
R3(config-router)#redistribute connected 
R3(config-router)#exit

R4

tex 复制代码
R4(config)#router bgp 300 
R4(config-router)#redistribute connected 
R4(config-router)#exit
验证-在R1上查看BGP路由明细
验证-在R4上查看BGP路由明细

4、最后分析

可以发现,R1学习不到R3的loopback地址,R4学习不到R2的loopback地址,是因为BGP的水平分隔的问题。可以将OSPF路由引入到BGP中来解决这个问题

R2

tex 复制代码
R2(config)#router bgp 100
R2(config-router)#redistribute ospf 1
R2(config-router)#exit

R3

tex 复制代码
R3(config)#router bgp 100
R3(config-router)#redistribute ospf 1
R3(config-router)#exit
验证-在R1和R4上查看BGP的路由明细


相关推荐
HavenlonLabs1 小时前
Havenlon 对抗性完整(十七):安全不是“防住攻击”,而是控制失败方式
网络·人工智能·架构·安全威胁分析·安全架构·havenlon
fei_sun2 小时前
路径MTU发现
linux·运维·网络
tachibana24 小时前
hot100 回文链表(234)
java·网络·数据结构·leetcode·链表
从零开始的代码生活_4 小时前
NAT、代理服务与内网穿透详解
linux·服务器·网络·c++·http·智能路由器
云栖梦泽在4 小时前
Claude Code / Codex 使用卡顿怎么办?AI 编程 Agent 连接失败与网络排查思路
网络·人工智能·网络协议·chatgpt·性能优化
Jeremy_WW5 小时前
QSFP-DD MSA Hardware协议解读(二)
网络·模块测试·智能硬件
深盾科技_Virbox5 小时前
加密狗授权能力选型:从授权模型到全生命周期管理
java·网络·数据库
运维管理5 小时前
H3C SecPath W2000-G[AK]系列Web应用防火墙 典型配置举例(E6711 E6712 E6713)-6W108-H3C 官方配置
服务器·网络·php
tuddy7894646 小时前
Privazer 源码级避坑指南:从编译到部署的深度解析
网络·copilot
懒鸟一枚6 小时前
Linux 系统 Service 服务配置详解
linux·服务器·网络