配置交换机SSH管理和端口安全——实验2:配置交换机端口安全

实验目的

通过本实验可以掌握:

  1. 交换机管理地址配置及接口配置。
  2. 查看交换机的MAC地址表。
  3. 配置静态端口安全、动态端口安全和粘滞端口安全的方法

实验拓扑

配置交换机端口安全的实验拓扑如图所示。

配置交换机端口安全的实验拓扑

实验步骤

(1)交换机基本配置

复制代码
Switch>enable
Switch#conf t
Switch(config)#hostname S1

S1(config)#interface vlan 1
//配置交换机交换虚拟接口,用于交换机远程管理

S1(config-if)#ip address 192.168.1.50 255.255.255.0
S1(config-if)#no shutdown 
S1(config-if)#exit

S1(config)#ip default-gateway 192.168.1.1
//配置交换机默认网关

S1(config)#interface fastEthernet 0/11	
S1(config-if)#duple auto        //配置以太网接口双工模式,默认时双工状态是auto
S1(config-if)#speed auto        //配置以太网接口的速率,默认时速率是自适应即auto
S1(config-if)#mdix auto         //配置auito-MDIX
S1(config-if)#exit
S1(config)#interface range f0/5-9,f0/13-24,g0/1,g0/2
S1(config-if-range)#shutdown 
//以上2行批量禁用未使用的端口

【技术要点】

在以太网接口上使用auto-MDIX(自动介质相关接口交叉)功能可以解决直通和交叉乡缆的自适应问题,该功能默认启用,但是接口的速率和双工模式必须是 auto,否则该功能生效。

(2)查看交换机的MAC地址表

首先在计算机 PCI、PC2和 Serverl上配置正确的IP地址,并且用 ipconfig /all命令查看各台计算机网卡的MAC地址,记下来,然后在计算机PCl上分别ping PC2和 Serverl,进行连通性测试,接下来查看交换机MAC地址表。

复制代码
S1#show mac-address-table 
          Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----

   1    0001.6406.207b    DYNAMIC     Fa0/11    //计算机Server1网卡的MAC地址
   1    0040.0b44.3494    DYNAMIC     Fa0/10    //计算机PC0网卡的MAC地址
   1    00d0.97c1.6a09    DYNAMIC     Fa0/12    //计算机PC1网卡的MAC地址
S1#

以上显示了交换机S1上的MAC地址表,其中 vlan字段表示交换机端口所在的VLAN;Mac Address字段表示与端口相连的设备的MAC地址:Type字段表示填充MAC地址记录的类型,DYNAMIC表示MAC记录是交换机动态学习的,STATIC表示MAC记录是静态配置或系统保留的:Ports字段表示设备连接的交换机端口。

1、可以通过下面命令查看交换机动态学习的MAC地址表的超时时间或老化时间,默认为300秒。

复制代码
S1#show mac address-table aging-time 
Global Aging Time:  300
Vlan    Aging Time
----    ----------
S1#

2、可以通过下面命令修改VLAN 1的 MAC地址表的超时时间为120秒。

复制代码
S1(config)#mac address-table aging-time 120 vlan 1

3、可以通过下面命令配置静态填充交换机MAC地址表

复制代码
S1(config)#mac address-table static 0001.6406.207b vlan 1 interface fastEthernet 0/11

(3)配置交换机静态端口安全

在交换机S1上配置端口安全,Fa0/10配置动态端口安全;FaO/11配置静态端口安全;FaO/12配置粘滞端口安全。因为交换机FaO/11端口连接Serverl服务器,服务器不会轻易更换,适合配置静态端口安全。

复制代码
S1(config)#interface fastEthernet 0/11
S1(config-if)#switchport mode access	
//端口配置为接入模式,配置端口安全的端口不能是动态协商模式
S1(config-if)#switchport port-security
 //打开交换机的端口安全功能
S1(config-if)#switchport port-security maximum 1
//配置端口允许接入设备的MAC地址最大数目,默认是1,即只允许一个设备接入
S1(config-if)#switchport port-security mac-address 0001.6406.207b
//配置端口允许接入计算机的MAC地址
S1(config-if)#switchport port-security violation shutdown 
//配置端口安全违规惩罚模式,这也是默认的惩罚行为
S1(config-if)#exit

此时,从Server1 上 ping交换机的管理地址,可以 ping通。

4)验证交换机静态端口安全

复制代码
S1#show mac-address-table 
          Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----

   1    0001.6406.207b    STATIC      Fa0/11       //Server1的网卡MAC地址静态加入MAC地址表
S1#

在S1端口Fa0/11接入另一台计算机,模拟非法服务器接入,交换机显示的信息如下:

复制代码
*Apr  3 07:43:43.080: %PM-4-ERR_DISABLE: psecure-violation error detected on Et0/1, putting Et0/1 in err-disable state
S1#
*Apr  3 07:43:43.080: %PORT_SECURITY-2-PSECURE_VIOLATION: Security violation occurred, caused by MAC address aabb.cc00.0200 on port Ethernet0/1.
*Apr  3 07:43:44.084: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/1, changed state to down
S1#
*Apr  3 07:43:45.080: %LINK-3-UPDOWN: Interface Ethernet0/1, changed state to down

