由于mac acl的工作机制所以端口会学到mac地址
如果要使用port-security,请看以下示例配置
!
interface FastEthernet0/5
switchport access vlan 5
switchport mode access
switchport port-security
switchport port-security violation restrict
switchport port-security mac-address sticky
switchport port-security mac-address sticky bcee.7b87.0541
spanning-tree portfast
# Violation Mode 有4种,分别是protect、restrict、shutdown、shutdown vlan, 默认Violation Mode 是 shutdown
如果设置成shutdown模式,那么可能导致端口down掉,需要手动对该端口执行 shutdown 和 no shutdown,所以violation模式
最好设置成restrict模式。
# port-security mac-address 最好设置成sticky模式,这样端口可以自动学习到mac地址并且学到的地址是static模式,学到后在
running-config中自动添加一行"switchport port-security mac-address sticky bcee.7b87.0541",保存配置后,对交换机重新加电
配置仍然生效
# 如果要清除 sticky 到的mac地址 bcee.7b87.0541,那么把对应 bcee.7b87.0541 的电脑从交换机上网线拔掉
然后执行命令"clear port-security sticky address bcee.7b87.0541",再执行命令"sh mac-address-table | in bcee.7b87.0541"
就会发现 mac-address 中已经没有了 bcee.7b87.0541 ,而且 interface FastEthernet0/5 中也没有了 switchport port-security mac-address sticky bcee.7b87.0541
这一行。如果你要 sticky 另一台电脑的mac地址,那么直接把另一台电脑插到对应端口,然后执行"clear port-security sticky address bcee.7b87.0541"即可。