7.5.1.1 mac 地址绑定介绍
通常交换机支持动态学习mac 地址的功能,每个端口可以动态学习多个mac 地址,从而实现端口之间已知mac 地址数据流的转发。当mac 地址老化后,则进行广播处理。也就是说,交换机某接口上学习到某mac 地址后可以进行转发,如果将连线切换到另外一个接口上交换机将重新学习该mac 地址,从而在新切换的接口上实现数据转发。
但是,有些情况下为了安全和便于管理,需要将mac 地址与端口进行绑定,端口只允许已绑定mac 的数据流的转发。即,mac 地址与端口绑定后,该mac 地址的数据流只能从绑定端口进入,其他没有与端口绑定的mac 地址的数据流不可以从该端口进入。
7.5.1.2 mac 地址绑定配置
7.5.1.2.1 mac 地址绑定配置任务序列
1. 使能端口的mac 地址绑定功能
2. 端口mac 地址的锁定
3. mac 地址绑定的属性配置
1. 使能端口的mac 地址绑定功能

2. 端口mac 地址的锁定

3. mac 地址绑定的属性配置

7.5.1.2.2 mac 地址绑定配置命令
7.5.1.2.2.1 switchport port-security
命令:switchport port-security
no switchport port-security
功能:使能端口mac 地址绑定功能;本命令的no 操作为关闭端口mac 地址绑定功能。
命令模式:接口配置模式
缺省情况:交换机端口不打开mac 地址绑定功能。
使用指南:mac 地址绑定功能与spanning tree、端口汇聚功能存在互斥关系,因此如果要打开端口的mac 地址绑定功能,就必须关闭端口上的spanning tree、端口汇聚功能,且打开mac 地址绑定功能的端口不能是trunk 口。
举例:使能端口1 的mac 地址绑定功能。
switch(config)#interface ethernet 0/0/1
switch(config-ethernet0/0/1)#switchport port-security
7.5.1.2.2.2 switchport port-security convert
命令:switchport port-security convert
功能:将端口学习到的动态mac 地址转化为静态安全mac 地址,并且关闭端口的mac地址学习功能。
命令模式:接口配置模式
使用指南:必须在安全端口锁定之后才能执行端口动态mac 地址转化命令。执行此命令之后,端口学习到的动态mac 地址将转化为静态安全mac 地址。该命令没有配置保留。
举例:将端口1 的mac 地址转化为静态安全mac 地址。
switch(config)#interface ethernet 0/0/1
switch(config-ethernet0/0/1)#switchport port-security convert
7.5.1.2.2.3 switchport port-security lock
命令:switchport port-security lock
no switchport port-security lock
功能:锁定端口。端口被锁定之后,端口的mac地址学习功能将被关闭;本命令的no操作为恢复端口的mac地址学习功能。
命令模式:接口配置模式
缺省情况:端口未锁定
使用指南:端口必须使能mac 地址绑定功能之后才能执行端口锁定命令。执行端口锁定命令之后,端口将关闭动态mac 学习功能。
举例:锁定端口1。
switch(config)#interface ethernet 0/0/1
switch(config-ethernet0/0/1)#switchport port-security lock
7.5.1.2.2.4 switchport port-security timeout
命令:switchport port-security timeout [value]
no switchport port-security timeout
功能:设置端口锁定的定时器;本命令的no 操作为恢复缺省值。
参数:[value] 锁定时器时间间隔,取值范围为0~300s。
命令模式:接口配置模式
缺省情况:端口未打开端口锁定的定时器。
使用指南:端口锁定定时器功能是一种动态mac 地址锁定功能,锁定定时器超时就执行mac 地址锁定操作及将动态mac 转换为安全mac 地址的操作。端口必须先开启mac 地址绑定功能后才能使用此命令。
举例:设置端口1 的锁定时器为30 秒。
switch(config)#interface ethernet 0/0/1
switch(config-ethernet0/0/1)# switchport port-security timeout 30
7.5.1.2.2.5 switchport port-security mac-address
命令:switchport port-security mac-address [mac-address]
no switchport port-security mac-address [mac-address]
功能:添加静态安全mac 地址;本命令的no 操作为删除静态安全mac 地址。
命令模式:接口配置模式
参数:[mac-address]为添加/删除的mac 地址。
使用指南:端口必须使能mac 地址绑定功能之后才能添加端口静态安全mac 地址。
举例:添加mac 00-03-0f-fe-2e-d3 到端口1。
switch(config)#interface ethernet 0/0/1
switch(config-ethernet0/0/1)#switchport port-security mac-address 00-03-0f-fe-2e-d3
7.5.1.2.2.6 clear port-security dynamic
命令:clear port-security dynamic [address [mac-addr] | interface [interface-id] ]
功能:清除指定端口的动态mac 地址。
参数:[mac-addr]为mac 地址;[interface-id]为指定的端口号。
使用指南:必须在安全端口锁定之后之后才能执行指定端口的动态mac 清除操作。如果不指定端口、mac 地址,则清除所有锁定的安全端口的动态mac;如果仅指定端口,不指定mac 地址,则清除指定端口的所有动态mac 地址。
举例:删除端口1 动态mac。
switch#clear port-security dynamic interface ethernet 0/0/1
7.5.1.2.2.7 switchport port-security maximum
命令:switchport port-security maximum [value]
no switchport port-security maximum
功能:设置端口最大安全mac 地址数;本命令的no 操作为恢复最大安全地址数1。
命令模式:接口配置模式
参数:[value] 端口静态安全mac 地址上限,取值范围1~128。
缺省情况:端口最大安全mac 地址数为1。
使用指南:端口必须使能mac 地址绑定功能之后才能设置端口安全mac 地址上限。如果端口静态安全mac 地址数大于设置的最大安全mac 地址数,则设置失败;必须删除端口的静态安全mac 地址,直到端口静态安全mac 地址数不大于设置的最大安全mac 地址数,设置才会成功。
举例:设置端口1 安全mac 地址上限为4。
switch(config)#interface ethernet 0/0/1
switch(config-ethernet0/0/1)#switchport port-security maximum 4
7.5.1.2.2.8 switchport port-security violation
命令:switchport port-security violation {protect | shutdown}
no switchport port-security violation
功能:设置端口违背模式;本命令的no 操作为恢复违背模式为protect。
命令模式:接口配置模式
参数:protect 为保护模式;shutdown 为关闭模式。
缺省情况:端口违背模式为缺省为protect。
使用指南:端口必须使能mac 地址绑定功能之后才能设置端口违背模式。如果端口违背模式设置为protect,那么当端口安全mac 地址超过设置的端口安全mac 上限的时候,端口仅仅关闭动态mac 地址学习功能;如果端口违背模式设置为shutdown,那么当端口安全mac 地址超过设置的端口安全mac 上限的时候,端口将被关闭,用户可以通过noshutdown 命令手工打开该端口。
举例:设置端口1 的违背模式为shutdown。
switch(config)#interface ethernet 0/0/1
switch(config-ethernet0/0/1)#switchport port-security violation shutdown
命令模式:特权用户配置模式
7.5.1.3 mac 地址绑定排错帮助
7.5.1.3.1 mac 地址绑定调试和监测命令
7.5.1.3.1.1 show port-security
命令:show port-security
功能:显示全局安全端口配置情况。
命令模式:特权用户配置模式
缺省情况:交换机不显示安全端口配置情况。
使用指南:本命令显示交换机当前已经配置为安全端口的端口信息。
举例:
switch#show port-security

