配置BGP的基本示例

news/2024/7/16 1:49:55

BGP简介

定义

边界网关协议BGP(Border Gateway Protocol)是一种实现自治系统AS(Autonomous System)之间的路由可达,并选择最佳路由的距离矢量路由协议。早期发布的三个版本分别是BGP-1(RFC1105)、BGP-2(RFC1163)和BGP-3(RFC1267),1994年开始使用BGP-4(RFC1771),2006年之后单播IPv4网络使用的版本是BGP-4(RFC4271),其他网络(如IPv6等)使用的版本是MP-BGP(RFC4760)。

MP-BGP是对BGP-4进行了扩展,来达到在不同网络中应用的目的,BGP-4原有的消息机制和路由机制并没有改变。MP-BGP在IPv6单播网络上的应用称为BGP4+,在IPv4组播网络上的应用称为MBGP(Multicast BGP)。

目的

为方便管理规模不断扩大的网络,网络被分成了不同的自治系统。1982年,外部网关协议EGP(Exterior Gateway Protocol)被用于实现在AS之间动态交换路由信息。但是EGP设计得比较简单,只发布网络可达的路由信息,而不对路由信息进行优选,同时也没有考虑环路避免等问题,很快就无法满足网络管理的要求。

BGP是为取代最初的EGP而设计的另一种外部网关协议。不同于最初的EGP,BGP能够进行路由优选、避免路由环路、更高效率的传递路由和维护大量的路由信息。

虽然BGP用于在AS之间传递路由信息,但并不是所有AS之间传递路由信息都需要运行BGP。比如在数据中心上行的连入Internet的出口上,为了避免Internet海量路由对数据中心内部网络的影响,设备采用静态路由代替BGP与外部网络通信。


组网需求 

如下图所示,需要在所有Switch间运行BGP协议,SwitchA、SwitchB之间建立EBGP连接,SwitchB、SwitchC和SwitchD之间建立IBGP全连接。 

注意:请确保该场景下互联接口的STP处于未使能状态。因为在使能STP的环形网络中,如果用交换机的VLANIF接口构建三层网络,会导致某个端口被阻塞,从而导致三层业务不能正常运行。 


 配置思路 

  • 在SwitchB、SwitchC和SwitchD间配置IBGP连接。
  • 在SwitchA和SwitchB之间配置EBGP连接。

操作步骤 

  • 配置各接口所属的VLAN

# 配置SwitchA。SwitchB、SwitchC和SwitchD的配置与SwitchA类似。

<Huawei>system-view 
[Huawei]sysname SwitchA
[SwitchA]undo stp enable 
[SwitchA]vlan batch 10 50
[SwitchA]interface GigabitEthernet 0/0/1
[SwitchA-GigabitEthernet0/0/1]port link-type trunk 
[SwitchA-GigabitEthernet0/0/1]port trunk allow-pass vlan 10
[SwitchA-GigabitEthernet0/0/1]quit	
[SwitchA]interface GigabitEthernet 0/0/2
[SwitchA-GigabitEthernet0/0/2]port link-type trunk 
[SwitchA-GigabitEthernet0/0/2]port trunk allow-pass vlan 50
[SwitchA-GigabitEthernet0/0/2]quit
  • 配置各VLANIF接口的IP地址

# 配置SwitchA。SwitchB、SwitchC和SwitchD的配置与SwitchA类似。

[SwitchA]interface Vlanif 10
[SwitchA-Vlanif10] ip address 192.168.1.2 24
[SwitchA-Vlanif10]quit	
[SwitchA]interface Vlanif 50
[SwitchA-Vlanif50]ip address 10.1.1.1 16
[SwitchA-Vlanif50]quit
  • 配置IBGP连接

# 配置SwitchB。

[SwitchB]bgp 65009	
[SwitchB-bgp]router-id 172.17.2.2
[SwitchB-bgp]peer 172.16.1.2 as-number 65009	
[SwitchB-bgp]peer 172.16.3.2 as-number 65009
[SwitchB-bgp]quit

