配置BGP的基本示例

2023-12-21 22:11:24

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

文章来源:https://blog.csdn.net/2301_77081516/article/details/135139093
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。