stprstppvst
MDstable
NoteSnippetChecklistPlaybook
Spanning Tree Protocol — STP / RSTP / PVST+
Comprendre et configurer STP, RSTP, PVST+ et les protections PortFast/BPDU Guard
snippetintermediate 2025-05-14 6 min read
stprstppvstspanning-treeciscoportfastbpdu-guardloop
Concepts fondamentaux
STP 802 prvient les boucles L2 en bloquant des ports redondantsRSTP 802 convergence rapide < vs 30-50s pour STP classiquePVST Per-VLAN Spanning Tree Cisco une instance STP par VLANRapid PVST RSTP PVST recommand sur Cisco moderneMSTP 802 Multiple STP regrouper plusieurs VLANs par instancelection Root BridgeLe switch avec le Bridge ID priorit MAC le plus bas devient RootPriorit par dfaut 32768 ; incrments de 4096En pratique configurer manuellement la priorit du rootRles des portsRoot Port RP meilleur chemin vers le Root Bridge 1 par switchDesignated Port DP port actif sur chaque segment forwardingBlocked/Alternate port bloqu pour viter les bouclesBackup Port RSTP backup dun Designated sur le mme segmenttats des ports STP classique Disabled Blocking Listening Learning Forwardingtats RSTP Discarding Learning Forwarding
Configuration Cisco — STP de base
Vérifier l'état STP actuel
text
Variables
{{VLAN_ID}}
show spanning-treeshow spanning-tree vlan {{VLAN_ID}}show spanning-tree summaryshow spanning-tree detail
Choisir le mode STP
text
conf t! Rapid PVST+ (recommandé — défaut sur IOS moderne)spanning-tree mode rapid-pvst! PVST+ classique (compatibilité anciens équipements)spanning-tree mode pvst! MSTPspanning-tree mode mst
Configurer le Root Bridge
text
conf t! Méthode 1 : forcer la priorité manuellement (multiple de 4096)spanning-tree vlan 10 priority 4096 ! Root primairespanning-tree vlan 10 priority 8192 ! Root secondaire! Méthode 2 : macro Cisco (calcule automatiquement la priorité optimale)spanning-tree vlan 10 root primaryspanning-tree vlan 10 root secondary! Pour plusieurs VLANs d'un coupspanning-tree vlan 10,20,30 root primaryspanning-tree vlan 40,50,60 root secondary! Vérifiershow spanning-tree vlan 10 | include Root
Diameter et hello timers
text
conf t! Modifier les timers (seulement sur le Root Bridge !)spanning-tree vlan 10 hello-time 2 ! défaut = 2sspanning-tree vlan 10 forward-time 15 ! défaut = 15s (listening+learning)spanning-tree vlan 10 max-age 20 ! défaut = 20s! En Rapid PVST+, les timers sont négociés automatiquement — ne pas modifier
PortFast
text
! Activer sur un port access individuel (postes, imprimantes, serveurs)! → passe directement en Forwarding sans attendre la convergence STPconf tinterface GigabitEthernet0/1spanning-tree portfast! Activer globalement sur TOUS les ports access (attention : pas sur les trunks)conf tspanning-tree portfast default! Désactiver PortFast sur un trunk (si portfast default est activé globalement)interface GigabitEthernet0/24spanning-tree portfast disable! Vérifiershow spanning-tree interface GigabitEthernet0/1 portfastshow running-config | include portfast
BPDU Guard
text
! BPDU Guard : si un BPDU est reçu sur un port PortFast → err-disable immédiat! Empêche qu'un switch non autorisé soit branché sur un port access! Activer sur une interface spécifiqueconf tinterface GigabitEthernet0/1spanning-tree bpduguard enable! Activer globalement sur tous les ports PortFastconf tspanning-tree portfast bpduguard default! Récupérer un port en err-disableinterface GigabitEthernet0/1shutdownno shutdown! Récupération automatique (optionnel)conf terrdisable recovery cause bpduguarderrdisable recovery interval 300 ! secondes! Vérifier les ports err-disabledshow interfaces status err-disabledshow errdisable recovery
BPDU Filter
text
! BPDU Filter : supprime l'envoi ET la réception de BPDUs! ATTENTION : dangereux — peut créer des boucles. Utiliser avec précaution.! Sur une interface (bloque totalement les BPDUs)interface GigabitEthernet0/1spanning-tree bpdufilter enable! Globalement (seulement sur ports PortFast — si BPDU reçu, PortFast désactivé)spanning-tree portfast bpdufilter default
Root Guard
text
Variables
{{VLAN_ID}}
! Root Guard : empêche un port de devenir Root Port! → si un BPDU supérieur est reçu, le port passe en root-inconsistent (bloqué)! Placer sur les ports Designated vers les switchs "inférieurs" (accès, distribution)conf tinterface GigabitEthernet0/24spanning-tree guard root! Vérifier les ports inconsistantsshow spanning-tree inconsistentportsshow spanning-tree vlan {{VLAN_ID}} inconsistentports
Loop Guard
text
! Loop Guard : si un port Root/Alternate cesse de recevoir des BPDUs! → passe en loop-inconsistent au lieu de Forwarding (évite la boucle)! Complémentaire de Root Guard — activer sur les ports non-Designatedconf t! Sur une interfaceinterface GigabitEthernet0/1spanning-tree guard loop! Globalementspanning-tree loopguard default! Vérifiershow spanning-tree detail | include loop
PVST+ — Équilibrage de charge par VLAN
text
! Stratégie : SW-CORE-1 = Root pour VLANs pairs, SW-CORE-2 = Root pour VLANs impairs! → utilise les deux liens trunk simultanément! Sur SW-CORE-1conf tspanning-tree vlan 10,30,50 root primaryspanning-tree vlan 20,40,60 root secondary! Sur SW-CORE-2conf tspanning-tree vlan 20,40,60 root primaryspanning-tree vlan 10,30,50 root secondary
Vérifications complètes
text
Variables
{{VLAN_ID}}
! Vue globale de toutes les instances STPshow spanning-tree summary! Détail complet d'une instanceshow spanning-tree vlan {{VLAN_ID}} detail! État des ports (roles, states, cost)show spanning-tree vlan {{VLAN_ID}}! Ports en état inconsistant (Root Guard, Loop Guard)show spanning-tree inconsistentports! Compteurs BPDU sur une interfaceshow spanning-tree interface GigabitEthernet0/1 detail! Debug (à utiliser avec précaution en prod)debug spanning-tree eventsdebug spanning-tree bpdu
Interprétation de show spanning-tree
VLAN0010Spanning tree enabled protocol rstpRoot ID Priority 4106 4096 VLAN IDAddress aabbcc000100This bridge is the root ce switch EST le rootHello Time 2 sec Max Age 20 sec Forward Delay 15 secBridge ID Priority 4106Address aabbcc000100Interface Role Sts Cost PrioNbr Type------------------- ---- --- --------- -------- ----Gi0/1 Desg FWD 4 1281 P2pGi0/2 Desg FWD 4 1282 P2pGi0/3 Root FWD 4 1283 P2p Root PortGi0/4 Altn BLK 4 1284 P2p Bloqu
💡 Tip —
Activer BPDU Guard sur tous les ports access avec spanning-tree portfast bpduguard default — c'est la protection la plus simple et la plus efficace contre une boucle L2 involontaire. Si quelqu'un branche un switch non managé sur un port access, le port passe immédiatement en err-disable au lieu de propager une boucle sur tout le réseau.
OPS·BRAIN v1.027 notes · Networklocal