# 配置SwitchC。

[SwitchC]bgp 65009
[SwitchC-bgp]router-id 172.17.3.3
[SwitchC-bgp]peer 172.16.3.1 as-number 65009
[SwitchC-bgp]peer 172.16.2.2 as-number 65009
[SwitchC-bgp]quit

# 配置SwitchD。

[SwitchD]bgp 65009
[SwitchD-bgp]rou	
[SwitchD-bgp]router-id 172.17.4.4
[SwitchD-bgp]peer 172.16.1.1 as-number 65009
[SwitchD-bgp]peer 172.16.2.1 as-number 65009
[SwitchD-bgp]quit
  • 配置EBGP

# 配置SwitchA。

[SwitchA]bgp 65008	
[SwitchA-bgp]router-id 172.17.1.1
[SwitchA-bgp]peer 192.168.1.1 as-number 65009
[SwitchA-bgp]quit

# 配置SwitchB。

[SwitchB]bgp 65009
[SwitchB-bgp]peer 192.168.1.2 as-number 65008
[SwitchB-bgp]quit

# 查看BGP对等体的连接状态。

[SwitchB]display bgp peer 

 BGP local router ID : 172.17.2.2
 Local AS number : 65009
 Total number of peers : 3		  Peers in established state : 3

  Peer            V          AS  MsgRcvd  MsgSent  OutQ  Up/Down       State Pre
fRcv

  172.16.1.2      4       65009        5        6     0 00:03:55 Established    
   0
  172.16.3.2      4       65009        7        8     0 00:05:24 Established    
   0
  192.168.1.2     4       65008        2        2     0 00:00:11 Established    
   0

可以看出,SwitchB其它Switch的BGP连接均已建立。

  • 配置SwitchA发布路由10.1.0.0/16

# 配置SwitchA发布路由。

[SwitchA]bgp 65008
[SwitchA-bgp]ipv4-family unicast 
[SwitchA-bgp-af-ipv4]network 10.1.0.0 255.255.0.0
[SwitchA-bgp-af-ipv4]quit
[SwitchA-bgp]quit

# 查看SwitchA路由表信息。

[SwitchA]display bgp routing-table

 BGP Local router ID is 172.17.1.1 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 1
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   10.1.0.0/16        0.0.0.0         0                     0      i

# 查看SwitchB的路由表。

[SwitchB]display bgp routing-table 

 BGP Local router ID is 172.17.2.2 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 1
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   10.1.0.0/16        192.168.1.2     0                     0      65008i

# 查看SwitchC的路由表。

[SwitchC]display bgp routing-table 

 BGP Local router ID is 172.17.3.3 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 1
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

   i  10.1.0.0/16        192.168.1.2     0          100        0      65008i

从路由表可以看出,SwitchC学到了AS65008中的10.1.0.0的路由,但因为下一跳192.168.1.2不可达,所以也不是有效路由。

  • 配置BGP引入直连路由

# 配置SwitchB。

[SwitchB]bgp 65009
[SwitchB-bgp]ipv4-family unicast 
[SwitchB-bgp-af-ipv4]import-route direct 
[SwitchB-bgp-af-ipv4]quit
[SwitchB-bgp]quit

# 查看SwitchA的BGP路由表。

[SwitchA]display bgp routing-table 

 BGP Local router ID is 172.17.1.1 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 4
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>   10.1.0.0/16        0.0.0.0         0                     0      i
 *>   172.16.1.0/24      192.168.1.1     0                     0      65009?
 *>   172.16.3.0/24      192.168.1.1     0                     0      65009?
      192.168.1.0        192.168.1.1     0                     0      65009?

# 查看SwitchC的路由表。

