はじめに
CiscoスイッチのPort Security、設定自体は簡単なんだけど、パラメータの組み合わせで挙動が結構変わる。特にviolation modeとstickyラーニングの理解が曖昧だと、本番導入後に「ポートが全部err-disabledになった」みたいな事故が起きる。
この記事では、Port Securityの設定手順と現場でよくあるハマりどころをまとめた。
Port Securityとは
Port Securityは、スイッチの各ポートに「接続を許可するMACアドレス」を制限する機能。認証サーバー不要で、スイッチ単体で完結するのがメリット。
前提条件:
- switchport mode access が必須(トランク・EtherChannelメンバーは不可)
- dynamic desirableのままだとエラーになる
MACアドレス学習方式(3種類)
| 方式 | 登録方法 | 再起動後 | ユースケース |
|---|---|---|---|
| Static | CLIで手入力 | configに保存 | サーバールーム等 |
| Dynamic | 自動学習 | 消える | テスト環境 |
| Sticky | 自動学習→configに書込 | write memで永続化 | オフィス(最も多い) |
実務ではstickyが圧倒的に多い。Staticは100ポート超のスイッチでは現実的じゃないし、Dynamicは再起動で消えるから運用が面倒。
違反モード(Violation Mode)
| モード | 動作 | Syslog | 復旧方法 |
|---|---|---|---|
| shutdown(デフォルト) | ポートをerr-disabledにして遮断 | あり | shut → no shut |
| restrict | 不正MACのフレームだけ破棄 | あり | 自動(不正機器外すだけ) |
| protect | 不正MACのフレームだけ破棄 | なし | 自動 |
おすすめはrestrict。 shutdownはポートが完全に死ぬし、protectはログが出ないので不正接続に気づけない。
IP電話+PCのデイジーチェーン構成では、maximumを2以上に設定すること。1のままだと朝一で全ポートerr-disabledになる。
設定手順
Switch(config)# interface GigabitEthernet1/0/1
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 10
Switch(config-if)# switchport port-security
Switch(config-if)# switchport port-security maximum 2
Switch(config-if)# switchport port-security violation restrict
Switch(config-if)# switchport port-security mac-address sticky
エージング設定(オプション):
Switch(config-if)# switchport port-security aging time 120
Switch(config-if)# switchport port-security aging type inactivity
err-disabled自動復旧(shutdownモード使用時は必須):
Switch(config)# errdisable recovery cause psecure-violation
Switch(config)# errdisable recovery interval 300
確認コマンド
| コマンド | 用途 |
|---|---|
show port-security |
全ポートの状態一覧 |
show port-security interface [IF] |
特定ポートの詳細 |
show port-security address |
学習済みMAC一覧 |
show errdisable recovery |
自動復旧の設定確認 |
show interfaces status err-disabled |
err-disabledポート一覧 |
よくあるトラブル
ポートがerr-disabledになった
→ show port-security interface [IF] で Last Source Address を確認。不正機器を外して shut → no shut で復旧。
PC交換後にポートが使えない
→ stickyで学習済みのMACが残ってるので手動削除:
Switch(config-if)# no switchport port-security mac-address sticky [旧MAC]
Switch(config-if)# shutdown
Switch(config-if)# no shutdown
DHCP Snooping・DAIとの組み合わせ
Port Security + DHCP Snooping + DAIの3つをセットで入れるのが現場の鉄板構成。MACアドレス制限・不正DHCPサーバー排除・ARPスプーフィング防止をL2レベルで実現できる。
詳しくはブログで
この記事の完全版(構成図・プログレスバー付き比較・エージング詳細設定など)はブログで公開しています。
👉 Cisco Port Security設定手順|sticky・違反モードの使い分けとerr-disabled対処法【実機検証】