
1、概述
2、作用
1、配置流程
Switch(config-if)#switchport mode access/trunk
Switch(config-if)#switchport port-security
#注意:启用端口安全的接口不能是动态协商(dynamic)模式,必须配置接口为接入或干道模式配置允许访问网络的MAC地址
Switch(config-if)#switchport port-security maximum { max-addr }
//max-addr参数的范围是1~8192,在默认情况下为1Switch(config-if)#switchport port-security mac-address { mac-addr }
//mac-addr为静态绑定的MAC地址#如果同一端口主机经常变化,而旧MAC地址一直保留,这可能导致新连接到端口的客无法正常通讯
#配置交换机接口老化时间,让交换机删除一段时间内没有流量的MAC地址
Switch(config-if)#switchport port-security aging time { time }
//time参数范围是1~1440分钟,默认为0表示不删除
Switch(config-if)#switchport port-security aging type { absolute | inactivity } //PT里面不支持
#absolute参数为老化时间到期后,删除所有MAC地址并重新学习
#inactivity参数为与端口连接的客户端一段时间(老化时间)没有流量,就将其MAC地址从地址表中删除
Switch(config-if)#switchport port-security aging static //PT里面不支持
#默认情况下静态绑定的MAC地址并不受老化时间的影响,Cisco交换机也可让静态绑定的MAC地址老化配置MAC地址违规后的策略
MAC地址违规
Switch(config-if)#switchport port-security violation { protect | restrict | shutdown}
#shutdown:端口成为err-disable状态,相当于关闭端口,默认处理方式
#protect:将违规的MAC地址的分组丢弃,但端口处于UP状态。交换机不记录违规分组
#restrict:将违规的MAC地址的分组丢弃,但端口处于UP状态。交换机记录违规分组当端口进入err-disable状态时,恢复接口状态的方法
Switch(config-if)#shutdown
Switch(config-if)#no shutdownSwitch(config)#errdisable recovery cause psecure-violation //出现err-disable状态的原因
Switch(config)#errdisable recovery interval { time } //恢复时间间隔err-disable状态的端口,默认情况下不会自动恢 复
配置端口安全的sticky(粘连)特性
Switch(config)#switchport port-securitymac-address sticky2、端口安全实验案例
实验拓扑

实验要求
配置过程
Switch>enable
Switch#conf t
Switch(config)#int f0/2
Switch(config-if)#switchport mode access //设置接口模式为接入链路
Switch(config-if)#switchport port-security //启用端口安全
Switch(config-if)#switchport port-security maximum 1 //设置端口活跃 MAC 地址数量为1个
Switch(config-if)#switchport port-security aging time 1 //配置老化时间1分钟
Switch(config-if)#switchport port-security violation restrict //配置违规策略为分组丢弃并记录
Switch(config-if)#switchport port-security mac-address 0000.0CB6.B828 //配置静态绑定2.主机配置(设置 IP 地址和子网掩码就可以,这里 就没有去划分 VLAN ,交换机所有接口都属于 VLAN 1

3.验证
Switch#show port-security int f0/2
Port Security : Enabled
Port Status : Secure-up #端口状态
Violation Mode : Restrict #违规策略
Aging Time : 1 mins #老化时间1分钟
Aging Type : Absolute #老化时间到期后删除所有 MAC 地址
SecureStatic Address Aging : Disabled #安全静态地址老化
Maximum MAC Addresses : 1 #最大 MAC 地址数量
Total MAC Addresses : 1 #静态绑定 MAC 地址数量
Configured MAC Addresses : 1 #MAC 地址配置1个
Sticky MAC Addresses : 0 #粘性 MAC 地址数量
Last Source Address:Vlan : 0000.0CB6.B828:1 #最后源地址和属于的 vlan
Security Violation Count : 0 #安全违规次数4.在交换机的 F0/2 接口上重新接上一台计算机来 模拟端口安全


3、配置脚本


//Switch0
interface FastEthernet0/2
switchport mode access
switchport port-security
switchport port-security violation restrict
switchport port-security mac-address 00E0.8F34.5B4D
switchport port-security aging time 1
