STP : -定义 -作用 在提供2层冗余链路的情况下,防止2层数据转发环路的发生; -报文 BPDU - bridge protocol data unit ,桥接 协议 数据 单元 -原理 1.确定交换机的角色 #根交换机 :在一个 LAN 中,有且只有一个根交换机; #非根交换机 :除了根交换机以外,其他的都叫做非根交换机; -原则: 各个交换机之间互相比较:BID(Bridge ID -桥ID) 优先级 + MAC 2个字节 6字节 BID越小越好: 1.首先比较优先级,越小越好;默认值 32768 ; 2.如果优先级相同,比较MAC,越小越好;

	             验证命令:
				      display stp -->查看的是交换机的 BID ;
					  display bridge mac-address ->查看交换机的MAC地址;
	  		   
2.确定端口的角色
       #根端口  :仅存在于非根交换机,有且只有1个,距离根交换机最近;
	   #指定端口:在任何一个网段中,都有,并且只有1个,距离根交换机最近;
	   #非指定端口:其他的所有的端口,都称之为“非指定端口”;
	   
3.确定端口状态
       #down
	   #listening
	   #learning
	   #forwarding : 根端口、指定端口;
	   #blocking :非指定端口;

STP协议中,是如何判断一个路径的距离的? 通过 cost ; #STP 协议对于不同带宽的链路,分配了一个默认的cost;

STP的报文格式 - BPDU :

Root-Switch:该字段包含的根交换机的 BID ;
Cost :  表示的是发送该BPDU的交换机到 根交换机的 距离;
BID  : 表示的是发送该 BPDU 的交换机的名字;
PID :表示的 port-id ,即发送该BPDU的交换机的出端口
      的 ID (端口优先级+端口号)
               端口优先级默认是128		  

STP计时器: forward-delay : 15s max-age : 20s

STP网络的收敛时间: 30s --- 50s


STP配置命令:

#开启/关闭 STP [SW] stp enable --> 开启 STP ,默认是开启的; stp disable --> 关闭 STP 。没有物理环路的环境下, 可以直接关闭的; #配置 交换机的 STP 优先级 [SW] stp priority {value} --> 默认是 32768 , 手动配置的数值必须是4096 的倍数; #配置 STP 的运行模式 : [SW] stp mode { stp | rstp | mstp }

#修改端口的 STP cost ; [SW]interface gi0/0/2 [SW-gi0/0/2] stp cost {value} --> 取值空间1到2亿 #关闭/开启端口下的 STP 功能: [sw]interface gi0/0/2 [sw-gi0/0/2]stp disable -->关闭端口上的 STP 功能; stp enable --> 端口下默认开启了 STP ;


MSTP的配置:

1.首先配置 PC vlan 14 : 192.168.14.0/24 vlan 23 : 192.168.23.0/24 2.其次配置 网络设备 - Switch #在每个设备上创建 VLAN : 14/23 [SW]vlan batch 14 23 -->在每个交换机上批量创建 vlan 14 , 23 ; #配置交换机之间的链路 - Trunk [SW]interface gi0/0/x port link-type trunk port trunk allow-pass vlan all #配置 MSTP (在所有交换机上配置以下命令) * stp mode mstp -> 默认就是 MSTP ; * stp region-configuration region-name HCNP --> 所有的交换机必须保证 具有相同的 region-name ; instance 1 vlan 14 ->创建实例树,并关联 vlan ; instance 2 vlan 23 active region-configuration -> 激活MSTP的配置

#将 SW1 配置为 instance 1 的主根; 同时配置为 instance 2 的备份根; stp instance 1 priority 0 --> 将该设备配置为了 instance 1 的主根; stp instance 2 priority 4096 -> 将该设备配置为了 instance 2 的备份根;

#将 SW2 配置为 instance 2 的主根; 同时配置为 instance 1 的备份根; stp instance 2 priority 0 --> 将该设备配置为了 instance 2 的主根; stp instance 1 priority 4096 -> 将该设备配置为了 instance 1 的备份根;

#验证 MSTP
     display stp brief ->要看清楚你所关注的端口当前属于
	                               那个 instance