一、實驗要求:
交換機f0/1只能連接兩臺pc,多了就自動斷線
配置命令
Switch(config)#int fa0/1
Switch(config-if)#switchport mode access //使用acces模式
Switch(config-if)#switchport port-security //先開啓安全
Switch(config-if)#switchport port-security maximum 2 //設置最大連接數爲2
Switch(config-if)#switchport port-security violation shutdown //超過連接數就斷線
二、驗證
新加一臺PC後,沒有進行通信,交換機的MAC表就不會有新加的PC的信息,也就是不知道有加計算機,用右邊ping左邊,還能ping通,當ping第三臺PC是,交換機會發現自己多加了一個MAC表,就會自動斷線,交換機和集線器的線會變紅
三、重啓交換機
拆掉多餘的PC,重啓交換機,可以恢復通信
Switch(config)#int fa0/1
Switch(config-if)#shut
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to administratively down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
Switch(config-if)#no shut
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
Switch(config-if)#