一、实验要求: 交换机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)#