[SwitchC]display bgp routing-table 

 BGP Local router ID is 172.17.3.3 
 Status codes: * - valid, > - best, d - damped,
               h - history,  i - internal, s - suppressed, S - Stale
               Origin : i - IGP, e - EGP, ? - incomplete


 Total Number of Routes: 4
      Network            NextHop        MED        LocPrf    PrefVal Path/Ogn

 *>i  10.1.0.0/16        192.168.1.2     0          100        0      65008i
 *>i  172.16.1.0/24      172.16.3.1      0          100        0      ?
   i  172.16.3.0/24      172.16.3.1      0          100        0      ?
 *>i  192.168.1.0        172.16.3.1      0          100        0      ?

可以看出,到10.1.0.0的路由变为有效路由,下一跳为SwitchA的地址。

# 使用Ping进行验证。

[SwitchC]ping 10.1.1.1
  PING 10.1.1.1: 56  data bytes, press CTRL_C to break
    Reply from 10.1.1.1: bytes=56 Sequence=1 ttl=254 time=140 ms
    Reply from 10.1.1.1: bytes=56 Sequence=2 ttl=254 time=80 ms
    Reply from 10.1.1.1: bytes=56 Sequence=3 ttl=254 time=120 ms
    Reply from 10.1.1.1: bytes=56 Sequence=4 ttl=254 time=60 ms
    Reply from 10.1.1.1: bytes=56 Sequence=5 ttl=254 time=90 ms

  --- 10.1.1.1 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 60/98/140 ms

配置文件 

  • SwitchA的配置文件

#
sysname SwitchA
#
vlan batch 10 50
#
stp disable
#
interface Vlanif10
 ip address 192.168.1.2 255.255.255.0
#
interface Vlanif50
 ip address 10.1.1.1 255.255.0.0
#
interface GigabitEthernet0/0/1
 port link-type trunk
 port trunk allow-pass vlan 10 
#
interface GigabitEthernet0/0/2
 port link-type trunk
 port trunk allow-pass vlan 50 
#
bgp 65008
 router-id 172.17.1.1
 peer 192.168.1.1 as-number 65009
 #
 ipv4-family unicast
  undo synchronization
  network 10.1.0.0 255.255.0.0
  peer 192.168.1.1 enable
#
return
  • SwitchB的配置文件

#
sysname SwitchB
#
vlan batch 10 20 30
#
stp disable
#
interface Vlanif10
 ip address 192.168.1.1 255.255.255.0
#
interface Vlanif20
 ip address 172.16.3.1 255.255.255.0
#
interface Vlanif30
 ip address 172.16.1.1 255.255.255.0
#
interface GigabitEthernet0/0/1
 port link-type trunk
 port trunk allow-pass vlan 10
#
interface GigabitEthernet0/0/2
 port link-type trunk
 port trunk allow-pass vlan 20
#
interface GigabitEthernet0/0/3
 port link-type trunk
 port trunk allow-pass vlan 30
#
bgp 65009
 router-id 172.17.2.2
 peer 172.16.1.2 as-number 65009
 peer 172.16.3.2 as-number 65009
 peer 192.168.1.2 as-number 65008
 #
 ipv4-family unicast
  undo synchronization
  import-route direct
  peer 172.16.1.2 enable
  peer 172.16.3.2 enable 
  peer 192.168.1.2 enable
#
return
  • SwitchC的配置文件

#
sysname SwitchC
#
vlan batch 20 40
#
stp disable
#
interface Vlanif20
 ip address 172.16.3.2 255.255.255.0
#
interface Vlanif40
 ip address 172.16.2.1 255.255.255.0
#
interface GigabitEthernet0/0/1
 port link-type trunk
 port trunk allow-pass vlan 20
#
interface GigabitEthernet0/0/2
 port link-type trunk
 port trunk allow-pass vlan 40
#
bgp 65009
 router-id 172.17.3.3
 peer 172.16.2.2 as-number 65009
 peer 172.16.3.1 as-number 65009
 #
 ipv4-family unicast
  undo synchronization
  peer 172.16.2.2 enable
  peer 172.16.3.1 enable
