本次讲解STP(生成树协议)配置方法:当交换机之间有多个VLAN时Trunk线路负载会过重,这时需要设置多个Trunk端口,但这样会形成网络环路。而STP协议便可以解决这个问题。本例配置模型图命令行:SwitchA配置如下:SwitchA#vlandatabaseSwitchA(vlan)#vtpdomaintztSwitchA(vlan)#vtpserverSwitchA(vlan)#vlan2nameVLAN2VLAN2added:Name:VLAN2SwitchA(vlan)#vlan3nameVLAN3VLAN3added:Name:VLAN3SwitchA(vlan)#vlan4nameVLAN4VLAN4added:Name:VLAN4SwitchA(vlan)#exitSwitchA#configureterminalSwitchA(config)#interfacef0/1//配置switchA的f0/1端口为trunk模式,允许所有vlan通过SwitchA(config-if)#switchportmodetrunkSwitchA(config-if)#switchporttrunkallowedvlanallSwitchA(config-if)#exitSwitchA(config)#interfacef0/2//配置switchA的f0/1端口为trunk模式,允许所有vlan通过SwitchA(config-if)#switchportmodetrunkSwitchA(config-if)#switchporttrunkallowedvlanallSwitchA(config-if)#endSwitchA#writeSwitchA#configureterminal//将模型图中switchA对应端口划分到各vlan中SwitchA(config)#interfacef0/4SwitchA(config-if)#switchportmodeaccessSwitchA(config-if)#switchportaccessvlan2SwitchA(config-if)#exitSwitchA(config)#interfacef0/5SwitchA(config-if)#switchportmodeaccessSwitchA(config-if)#switchportaccessvlan3SwitchA(config-if)#exitSwitchA(config)#interfacef0/6SwitchA(config-if)#switchportmodeaccessSwitchA(config-if)#switchportaccessvlan4SwitchA(config-if)#exitSwitchA(config-if)#endSwitchA#writeSwitchA#showvlan//查看vlan信息VLANNameStatusPorts----------------------------------------------------------------------------1defaultactiveFa0/3,Fa0/8,Fa0/9,Fa0/10Fa0/11,Fa0/12,Fa0/13,Fa0/14Fa0/15,Fa0/16,Fa0/17,Fa0/18Fa0/19,Fa0/20,Fa0/21,Fa0/22Fa0/23,Fa0/24,Gig1/1,Gig1/22VLAN2activeFa0/43VLAN3activeFa0/54VLAN4activeFa0/65VLAN5activeFa0/7//在交换机SwitchA设置各VLAN在Trunk端口的STP值SwitchA(config)#interfacef0/1SwitchA(config-if)#spanning-treevlan1port-priority16SwitchA(config-if)#spanning-treevlan2port-priority16SwitchA(config-if)#exitSwitchA(config)#interfacef0/2SwitchA(config-if)#spanning-treevlan3port-priority16SwitchA(config-if)#spanning-treevlan4port-priority16SwitchA(config-if)#endSwitchA#copyrunning-configstartup-configSwitchA配置如下:在交换机SwitchB上配置VTPClient学习VLAN信息并配置VLANTrunkSwitchB#vlandatabaseSwitchB(vlan)#vtpdomaintztSwitchB(vlan)#vtpclientSwitchB(vlan)#exitSwitchB#configureterminalSwitchB(config)#interfacef0/1SwitchB(config-if)#switchportmodetrunkSwitchB(config-if)#switchporttrunkallowedvlanallSwitchB(config-if)#exitSwitchB(config)#interfacef0/2SwitchB(config-if)#switchportmodetrunkSwitchB(config-if)#switchporttrunkallowedvlanallSwitchB(config-if)#exitSwitchB#write在交换机SwitchB把端口归属各相应的VLANSwitchB#configureterminalSwitchB(config)#interfacef0/4SwitchB(config-if)#switchportmodeaccessSwitchB(config-if)#switchportaccessvlan2SwitchB(config-if)#exitSwitchB(config)#interfacef0/5SwitchB(config-if)#switchportmodeaccessSwitchB(config-if)#switchportaccessvlan3SwitchB(config-if)#exitSwitchB(config)#interfacef0/6SwitchB(config-if)#switchportmodeaccessSwitchB(config-if)#switchportaccessvlan4SwitchB(config-if)#endSwitchB#writeSwitchB#showvlanVLANNameStatusPorts----------------------------------------------------------------------------1defaultactiveFa0/3,Fa0/7.Fa0/8,Fa0/9,Fa0/10Fa0/11,Fa0/12,Fa0/13,Fa0/14Fa0/15,Fa0/16,Fa0/17,Fa0/18Fa0/19,Fa0/20,Fa0/21,Fa0/22Fa0/23,Fa0/24,Gig1/1,Gig1/22VLAN2activeFa0/43VLAN3activeFa0/54VLAN4activeFa0/6在交换机SwitchC设置各VLAN在Trunk端口的STP值、SwitchB(config)#interfacef0/1SwitchB(config-if)#spanning-treevlan1port-priority16SwitchB(config-if)#spanning-treevlan2port-priority16SwitchB(config-if)#exitSwitchB(config)#interfacef0/2SwitchB(config-if)#spanning-treevlan3port-priority16SwitchB(config-if)#spanning-treevlan4port-priority16SwitchB(config-if)#endSwitchB#copyrunning-configstartup-config查看配置情况:SwitchA#showinterfacestrunkPortModeEncapsulationStatusNativevlanFa0/1on802.1qtrunking1Fa0/2on802.1qtrunking1PortVlansallowedontrunkFa0/11-1005Fa0/21-1005PortVlansallowedandactiveinmanagementdomainFa0/11,2,3,4,Fa0/21,2,3,4,PortVlansinspanningtreeforwardingstateandnotprunedFa0/11,2Fa0/23,4,注:以上配置完成后重启交换机方可正常运行。本次讲解结束!