端口安全总结

=========
端口安全
=========
- 端口安全是第2层特性,能够提供如下5种保护特性:
 > 基于主机MAC地址允许流量
 > 基于主机MAC地址限制流量
 > 在期望的端口上阻塞单播扩散
 > 避免MAC扩散攻击
 > 避免MAC欺骗攻击

- 合法的MAC地址才能使用端口。合法地址可以自动学习也可静态定义合法MAC地址可靠的MAC地址。配置时候有三种类型。
静态可靠的MAC地址:在交换机接口模式下手动配置,这个配置会被保存在交换机MAC地址表和运行配置文件中,交换机重新启动后不丢失(当然是在保存配置完成后),具体命令如下:
Switch(config-if)#switchport port-security mac-address Mac地址
动态可靠的MAC地址:这种类型是交换机默认的类型。在这种类型下,交换机会动态学习MAC地址,但是这个配置只会保存在MAC地址表中,不会保存在运行配置文件中,并且交换机重新启动后,这些MAC地址表中的MAC地址自动会被清除。
黏性可靠的MAC地址:这种类型下,可以手动配置MAC地址和端口的绑定,也可以让交换机自动学习来绑定,这个配置会被保存在MAC地址中和运行配置文件中,如果保存配置,交换机重起动后不用再自动重新学习MAC地址,虽然黏性的可靠的MAC地址可以手动配置,但是CISCO官方不推荐这样做。具体命令如下:
Switch(config-if)#switchport port-security mac-address sticky (sticky的功能,无论MAC是静态,还是动态,重启后仍然存在)
其实在上面这条命令配置后并且该端口得到MAC地址后,会自动生成一条配置命令
Switch(config-if)#switchport port-security mac-address sticky Mac地址
这也是为何在这种类型下CISCO不推荐手动配置MAC地址的原因。


1.基于主机MAC来允许流量
配置端口安全特性:
1.启用端口安全特性:
router(config-if)#switchport port-security

2.限制被允许访问的MAC地址的最大数目:
(config-if)#switchport port-security maximum{number}[vlan vlan-id]

3.静态定义MAC地址,可以设置一个或多个MAC地址:
(config-if)#switchport port-security mac-address {mac-address}[vlan vlan-id]

4.定义当收到带有违法MAC地址信息的帧的时候,端口所采用的动作.
(config-if)#switchport port-security violation {protect|restrict|shutdown}
  >>shutdown (关闭)交换机将永久性或在特定时间周期内error-disable状态,即不可用
  >>restrict (限制)交换机继续工作,但将把来自未授权主机的数据帧丢弃
  >>protect  (保护)当超过允许学习的最大MAC地址数的时候,交换机将继续工作,但将把来自新主机的数据帧丢弃

5.启用MAC地址的粘滞学习(sticky learning),即当交换机重启后,MAC地址不需要重新学习,它们是被保持在交换机启动配置文件里.可选:
(config-if)#switchport port-security mac-address sticky
注意:端口安全仅仅配置在静态Access端口;
     在trunk端口、SPAN端口、快速以太通道、吉比特以太通道端口组或者被动态划给一个VLAN的端口上不能配置端口安全功能;
不能基于每VLAN设置端口安全;交换机不支持黏性可靠的MAC地址老化时间。protect和restrict模式不能同时设置在同一端口上。

eg:

授权MAC地址
server: 00-00-00-00-00-08
client: 00-00-00-00-11-18
需求:
1.实时媒体服务器插入交换机端口3/47,为了防止其他任何非授权设备插入相同的端口中。
2.接受授权MAC地址,任何非授权工作站插入端口2/2,交换机将关闭LAN端口2/2
4503(config)#interface FastEthernet 3/47
4503(config-if)#switchport
4503(config-if)#switchport mode access  /指定端口模式
4503(config-if)#switchport port-security
4503(config-if)#switchport port-security mac-address 0000.0000.0008 /配置MAC地址。 
4503(config-if)#switchport port-security maximum 1 /限制此端口允许通过的MAC地址数为1。 
4503(config-if)#switchport port-security aging static //打开静态映射 
4503(config-if)#switchport port-security violation restrict
4503(config)#interface FastEthernet 2/2
4503(config-if)#switchport
4503(config-if)#switchport mode access
4503(config-if)#switchport port-security
4503(config-if)#switchport port-security mac-address 0000.0000.1118
4503(config-if)#switchport port-security maximum 1
4503(config-if)#switchport port-security aging static
4503(config-if)#switchport port-security violation shutdown /当发现与上述配置不符时,端口down掉。 