以上输出显示了交换机启用端口安全的端口、允许连接最大MAC地址的数量、目前连接MAC地址的数量、惩罚计数和惩罚模式。

复制代码
S1#show port-security interface fastEthernet 0/11
Port Security              : Enabled
Port Status                : Secure-shutdown
Violation Mode             : Shutdown
Aging Time                 : 0 mins
Aging Type                 : Absolute
SecureStatic Address Aging : Disabled
Maximum MAC Addresses      : 1
Total MAC Addresses        : 1
Configured MAC Addresses   : 1
Sticky MAC Addresses       : 0
Last Source Address:Vlan   : 0030.A3E5.7101:1
Security Violation Count   : 1

移除非法设备后,重新连接Serverl到该接口,由于已经配置了端口 errdisable自动恢复所以交换机显示自动恢复的消息如下:

【提示】

如果没有配置由于端口安全惩罚而关闭的端口自动恢复,则需要管理员在交换机的Fa0/11端口下执行 shutdown和 no shutdown命令来重新开启该端口,如果还是非法主机尝试连接,则继续惩罚,端口再次变为err-disable状态。

(5)配置交换机动态端口安全

很多公司员工使用笔记本电脑办公,而且位置不固定(如会议室),因此适合配置动态端口安全,限制每个端口只能连接1台计算机,避免用户私自连接AP或者其他的交换机而带来安全隐患。交换机 Fa0/10端口连接计算机不固定,适合配置动态端口安全,安全惩罚模式为restrict。

复制代码
S1(config)#interface fastEthernet 0/10
S1(config-if)#switchport mode access
S1(config-if)#switchport port-security 
S1(config-if)#switchport port-security maximum 1
S1(config-if)#switchport port-security violation restrict 
S1(config-if)#exit

(6)验证动态端口安全

复制代码
S1#show port-security interface fastEthernet 0/10
Port Security              : Enabled
Port Status                : Secure-up
Violation Mode             : Restrict
Aging Time                 : 0 mins
Aging Type                 : Absolute
SecureStatic Address Aging : Disabled
Maximum MAC Addresses      : 1
Total MAC Addresses        : 0
Configured MAC Addresses   : 0
Sticky MAC Addresses       : 0
Last Source Address:Vlan   : 0000.0000.0000:0
Security Violation Count   : 0

(7)配置粘滞端口安全

很多公司员工使用台式电脑办公,位置固定,如果配置静态端口安全,需要网管员到员工的计算机上查看MAC地址,工作量巨大。为了减轻工作量,适合配置粘滞端口安全,限制每个端口只能连接Ⅰ台计算机,避免其他用户的计算机使用交换机端口而带来安全隐患。交换机FaO/12端口连接计算机位置固定,适合配置粘滞端口安全,安全惩罚模式为restrict。

复制代码
S1(config)#interface fastEthernet 0/12
S1(config-if)#switchport mode access
S1(config-if)#switchport port-security 
S1(config-if)#switchport port-security maximum 1
S1(config-if)#switchport port-security violation restrict 
S1(config-if)#switchport port-security mac-address sticky 
//配置交换机端口自动粘滞访问该端口计算机的 MAC地址
S1(config-if)#exit

(8)验证粘滞端口安全

从PC2 上 ping交换机192.168.1.1,然后验证。

复制代码
S1#show port-security interface fastEthernet 0/12
Port Security              : Enabled
Port Status                : Secure-up
Violation Mode             : Restrict
Aging Time                 : 0 mins
Aging Type                 : Absolute
SecureStatic Address Aging : Disabled
Maximum MAC Addresses      : 1
Total MAC Addresses        : 1
Configured MAC Addresses   : 0
Sticky MAC Addresses       : 1
Last Source Address:Vlan   : 00D0.97C1.6A09:1
Security Violation Count   : 0

至此实验结束。

相关推荐
用户962377954488 小时前
DVWA 靶场实验报告 (High Level)
安全
数据智能老司机11 小时前
用于进攻性网络安全的智能体 AI——在 n8n 中构建你的第一个 AI 工作流
人工智能·安全·agent
数据智能老司机11 小时前
用于进攻性网络安全的智能体 AI——智能体 AI 入门
人工智能·安全·agent
用户9623779544813 小时前
DVWA 靶场实验报告 (Medium Level)
安全
red1giant_star13 小时前
S2-067 漏洞复现:Struts2 S2-067 文件上传路径穿越漏洞
安全
用户9623779544816 小时前
DVWA Weak Session IDs High 的 Cookie dvwaSession 为什么刷新不出来?
安全
cipher2 天前
ERC-4626 通胀攻击:DeFi 金库的"捐款陷阱"
前端·后端·安全
埃博拉酱5 天前
VS Code Remote SSH 连接 Windows 服务器卡在"下载 VS Code 服务器":prcdn DNS 解析失败的诊断与 BITS 断点续传
windows·ssh·visual studio code
一次旅行5 天前
网络安全总结
安全·web安全
DianSan_ERP5 天前
电商API接口全链路监控:构建坚不可摧的线上运维防线
大数据·运维·网络·人工智能·git·servlet