配置STP、RSTP以及负载均衡

生成树协议是一种二层管理协议,它通过有选择性地阻塞网络冗余链路来达到消除网络二层环路的目的,同时具备链路的备份功能。

每个VLAN都生成一棵树是一种比较直接,而且最简单的解决方法。它能够保证每一个VLAN都不存在环路。但是由于种种原因,以这种方式工作的生成树协议并没有形成标准,而是各个厂商各有一套,尤其是以Cisco的VLAN生成树PVST(Per VLAN Spanning Tree)为代表。

SW1,SW2,SW3同一的配置。  SW1为例

Switch>en
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#hostname SW1

SW1(config)#interface range fastEthernet 0/23-24

SW1(config-if-range)#switchport mode trunk 


SW1(config-if-range)#end

SW1#show interfaces trunk 
Port        Mode         Encapsulation  Status        Native vlan
Fa0/23      on           802.1q         trunking      1
Fa0/24      on           802.1q         trunking      1

Port        Vlans allowed on trunk
Fa0/23      1-1005
Fa0/24      1-1005

Port        Vlans allowed and active in management domain
Fa0/23      1
Fa0/24      1

Port        Vlans in spanning tree forwarding state and not pruned
Fa0/23      none
Fa0/24      none

SW1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.

SW1(config)#vlan 2
SW1(config-vlan)#name caiwu
SW1(config-vlan)#vlan 3
SW1(config-vlan)#name it

SW1(config)#end

SW1#show vlan brief 

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/1, Fa0/2, Fa0/3, Fa0/4
                                                Fa0/5, Fa0/6, Fa0/7, Fa0/8
                                                Fa0/9, Fa0/10, Fa0/11, Fa0/12
                                                Fa0/13, Fa0/14, Fa0/15, Fa0/16
                                                Fa0/17, Fa0/18, Fa0/19, Fa0/20
                                                Fa0/21, Fa0/22, Gig0/1, Gig0/2
2    caiwu                            active    
3    it                               active    
1002 fddi-default                     active    
1003 token-ring-default               active    
1004 fddinet-default                  active    
1005 trnet-default 

SW3 划分VLAN 配置

SW3#conf t
Enter configuration commands, one per line.  End with CNTL/Z.

SW3(config)#interface range fastEthernet 0/1-2

SW3(config-if-range)#switchport mode  access 

SW3(config-if-range)#switchport access vlan 2

SW3(config-if-range)#interface range fastEthernet 0/3-4

SW3(config-if-range)#switchport mode  access 

SW3(config-if-range)#switchport access vlan 3
SW3(config-if-range)#end

SW3#show vlan brief 

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/5, Fa0/6, Fa0/7, Fa0/8
                                                Fa0/9, Fa0/10, Fa0/11, Fa0/12
                                                Fa0/13, Fa0/14, Fa0/15, Fa0/16
                                                Fa0/17, Fa0/18, Fa0/19, Fa0/20
                                                Fa0/21, Fa0/22, Gig0/1, Gig0/2
2    caiwu                            active    Fa0/1, Fa0/2
3    it                               active    Fa0/3, Fa0/4
1002 fddi-default                     active    
1003 token-ring-default               active    
1004 fddinet-default                  active    
1005 trnet-default                    active    
SW3#

查看 

BID:优先级+MAC (MAC地址数字越小,为根桥)

SW1

SW1#show version 

63488K bytes of flash-simulated non-volatile configuration memory.
Base ethernet MAC Address       : 0001.9766.27A9
Motherboard assembly number     : 73-9832-06
Power supply part number        : 341-0097-02
Motherboard serial number       : FOC103248MJ
Power supply serial number      : DCA102133JA
Model revision number           : B0
Motherboard revision number     : C0
Model number                    : WS-C2960-24TT
System serial number            : FOC1033Z1EY



SW2

SW2#show version 

63488K bytes of flash-simulated non-volatile configuration memory.
Base ethernet MAC Address       : 0003.E44D.7A96
Motherboard assembly number     : 73-9832-06
Power supply part number        : 341-0097-02
Motherboard serial number       : FOC103248MJ
Power supply serial number      : DCA102133JA
Model revision number           : B0
Motherboard revision number     : C0
Model number                    : WS-C2960-24TT
System serial number            : FOC1033Z1EY



SW3

SW3#show version 
63488K bytes of flash-simulated non-volatile configuration memory.
Base ethernet MAC Address       : 00D0.97CD.098A
Motherboard assembly number     : 73-9832-06
Power supply part number        : 341-0097-02
Motherboard serial number       : FOC103248MJ
Power supply serial number      : DCA102133JA
Model revision number           : B0
Motherboard revision number     : C0
Model number                    : WS-C2960-24TT
System serial number            : FOC1033Z1EY

SW1

