Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#interface fa0/1
Switch(config-if)#description link routerA
Switch(config-if)#int vlan1
Switch(config-if)#ip add 192.168.1.2 255.255.255.0
Switch(config-if)#exit
Switch(config)#host 2960
2960(config)#ip default-gateway 192.168.1.1
2960(config)#interface fa0/2
2960(config-if)#description link pc0
2960(config-if)#int fa0/3
2960(config-if)#description link pc1
2960(config-if)#switchport mode access
2960(config-if)#switchport port-security
2960(config-if)#switchport port-security maximum 1
2960(config-if)#switchport port-security violation shutdown
**switchport port-security maximum :可以使用這個選項答應多個MAC地址。例如,假如用戶有一個12端口的集線器連接到交換機的此端口,就需要12個MAC:switchport port-security maximum 12 /答應此端口通過的最大MAC地址數目爲12
switchport port-security violation [protect|restrict|shutdown]:此命令告訴交換機當端口上MAC地址數超過了最大數量之後交換機應該怎麼做,一共三個參數:protect,restrict和shutdown,默認是關閉端口(shutdown)。我們可以選擇使用restrict來警告網絡治理員,也可以選擇protect來答應通過安全端口通信並丟棄來自其它MAC地址的數據包。