{"id":958,"date":"2011-09-07T22:41:00","date_gmt":"2011-09-07T14:41:00","guid":{"rendered":"http:\/\/note.systw.net\/note\/?p=958"},"modified":"2023-11-07T22:46:24","modified_gmt":"2023-11-07T14:46:24","slug":"cisco-stp-guard","status":"publish","type":"post","link":"https:\/\/systw.net\/note\/archives\/958","title":{"rendered":"Cisco STP Guard"},"content":{"rendered":"\n<p>STP guard<\/p>\n\n\n\n<p><br><strong>\u9632\u6b62\u672a\u8a31\u53ef\u7684BPDU<\/strong><br>\u91cd\u8981\u6027<br>\u3000\u7576&#8221;foreign or rogue&#8221; switch(\u672a\u7d93\u6388\u6b0a\u7684\u4ea4\u63db\u8a2d\u5099) is connected to the STP network<br>\u3000\u8a72switch\u53ef\u80fd\u6703\u8b8a\u6210root bridge,\u800c\u9020\u6210\u672a\u9810\u671f\u7684stp\u62d3\u6a38,\u4f7f\u7db2\u8def\u767c\u751f\u8b8a\u52d5<br>\u907f\u514d\u65b9\u6cd5\u4e3b\u8981\u6709\u4ee5\u4e0b\u5169\u7a2e:<br>\u3000Root Guard<br>\u3000BPDU Guard<\/p>\n\n\n\n<p><strong>\u9632\u6b62sudden loss of BPDUs<\/strong><br>\u91cd\u8981\u6027:\u6c92\u6709BPDU\u53ef\u80fd\u6703\u8b93\u8f49\u8b8aport\u72c0\u614b\u6642\u8aa4\u5224,\u800c\u5f62\u6210LOOP<br>\u907f\u514d\u65b9\u6cd5\u6709\u4ee5\u4e0b\u5169\u7a2e:<br>\u3000LOOP GUARD<br>\u3000UDLD<\/p>\n\n\n\n<p><strong>\u505c\u6b62\u8655\u7406BPDU<\/strong><br>\u65b9\u6cd5\u70babpdu filtering<\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..<\/p>\n\n\n\n<p><strong>Root Guard<\/strong><br>\u4e0d\u5141\u8a31designated port\u51fa\u73fe\u65b0\u7684root bridge<br>If another switch advertises a superior BPDU, or one with a better bridge ID on &#8220;Root Guard port&#8221;<br>the local switch will \u8996\u70ba\u7570\u5e38<\/p>\n\n\n\n<p><br>\u767c\u73fe\u7570\u5e38\u6642<br>\u7576\u67d0\u500bdesignated port\u767c\u73feswitch\u8b8a\u6210root bridge,\u4f5c\u696d\u5982\u4e0b<br>1. the port that receive superior BPDU will be kept in the&nbsp;<strong>root-inconsistent STP state<\/strong><br>2.<strong>&nbsp;No data can be sent or received<\/strong>&nbsp;in that state, but the switch&nbsp;<strong>can listen<\/strong>&nbsp;to BPDUs received on the port to detect a new root advertising itself<br>\u7576\u767c\u751f\u7570\u5e38\u6642,log\u5927\u81f4\u5982\u4e0b<br>%SPANTREE-2-ROOTGUARDBLOCK: Port 1\/1 tried to become non-designated in VLAN 2. Moved to root-inconsistent state<br>ps:<br>Root Guard&nbsp;<strong>affects the entire port<\/strong>&nbsp;so that a root bridge never can be allowed on any VLAN on the port.<br>When a superior BPDU is heard on the port, the entire port, in effect,&nbsp;<strong>becomes blocked<\/strong><\/p>\n\n\n\n<p>\u6062\u5fa9\u6b63\u5e38\u6642<br>When the superior BPDUs no longer are received, the port is cycled through the normal STP states to return to normal use<br>ps:\u9810\u8a2d3\u500bhello-timer\u5468\u671f(6\u79d2)\u6c92\u5728\u6536\u5230\u5247\u6062\u5fa9<\/p>\n\n\n\n<p>enable Root Guard<br><strong>Switch(config-if)# spanning-tree guard root<\/strong><br>by default, it is disabled on all switch ports<br>\u5efa\u8b70\u4f7f\u7528\u7684\u4ecb\u9762:never expect to find the root bridge for a VLAN<\/p>\n\n\n\n<p>display about root-inconsistent state<br><strong># show spanning-tree inconsistentports<\/strong><\/p>\n\n\n\n<p>Look for detailed reasons for inconsistencies.<br><strong># show spanning-tree interface &lt; interface &gt; [detail]<\/strong><\/p>\n\n\n\n<p><br>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<\/p>\n\n\n\n<p><strong>bpdu Guard<\/strong><br>\u9632\u6b62portfast\u4ecb\u9762\u4e0b\u6536\u5230bpdu<br>ps:<br>\u5728portfast\u4ecb\u9762\u4e0b\u4e00\u822c\u90fd\u662f\u63a5\u5de5\u4f5c\u7ad9,\u6b63\u5e38\u60c5\u6cc1\u4e0b\u4e0d\u6703\u6536\u5230\u4efb\u4f55bpdu<\/p>\n\n\n\n<p><br>Suppose that a switch is connected by mistake to a port where PortFast is enabled.<br>\u53ef\u80fd\u7684\u5371\u5bb3\u6709\u4ee5\u4e0b<br>1. Now there is a potential for a<strong>&nbsp;bridging loop to form<\/strong>.<br>2. the newly connected device to advertise itself and&nbsp;<strong>become the new root bridge<\/strong><\/p>\n\n\n\n<p><strong>\u767c\u751f\u7570\u5e38\u6642(bpdu guard\u4ecb\u9762\u6536\u5230bpdu\u6642)<\/strong><br>If&nbsp;<strong>any BPDU<\/strong>&nbsp;received on a port where BPDU Guard is enabled, that port immediately is put into the&nbsp;<strong>errdisable state<\/strong><br>ps:<br>\u6062\u5fa9\u6b63\u5e38\u6642<br>bpdu guard\u4ecb\u9762\u4e0d\u518d\u6536\u5230bpdu\u6642,the port still remains in the errdisable state<\/p>\n\n\n\n<p><br><strong>\u53ef\u9694\u96e2loop\u554f\u984c,\u4f46\u8ff4\u5708\u4ecd\u5728<\/strong><br>Naturally, BPDU Guard<strong>&nbsp;does not prevent a bridging loop<\/strong>&nbsp;from forming if an Ethernet hub<br>is connected to the PortFast port. This is because a hub doesn&#8217;t transmit BPDUs itself<br>ps:<br>a loop can be detected only in a finite amount of time-the length of time required to move the port through the normal STP state<\/p>\n\n\n\n<p>\u5c07\u6240\u6709portfast\u4ecb\u9762\u555f\u7528bpdu Guard<br><strong>Switch(config)# spanning-tree portfast bpduguard default<\/strong><br>By default, BPDU Guard is disabled<br>\u5efa\u8b70\u5728\u6240\u6709STP PortFast\u4ecb\u9762\u555f\u7528<br>never should enable BPDU Guard on any switch uplink where the root bridge is located<br>ps:<br>enable bpdu Guard on a per-port basis<br><strong>Switch(config-if)# [no] spanning-tree bpduguard enable<\/strong><\/p>\n\n\n\n<p>Display the global BPDU Guard status<br><strong># show spanning-tree summary [total]<\/strong><\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<\/p>\n\n\n\n<p><br><strong>Loop Guard<\/strong><br>keeps track of the BPDU activity on nondesignated ports(\u907f\u514dBloack Port\u6210\u70baForwarding status\u800c\u5c0e\u81f4Loop)<br>\u53ea\u904b\u4f5c\u5728nondesignated role(root port,block port)<\/p>\n\n\n\n<p>\u7576blocking port\u6c92\u6536\u5230bpdu\u4e00\u76f4\u5230maxage timer\u5f8c,\u6703\u8a8d\u70ba\u6c92\u6709\u9023\u63a5\u5230stp\u8a2d\u5099,\u56e0\u6b64\u5c31\u6703\u96e2\u958bblocking status,\u4e26\u6839\u64dastp\u898f\u5247\u6703\u8f49\u8b8a\u70baforwarding status<br>\u7576\u9023\u63a5\u8a2d\u5099\u70ba<br>\u3000\u958b\u6a5f\u7684pc:\u53ef\u6b63\u5e38\u50b3\u9001\u6d41\u91cf\u3000<br>\u3000\u672a\u50b3\u9001bpdu\u4e4bswitch:\u53ef\u50b3\u8f38\u6d41\u91cf\u56e0\u6b64\u5f62\u6210loop<\/p>\n\n\n\n<p>\u767c\u751f\u7570\u5e38\u6642(BPDUs go missing and link is up)<br>Loop Guard moves the port into the<strong>&nbsp;loop-inconsistent state<\/strong><br>The port is effectively&nbsp;<strong>blocking<\/strong>&nbsp;at this point to prevent a loop from forming and to keep it in the nondesignated role<br>ps: blocking action is taken on a per-VLAN basis ,so Loop Guard&nbsp;<strong>doesn&#8217;t block the entire port<\/strong><\/p>\n\n\n\n<p>\u6062\u5fa9\u6b63\u5e38\u6642(BPDUs are received on the port again and link is up)<br>Loop Guard allows the port to move through the&nbsp;<strong>normal STP states<\/strong>&nbsp;and become active<\/p>\n\n\n\n<p>enable Loop Guard as a global default<br><strong>Switch(config)# spanning-tree loopguard default<\/strong><br>ps:<br>enable Loop Guard on a specific switch port<br><strong>Switch(config-if)# [no] spanning-tree guard loop<\/strong><br>By default, Loop Guard is disabled<br>ps:<br>(config-if)#switch mode trunk\u4e0d\u6703\u5e72\u64feloop guard<br>ps:<br>Access ports\u4e0d\u6703\u6536\u5230BPDUs,\u82e5LoopGuard\u8a2d\u5728access ports,\u5247\u6703\u4e00\u76f4\u4fdd\u6301Loop Inconsistent mode\u4e26block the port<\/p>\n\n\n\n<p>Display the Loop Guard states.<br><strong># show spanning-tree summary<\/strong><\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;..<\/p>\n\n\n\n<p><br><strong>UDLD(Unidirectional Link Detection)<\/strong><br>interactively monitors a port to see whether the link is truly&nbsp;<strong>bidirectional<\/strong><br>ps:It is recommended that it be used with the &#8220;loop guard&#8221; feature<\/p>\n\n\n\n<p><strong>unidirectional link\u554f\u984c<\/strong><br>if just one side of the link (receive or transmit) had an odd failure, such as malfunctioning transmit circuitry in a GBIC or SFP modules?<br>In some cases, the two switches still might see a functional bidirectional link, although traffic actually would be delivered in only one direction. This is known as a unidirectional link<br>ex:switch1\u53ef\u628apacket\u50b3\u7d66neighbor switch2,\u4f46switch2\u50b3\u7684packet\u7121\u6cd5\u88abswitch1\u6536\u5230&nbsp;<br>ps:<br>Twisted-pair or copper media does not suffer from the physical layer conditions that allow a unidirectional link to form<br>ps:<br>\u6b64\u60c5\u6cc1\u767c\u751f\u6642,\u5728\u5169\u908a\u4f7f\u7528show cdp\u6703\u767c\u73fe,\u53ea\u6709\u4e00\u908a\u770b\u7684\u5230\u5c0d\u65b9<\/p>\n\n\n\n<p><strong>unidirectional link\u7684\u5371\u96aa<\/strong><br>A unidirectional link poses a potential danger to STP topologies because BPDUs will not be received on one end of the link. If that end of the link normally would be in the Blocking state, it will not be that way for long. A switch interprets the absence of BPDUs to mean that the port can be moved safely through the STP states so that traffic can be forwarded.<br>However, if that is done&nbsp;<strong>on a unidirectional link, a bridging loop forms<\/strong>&nbsp;and the switch never realizes the mistake<\/p>\n\n\n\n<p><strong>UDLD\u904b\u4f5c\u539f\u7406<\/strong><br>1<br>A switch&nbsp;<strong>sends special Layer 2 UDLD frames<\/strong>&nbsp;identifying its switch port at&nbsp;<strong>regular intervals(The default is 15 sec)<\/strong><br>Destination MAC\u70ba0100:0CCC:CCCC<br>2<br>UDLD expects the far-end switch to echo those frames back across the same link, with the far-end switch port&#8217;s identification added<br>3<br>\u6b63\u5e38\u60c5\u6cc1\u4e0b<br>If a UDLD frame is received in return and both neighboring ports are identified in the frame, the link must be bidirectional<\/p>\n\n\n\n<p>\u7570\u5e38\u767c\u751f\u6642<br>if the echoed frames are not seen, the link must be unidirectional for some reason<br>UDLD\u6839\u64da\u4e0d\u540cmode\u6709\u4e0d\u540c\u505a\u6cd5<br><strong>Normal mode :<\/strong><br>the port is allowed to continue its operation.<br>UDLD merely marks the port as having an undetermined state and&nbsp;<strong>generates a syslog message<\/strong><br><strong>aggressive mode(recommended)<\/strong><br>the switch takes action to reestablish the link.<br>UDLD messages are sent out once<strong>&nbsp;a second for 8 seconds.<\/strong><br>If none of those messages is echoed back, the port is placed in the<strong>&nbsp;Errdisable state<\/strong>&nbsp;so that it cannot be used<\/p>\n\n\n\n<p><strong>UDLD\u6642\u9593<\/strong><br>\u9700\u5728blocked port into the Forwarding state\u4e4b\u524d\u6aa2\u6e2c\u5230unidirectional link condition<br>ps:<br>the target time must &lt; &#8220;the Max Age timer + two intervals of the Forward Delay timer&#8221;, ( default is 50 seconds)<br>\u6aa2\u6e2cunidirectional link\u6642\u9593\u4e0d\u8d85\u904e<strong>&nbsp;3 times the UDLD message<\/strong>&nbsp;interval (default 45sec total).<\/p>\n\n\n\n<p>UDLD\u555f\u7528\u904e\u7a0b<br>1<br>UDLD has no record of any neighbor on the link.<br>It starts sending out messages,<br>2<br><strong>case1:the neighboring switch also support UDLD<\/strong><br>a neighboring switch will hear them and echo them back<br><strong>case2:the neighboring switch does not yet have UDLD enabled<\/strong><br>UDLD will<br>\u30001. keep trying (indefinitely) to detect a neighbor<br>\u30002. not disable the link<br>After the neighbor has UDLD configured also,<br>a neighboring switch will hear them and echo them back<br>3<br>both switches become aware of each other and the bidirectional state of the link through their UDLD message exchanges<br>if messages are not echoed, the link can accurately be labeled as unidirectional<br>ps:<br>This becomes important in an EtherChannel:<br>If one link within the channel becomes unidirectional, UDLD flags or disables only the offending link in the bundle,not the entire EtherChannel. UDLD sends and echoes its messages on each link within an EtherChannel channel independently<\/p>\n\n\n\n<p><br>\u4ee5global\u8a2d\u5b9audld\u4f5c\u696d\u6a21\u5f0f<br><strong>(config)# udld&nbsp;&lt; enable | aggressive&gt;<\/strong><br>By default,UDLD is disabled on all switch ports<br>enables UDLD only on ports that use&nbsp;<strong>fiber-optic media<\/strong><br>\u5404\u53c3\u6578\u8aaa\u660e\u5982\u4e0b<br><strong>enable<\/strong>: \u9810\u8a2d,\u4f7f\u7528normal mode<br><strong>aggressive<\/strong>: \u4f7f\u7528aggressive mode<br>ps:<br>\u4ee5port\u8a2d\u5b9audld\u4f5c\u696d\u6a21\u5f0f<br><strong>(config-if)# udld &lt; enable | aggressive | disable&gt;<\/strong><br>disable\u662f\u95dc\u9589\u9019\u500bport\u7684udld<br>ps:<br>\u5efa\u8b70\u4ee5global\u555f\u52d5\u65b9\u5f0f\u4ee3\u66ffindividual port\u555f\u52d5<br>ps:<br>UDLD\u6ce8\u610f\u4e8b\u9805<br>an echo process such as this requires&nbsp;<strong>both ends of the link to be configured for UDLD<\/strong>&nbsp;. Otherwise, one end of the link will not echo the frames back to the originator<\/p>\n\n\n\n<p>\u8a2d\u5b9audld time intervals<br><strong>(config)# udld message time &lt; seconds&gt;<\/strong><br>seconds\u53ef\u8a2d\u7bc4\u570d\u70ba7-90\u79d2<br>ps:Catalyst 3550 default is 7 sec; Catalyst 4500\/6500 default is 15 seconds<\/p>\n\n\n\n<p><br>Display the UDLD status on one or all ports.<br><strong># show udld &lt; interface&gt;<\/strong><\/p>\n\n\n\n<p>Reenable ports that UDLD aggressive mode has errdisabled.<br><strong># udld reset<\/strong><\/p>\n\n\n\n<p>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.<\/p>\n\n\n\n<p><strong>BPDU Filtering<\/strong><br>to prevent BPDUs from being sent or processed on one or more switch ports<br>disable STP on those ports<br>ps<br>Enable BPDU filtering only if the connected device cannot allow BPDUs to be accepted or sent. Otherwise, you should permit STP to operate on the switch ports as a precaution.<\/p>\n\n\n\n<p>\u5c07\u6240\u6709portfast\u4ecb\u9762\u555f\u7528bpdu filtering<br><strong>(config)# spanning-tree portfast bpdufilter &lt; default | enable &gt;<\/strong><br>default:\u7576portfast\u4ecb\u9762\u6536\u5230bpdu\u6642,\u8a72\u4ecb\u9762portfast\u6703\u88ab\u95dc\u9589\u4e26enable stp&nbsp;&nbsp;<br>If PortFast is disabled on a port, then BPDU filtering will not be enabled there<br>By default, BPDU filtering is disabled on all switch ports<br>ps:<br>you are absolutely sure that a switch port will have a single host connected and that a loop will be impossible<br>ps:<br>enable(or disable) bpdu filtering on a per-port basis<br><strong>(config-if)# spanning-tree bpdufilter &lt; enable | disable&gt;<\/strong><\/p>\n\n\n\n<p>Display the BPDU filter states<br><strong># show spanning-tree summary [ total]<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>STP guard \u9632\u6b62\u672a\u8a31\u53ef\u7684BPDU\u91cd\u8981\u6027\u3000\u7576&#038;#822 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[34],"tags":[],"class_list":["post-958","post","type-post","status-publish","format-standard","hentry","category-cisco-layer2"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/comments?post=958"}],"version-history":[{"count":0,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/958\/revisions"}],"wp:attachment":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/media?parent=958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/categories?post=958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/tags?post=958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}