#
return
  • SwitchD的配置文件

#
sysname SwitchD
#
vlan batch 30 40
#
stp disable
#
interface Vlanif30
 ip address 172.16.1.2 255.255.255.0
#
interface Vlanif40
 ip address 172.16.2.2 255.255.255.0
#
interface GigabitEthernet0/0/1
 port link-type trunk
 port trunk allow-pass vlan 30
#
interface GigabitEthernet0/0/2
 port link-type trunk
 port trunk allow-pass vlan 40
#
bgp 65009
 router-id 172.17.4.4
 peer 172.16.1.1 as-number 65009
 peer 172.16.2.1 as-number 65009
 #
 ipv4-family unicast
  undo synchronization
  peer 172.16.1.1 enable
  peer 172.16.2.1 enable
#
return

http://lihuaxi.xjx100.cn/news/1908026.html

相关文章

使用PE信息查看工具和Beyond Compare文件比较工具排查dll文件版本不对的问题

目录 1、问题说明 2、修改了代码&#xff0c;但安装版本还是有问题 3、使用PE信息查看工具查看音视频库文件&#xff08;二进制&#xff09;的时间戳 4、使用Beyond Compare比较两个库文件的差异 5、找到原因 6、最后 C软件异常排查从入门到精通系列教程&#xff08;专栏…

Flink 状态管理与容错机制(CheckPoint SavePoint)的关系

一、什么是状态 无状态计算的例子&#xff1a; 例如一个加法算子&#xff0c;第一次输入235那么以后我多次数据23的时候得到的结果都是5。得出的结论就是&#xff0c;相同的输入都会得到相同的结果&#xff0c;与次数无关。 有状态计算的例子&#xff1a; 访问量的统计&#x…

cmakelists.txt中install函数/命令

原文链接install — CMake 3.28.1 Documentation install Contents install Synopsis Introduction Signatures Examples Example: Install Targets with Per-Artifact Components Example: Install Targets to Per-Config Destinations Generated Installation Script …

git 杂项

----------------------------------------------------------- 1. Failed to connect to github.com port 443 连接超时 ----------------------------------------------------------- $ git config --global --https.sslVerify "false" 它会在全局配置文件中, 通常…

【MIKE】MIKE河网编辑器操作说明

目录 MIKE河网编辑器说明河网定义河网编辑工具栏河网文件(.nwk11)输入步骤1. 从传统的地图引入底图1.1 底图准备1.2 引入河网底图1.3 输入各河段信息2. 从ARCView .shp文件引入底图MIKE河网编辑器说明 河网编辑器主要功能有两个: ①河网的编辑和参数输人,包括数字化河网及…

【python笔记】并发编程

前言 菜某的笔记总结分享。有错误请指正。 并发编程的意义 并发编程是用来提升代码执行的效率的。 名词理解 进程和线程 我们可以这样理解进程和线程。进程是一个工厂&#xff0c;线程是工厂里的一条流水线。 我们要让我们产品的生产效率提高&#xff0c;我们可以多开工…

[node]Node.js 中REPL简单介绍

[node]Node.js 中REPL简单介绍 什么是REPL为什么使用REPL如何使用REPL 命令REPL模式node的全局内容展示node全局所有模块查看全局模块具体内容其它命令 实践 什么是REPL Node.js REPL(Read Eval Print Loop:交互式解释器) 表示电脑的环境&#xff0c;类似 Windows 系统的终端或…

[网络安全]用户与组管理

一: 用户管理 1. 每个用户拥有不同的操作权限 2. 每个用户拥有唯一一个SID(安全标识符) 用户SID : whoami /user 所有SID: whoami /all 给账户赋权限 实质是给 SID赋权限 用户UID : 500Windows的administrator 的UID 从500开始普通用户从 1000开始 3.账户密…