2.基于主机MAC来限制流量 (3550上才可以做)
 列表中定义的MAC将被限制流量
(config)#mac-address-table static 0010.7b80.7b9b vlan 1 drop

3.阻塞未知单(组)播扩散 (3550上才可以做)
 对未知MAC地址,SW将从本VLAN的其他端口转发出去,但对于某些端口(端口安全只需要一个MAC/已到最大MAC)没必要再转发这些单(组)播。就可以在这些端口上设定这一特性,通常结合端口安全来做。
int f0/1
  switchport block [unicast | multicast]
show int f0/1 switchport
...Unknown unicast blocked: enabled
...Unknown multicast blocked: disabled


检验命令:显示所有接口上应用端口安全的信息: Switch#show port-security

显示具体接口上所应用端口安全的信息:Switch#show port-security interface interface x/y 如下图

显示合法的MAC 地址信息:Switch#show port-security address 如下图

默认的端口安全配置:
以下是端口安全在接口下的配置-
特性:port-sercurity  默认设置:关闭的。
特性:最大安全mac地址数目 默认设置:1
特性:违规模式  默认配置:shutdown,这端口在最大安全mac地址数量达到的时候会shutdown,并发snmp陷阱。
配置向导:
下面是配置端口安全的向导-
·安全端口不能在动态的access口或者trunk口上做,换言之,敲port-secure之前必须的是switch mode acc之后。
·安全端口不能是一个被保护的端口。
·安全端口不能是SPAN的目的地址。
·安全端口不能属于GEC或FEC的组。
·安全端口不能属于802.1x端口。如果你在安全端口试图开启802.1x,就会有报错信息,而且802.1x也关了。如果你试图改变开启了802.1x的端口为安全端口,错误信息就会出现,安全性设置不会改变。
配置案例:
1.在f0/12上最大mac地址数目为5的端口安全,违规动作为默认。
switch#config t
Enter configuration commands, one per line.  End with CNTL/Z.
switch(config)#int f0/12
switch(config-if)#swi mode acc
switch(config-if)#swi port-sec
switch(config-if)#swi port-sec max 5
switch(config-if)#end
switch#show port-sec int f0/12
Security Enabled:Yes, Port Status:SecureUp
Violation Mode:Shutdown
Max. Addrs:5, Current Addrs:0, Configure Addrs:0
 
2.如何配置f0/12安全mac地址
switch(config)#int f0/12
switch(config-if)#swi mode acc
switch(config-if)#swi port-sec
switch(config-if)#swi port-sec mac-add 1111.1111.1111
switch(config-if)#end
switch#show port-sec add
 Secure Mac Address Table
------------------------------------------------------------
 
Vlan    Mac Address       Type                Ports
----    -----------       ----                -----
   1    1000.2000.3000    SecureConfigured     Fa0/12
3.配置端口安全超时时间两小时。
switch(config)#int f0/12
switch(config)#swi port-sec aging time 120 
4.端口安全超时时间2分钟,给配置了安全地址的接口,类型为inactivity aging:
switch(config-if)#swi port-sec aging time 2
switch(config-if)#swi port-sec aging type inactivity
switch(config-if)#swi port-sec aging static
show port-security interface f0/12可以看状态.
其他show
show port-security 看哪些接口启用了端口安全.
show port-security address 看安全端口mac地址绑定关系.
 

原文地址:https://www.cnblogs.com/cyrusxx/p/12615681.html