SW1#show spanning-tree 
VLAN0001
  Spanning tree enabled protocol ieee
  Root ID    Priority    32769
             Address     0001.9766.27A9
             This bridge is the root
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     0001.9766.27A9
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/23           Desg FWD 19        128.23   P2p
Fa0/24           Desg FWD 19        128.24   P2p

VLAN0002
  Spanning tree enabled protocol ieee
  Root ID    Priority    32770
             Address     0001.9766.27A9
             This bridge is the root
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32770  (priority 32768 sys-id-ext 2)
             Address     0001.9766.27A9
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/23           Desg FWD 19        128.23   P2p
Fa0/24           Desg FWD 19        128.24   P2p

VLAN0003
  Spanning tree enabled protocol ieee
  Root ID    Priority    32771
             Address     0001.9766.27A9
             This bridge is the root
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32771  (priority 32768 sys-id-ext 3)
             Address     0001.9766.27A9
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/23           Desg FWD 19        128.23   P2p
Fa0/24           Desg FWD 19        128.24   P2p

SW1 SW2 SW3 配置快速STP

SW1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
SW1(config)#sp
SW1(config)#spanning-tree mode ?
  pvst        Per-Vlan spanning tree mode
  rapid-pvst  Per-Vlan rapid spanning tree mode

SW1(config)#spanning-tree mode rapid-pvst 

根 负载均衡 配置。  默认(4096)倍数     primary -4096-4096  ...   secondary -4096

SW1成为VLAN2的根,VLAN3的备份根      

SW2成为VLAN3的根,  VLAB2的备份根      

SW1

SW1(config)#spanning-tree vlan 2 priority ?
  <0-61440>  bridge priority in increments of 4096

#可以使用思科的宏命令
SW1(config)#spanning-tree vlan 2 root primary 

SW1(config)#spanning-tree vlan 3 root secondary 

SW1#show running-config 
Building configuration...

Current configuration : 1197 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname SW1
!
!
!
!
!
spanning-tree mode rapid-pvst
spanning-tree extend system-id
spanning-tree vlan 2 priority 24576
spanning-tree vlan 3 priority 28672
!
interface FastEthernet0/1
!

SW2

SW2>en
SW2#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
 
SW2(config)#spanning-tree vlan 3 root ?
  primary    Configure this switch as primary root for this spanning tree

#相反
SW2(config)#spanning-tree vlan 3 root primary 

SW2(config)#spanning-tree vlan 2 root secondary 

SW2#show running-config 
Building configuration...

Current configuration : 1197 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname SW2
!
!
!
!
!
spanning-tree mode rapid-pvst
spanning-tree extend system-id
spanning-tree vlan 3 priority 24576
spanning-tree vlan 2 priority 28672

查看是否配置正确

SW1

SW1# show spanning-tree 
VLAN0001
  Spanning tree enabled protocol rstp
  Root ID    Priority    32769
             Address     0001.9766.27A9
             This bridge is the root
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     0001.9766.27A9
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/23           Desg FWD 19        128.23   P2p
Fa0/24           Desg FWD 19        128.24   P2p

VLAN0002
  Spanning tree enabled protocol rstp
  Root ID    Priority    24578
             Address     0001.9766.27A9
             This bridge is the root
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    24578  (priority 24576 sys-id-ext 2)
             Address     0001.9766.27A9
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/23           Desg FWD 19        128.23   P2p
Fa0/24           Desg FWD 19        128.24   P2p

VLAN0003
  Spanning tree enabled protocol rstp
  Root ID    Priority    24579
             Address     0003.E44D.7A96
             Cost        19
             Port        23(FastEthernet0/23)
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    28675  (priority 28672 sys-id-ext 3)
             Address     0001.9766.27A9
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/23           Root FWD 19        128.23   P2p
Fa0/24           Desg FWD 19        128.24   P2p

SW2

SW2# show spanning-tree 
VLAN0001
  Spanning tree enabled protocol rstp
  Root ID    Priority    32769
             Address     0001.9766.27A9
             Cost        19
             Port        23(FastEthernet0/23)
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32769  (priority 32768 sys-id-ext 1)
             Address     0003.E44D.7A96
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/23           Root FWD 19        128.23   P2p
Fa0/24           Desg FWD 19        128.24   P2p

VLAN0002
  Spanning tree enabled protocol rstp
  Root ID    Priority    24578
             Address     0001.9766.27A9
             Cost        19
             Port        23(FastEthernet0/23)
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    28674  (priority 28672 sys-id-ext 2)
             Address     0003.E44D.7A96
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/23           Root FWD 19        128.23   P2p
Fa0/24           Desg FWD 19        128.24   P2p

VLAN0003
  Spanning tree enabled protocol rstp
  Root ID    Priority    24579
             Address     0003.E44D.7A96
             This bridge is the root
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    24579  (priority 24576 sys-id-ext 3)
             Address     0003.E44D.7A96
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/23           Desg FWD 19        128.23   P2p
Fa0/24           Desg FWD 19        128.24   P2p
原文地址:https://www.cnblogs.com/peter1007/p/9404885.html