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的路由明细


相关推荐
科技小E1 分钟前
口罩佩戴检测算法AI智能分析网关V4工厂/工业等多场景守护公共卫生安全
网络·人工智能
御承扬10 分钟前
从零开始开发纯血鸿蒙应用之网络检测
网络·华为·harmonyos
DevSecOps选型指南9 小时前
2025软件供应链安全最佳实践︱证券DevSecOps下供应链与开源治理实践
网络·安全·web安全·开源·代码审计·软件供应链安全
国科安芯10 小时前
抗辐照MCU在卫星载荷电机控制器中的实践探索
网络·嵌入式硬件·硬件工程·智能硬件·空间计算
EasyDSS11 小时前
国标GB28181设备管理软件EasyGBS远程视频监控方案助力高效安全运营
网络·人工智能
玩转4G物联网11 小时前
零基础玩转物联网-串口转以太网模块如何快速实现与TCP服务器通信
服务器·网络·物联网·网络协议·tcp/ip·http·fs100p
派阿喵搞电子11 小时前
Ubuntu下有关UDP网络通信的指令
linux·服务器·网络
搬码临时工12 小时前
外网访问内网服务器常用的三种简单操作步骤方法,本地搭建网址轻松让公网连接
服务器·网络·智能路由器
Fortinet_CHINA13 小时前
引领AI安全新时代 Accelerate 2025北亚巡展·北京站成功举办
网络·安全
dustcell.13 小时前
Cisco Packer Tracer 综合实验
网络