LoginSignup
9

More than 5 years have passed since last update.

posted at

[CISCO IOS] Spanning-treeのベストプラクティスを考える

1. はじめに

オプションがたくさんあって複雑なSTPの設定方法をまとめます。

2. 前提

使うのはRPVST (Rapid Per-Vlan Spanning-Tree)。

3. 設定方法

RPVSTの有効化:

(config)#spanning-tree mode rapid-pvst

Primary/Secondryブリッジの設定:
 1系スイッチに対して

(config)#spanning-tree vlan 1-4094 priority 0

 2系スイッチに対して

(config)#spanning-tree vlan 1-4094 priority 4096

BPDU Guardの有効化:

(config)#spanning-tree portfast bpduguard default

Portfastの設定:
 アクセスリンクに対して

tc0001(config-if)#spanning-tree portfast

 トランクリンクに対して

tc0001(config-if)#spanning-tree portfast trunk

4. 解説

4-1. RPVSTの有効化

デフォルトではRPVSTではなくPVSTが有効になっていますので、RPVSTに変更します。

tc0001#show spanning-tree

VLAN0001
  Spanning tree enabled protocol ieee
(以下省略)

tc0001#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
tc0001(config)#spanning-tree mode rapid-pvst
tc0001(config)#end
tc0001#show spanning-tree

VLAN0001
  Spanning tree enabled protocol rstp
(以下省略)

たまにno spanning-treeという悪魔のコマンドを使ってSTPを切っているスイッチがありますが、スイッチがシングル構成であっても絶対に辞めましょう。人はケーブルがあると空きポートに挿したくなる生き物なのです。STPを有効にすることによるデメリットはありません。

4-2. Primary/Secondaryブリッジの設定

上位スイッチが2台ある環境では1系をprimary、2系をsecondaryに設定しましょう。まずはCisco推奨のroot primaryというオプションを使ってみます。

tc0001#show spanning-tree
VLAN0001
  Spanning tree enabled protocol rstp
  Root ID    Priority    32769
             Address     0015.6256.6300
             Cost        19
             Port        25 (FastEthernet1/0/23)
(以下省略)
tc0001#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
tc0001(config)#spanning-tree vlan 1-4094 root primary
tc0001(config)#end
tc0001#show spanning-tree

VLAN0001
  Spanning tree enabled protocol rstp
  Root ID    Priority    24577
             Address     0016.4779.5500
             This bridge is the root
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
(以下省略)
tc0002#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
tc0002(config)#spanning-tree vlan 1-4094 root secondary
tc0002(config)#end
tc0002#show spanning-tree
(以下省略)
  Bridge ID  Priority    28673  (priority 28672 sys-id-ext 1)
             Address     0015.6256.6300
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time 300

Priorityが24576に変更されました。ちょっと中途半端で、納得のいかない数字です。既に他のブリッジにpriorityが設定してある時にprimaryオプションを設定するとどうなるかやってみましょう。2系スイッチにPriority 8192を設定した状態から始めます。

tc0001#show spanning-tree

VLAN0001
  Spanning tree enabled protocol rstp
  Root ID    Priority    8193
             Address     0015.6256.6300
             Cost        19
             Port        26 (FastEthernet1/0/24)
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
(省略)
tc0001#configure terminal
tc0001(config)#spanning-tree vlan 1-4094 root primary
tc0001(config)#end
tc0001#show spanning-tree

VLAN0001
  Spanning tree enabled protocol rstp
  Root ID    Priority    4097
             Address     0016.4779.5500
             This bridge is the root
             Hello Time   2 sec  Max Age 20 sec  Forward Delay 15 sec
(省略)

今度はpriorityが4096になりました。これはどういうことでしょうか? show runで設定を確認してみます。

tc0001#show running-config | include priority
spanning-tree vlan 1 priority 4096
spanning-tree vlan 2-4094 priority 24576
tc0001#

root primaryという設定を入れたはずなのに、vlan 1のpriorityが4096に、それ以外が24576に設定されています。どうやら、root primaryはコマンドが発効された瞬間にroot bridgeのpriorityを見て、それを上回るように設定されるようですね。2系スイッチのpriorityを0に設定した状態でコマンドを入れると失敗します。

tc0001(config)#spanning-tree vlan 1-4094 root primary
% Failed to make the bridge root for vlan 1
% It may be possible to make the bridge root by setting the priority
% for some (or all) of these instances to zero.

これはciscoの推奨コマンドではありますが、設計とは呼べないですね。priorityは定数で設定しましょう。実際にループ構成を取る設計だと、1系コアスイッチ、2系コアスイッチ、各アクセススイッチの順でpriorityが高くなっていく必要があります。1系には0を、2系には4096を設定しましょう。

tc0001(config)#spanning-tree vlan 1-4094 priority 0
tc0002(config)#spanning-tree vlan 1-4094 priority 4096

4-3. BPDU Guardの有効化とPortfast

Portfastはインターフェースに設定し、対象のポートでLink upが発生した際に、ListeningとLearningのプロセスをスキップして速やかにForwarding状態に移行させるコマンドです。STPとは関係のないサーバ、PC、ルータ等が接続されるポートで使用します。

STPでBLK状態のportに対して誤ってportfastを入れるとどうなるでしょうか? Fa1/0/23とFa1/0/24を接続して、2系のスイッチのFa1/0/24がBLKになった状態から始めます。

tc0002#show spanning-tree
(省略)

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa1/0/23         Root FWD 19        128.25   P2p
Fa1/0/24         Altn BLK 19        128.26   P2p

tc0002#debug spanning-tree events
Spanning Tree event debugging is on
tc0002#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
tc0002(config)#interface FastEthernet 1/0/24
tc0002(config-if)#spanning-tree portfast
%Warning: portfast should only be enabled on ports connected to a single
 host. Connecting hubs, concentrators, switches, bridges, etc... to this
 interface  when portfast is enabled, can cause temporary bridging loops.
 Use with CAUTION

%Portfast has been configured on FastEthernet1/0/24 but will only
 have effect when the interface is in a non-trunking mode.
tc0002(config-if)#end

...
...

何も起きませんでしたね。Portfastの細かい検証は別の回に再度やろうと思います。

BPDU Guardは機器全体に設定します。Portfastに設定されたポートに対してBPDUが飛んできた時、つまり設計とは異なる機器が接続されてしまった時に、そのポートを強制的にdisableにします。
BPDU GuardはPortfastの弱点を補完するコマンドで、デメリットも無いため必ず設定しましょう。

tc0001#show spanning-tree summary
(略)
PortFast BPDU Guard Default  is disabled
(略)
tc0001#configure terminal
Enter configuration commands, one per line.  End with CNTL/Z.
tc0001(config)#spanning-tree portfast bpduguard default
tc0001(config)#end
tc0001#show spanning-tree summary
(略)
PortFast BPDU Guard Default  is enabled

4. おわりに

やはり分量が多くなってしまいました。次回もstp編です。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
9