华为STP

组网需求

在一个复杂的网络中,网络规划者由于冗余备份的需要,一般都倾向于在设备之间部署多条物理链路,其中一条作主用链路,其他链路作备份。这样就难免会形成环形网络,若网络中存在环路,可能会引起广播风暴和MAC表项被破坏。

网络规划者规划好网络后,可以在网络中部署STP协议预防环路。当网络中存在环路,STP通过阻塞某个端口以达到破除环路的目的。如图14-18所示,当前网络中存在环路,SwitchA、SwitchB、SwitchC和SwitchD都运行STP,通过彼此交互信息发现网络中的环路,并有选择的对某个端口进行阻塞,最终将环形网络结构修剪成无环路的树形网络结构,从而防止报文在环形网络中不断循环,避免设备由于重复接收相同的报文造成处理能力下降。

图14-18  配置STP功能组网图

配置思路

采用以下思路配置STP功能:
  1. 在处于环形网络中的交换设备上配置STP基本功能,包括:
    1. 配置环网中的设备生成树协议工作在STP模式。

    2. 配置根桥和备份根桥设备。

    3. 配置端口的路径开销值,实现将该端口阻塞。

    4. 使能STP,实现破除环路。与PC相连的端口不用参与STP计算,将其设置为边缘端口。

操作步骤

  1. 配置STP基本功能
    1. 配置环网中的设备生成树协议工作在STP模式

      # 配置交换设备SwitchA的STP工作模式。

      <HUAWEI> system-view
      [HUAWEI] sysname SwitchA
      [SwitchA] stp mode stp

      # 配置交换设备SwitchB的STP工作模式。

      <HUAWEI> system-view
      [HUAWEI] sysname SwitchB
      [SwitchB] stp mode stp

      # 配置交换设备SwitchC的STP工作模式。

      <HUAWEI> system-view
      [HUAWEI] sysname SwitchC
      [SwitchC] stp mode stp

      # 配置交换设备SwitchD的STP工作模式。

      <HUAWEI> system-view
      [HUAWEI] sysname SwitchD
      [SwitchD] stp mode stp
    2. 配置根桥和备份根桥设备

      # 配置SwitchA为根桥。

      [SwitchA] stp root primary

      # 配置SwitchD为备份根桥。

      [SwitchD] stp root secondary
    3. 配置端口的路径开销值,实现将该端口阻塞

      • 端口路径开销值取值范围由路径开销计算方法决定,这里选择使用华为计算方法为例,配置将被阻塞端口的路径开销值为20000。

      • 同一网络内所有交换设备的端口路径开销应使用相同的计算方法。

      # 配置SwitchA的端口路径开销计算方法为华为计算方法。

      [SwitchA] stp pathcost-standard legacy

      # 配置SwitchB的端口路径开销计算方法为华为计算方法。

      [SwitchB] stp pathcost-standard legacy

      # 配置SwitchC端口GigabitEthernet1/0/1端口路径开销值为20000。

      [SwitchC] stp pathcost-standard legacy
      [SwitchC] interface gigabitethernet 1/0/1
      [SwitchC-GigabitEthernet1/0/1] stp cost 20000
      [SwitchC-GigabitEthernet1/0/1] quit

      # 配置SwitchD的端口路径开销计算方法为华为计算方法。

      [SwitchD] stp pathcost-standard legacy
    4. 使能STP,实现破除环路

      • 将与PC机相连的端口设置为边缘端口

        # 配置SwitchB端口GigabitEthernet1/0/2为边缘端口。

        [SwitchB] interface gigabitethernet 1/0/2
        [SwitchB-GigabitEthernet1/0/2] stp edged-port enable
        [SwitchB-GigabitEthernet1/0/2] quit

        (可选)配置SwitchB的BPDU保护功能。

        [SwitchB] stp bpdu-protection

        # 配置SwitchC端口GigabitEthernet1/0/2为边缘端口。

        [SwitchC] interface gigabitethernet 1/0/2
        [SwitchC-GigabitEthernet1/0/2] stp edged-port enable
        [SwitchC-GigabitEthernet1/0/2] quit

        (可选)配置SwitchC的BPDU保护功能。

        [SwitchC] stp bpdu-protection
        如果与边缘端口相连的是使能了STP功能的网络设备,配置BPDU保护功能后,如果边缘端口收到BPDU报文,边缘端口将会被shutdown,边缘端口属性不变。
      • 设备全局使能STP

        # 设备SwitchA全局使能STP。

        [SwitchA] stp enable

        # 设备SwitchB全局使能STP。

        [SwitchB] stp enable

        # 设备SwitchC全局使能STP。

        [SwitchC] stp enable

        # 设备SwitchD全局使能STP。

        [SwitchD] stp enable
  2. 验证配置结果

    经过以上配置,在网络计算稳定后,执行以下操作,验证配置结果。

    # 在SwitchA上执行display stp brief命令,查看端口状态和端口的保护类型,结果如下:

    [SwitchA] display stp brief
     MSTID  Port                        Role  STP State     Protection
       0    GigabitEthernet1/0/1        DESI  FORWARDING      NONE
       0    GigabitEthernet1/0/2        DESI  FORWARDING      NONE

    将SwitchA配置为根桥后,与SwitchB、SwitchD相连的端口GigabitEthernet1/0/2和GigabitEthernet1/0/1在生成树计算中被选举为指定端口。

    # 在SwitchB上执行display stp interface gigabitethernet 1/0/1 brief命令,查看端口GigabitEthernet1/0/1状态,结果如下:

    [SwitchB] display stp interface gigabitethernet 1/0/1 brief
     MSTID  Port                        Role  STP State     Protection
       0    GigabitEthernet1/0/1        DESI  FORWARDING      NONE      

    端口GigabitEthernet1/0/1在生成树选举中成为指定端口,处于Forwarding状态。

    # 在SwitchC上执行display stp brief命令,查看端口状态,结果如下:

    [SwitchC] display stp brief
     MSTID  Port                        Role  STP State     Protection
       0    GigabitEthernet1/0/1        ALTE  DISCARDING      NONE     
       0    GigabitEthernet1/0/3        ROOT  FORWARDING      NONE      

    端口GigabitEthernet1/0/3在生成树选举中成为根端口,处于FORWARDING状态。

    端口GigabitEthernet1/0/1在生成树选举中成为Alternate端口,处于DISCARDING状态。

配置文件

  • SwitchA的配置文件

    #
    sysname SwitchA  
    #
    stp mode stp
    stp instance 0 root primary 
    stp pathcost-standard legacy
    #
    return
  • SwitchB的配置文件

    # 
    sysname SwitchB   
    # 
    stp mode stp   
    stp bpdu-protection
    stp pathcost-standard legacy
    #  
    interface GigabitEthernet1/0/2   
     stp edged-port enable 
    #  
    return                    
  • SwitchC的配置文件

    # 
    sysname SwitchC  
    #  
    stp mode stp 
    stp pathcost-standard legacy
    stp bpdu-protection
    #  
    interface GigabitEthernet1/0/1          
     stp instance 0 cost 20000 
    #  
    interface GigabitEthernet1/0/2     
     stp edged-port enable 
    #  
    return           
  • SwitchD的配置文件

    # 
    sysname SwitchD 
    # 
    stp mode stp  
    stp instance 0 root secondary      
    stp pathcost-standard legacy
    #   
    return 
原文地址:https://www.cnblogs.com/victor0/p/13463314.html