total addresses in system :2
max addresses limit in system :128

7.5.1.3.1.2 show port-security interface
命令:show port-security interface [interface-id]
功能:显示安全端口配置情况。
命令模式:特权用户配置模式
参数:[interface-id] 指定的显示端口。
缺省情况:交换机不显示安全端口配置情况。
使用指南:本命令显示交换机安全端口的详细配置信息。
举例:
switch#show port-security interface ethernet 0/0/1
port security :enabled
port status :security up
violation mode :protect
maximum mac addresses :1
total mac addresses :1
configured mac addresses :1
lock timer is shutdown
mac-learning function is : opened

7.5.1.3.1.3 show port-security address
命令:show port-security address [interface [interface-id]]
功能:显示端口安全mac 地址。
命令模式:特权用户配置模式
参数:[interface-id] 指定的显示端口。
使用指南:本命令显示端口安全mac 地址信息,如果不指定端口则显示所有端口安全mac地址。显示内容举例如下:
switch#show port-security address interface ethernet 0/0/3
security mac address table

7.5.1.3.2 mac 地址绑定排错帮助
用户在端口使能mac 地址绑定功能的时候,有可能会遇到失败的情况。可能的原因及解决建议如下:
1 如果出现端口无法配置mac 地址绑定功能的情况,请检查交换机的端口是否运行了spanning-tree,端口汇聚或者端口已经配置为trunk 端口。mac 绑定在端口上与这些配置是互斥的,如果该端口要打开mac 地址绑定功能,就必须首先确认端口下的上述功能已经被关闭。
2 将安全地址设置为静态地址,然后删除,则该安全地址尽管存在,但已经不起作用。因此建议用户在mac 绑定的端口不要设置静态地址。