模块六 二层交换机端口与MAC 地址绑定【场景构建】在日常工作中,经常会发生用户随意插拔交换机上的网线,给网管员在网络管理上带来一定的不便。
同时也会出现在一个交换机端口下连接另一个Hub 或交换机,导致网络线路的拥堵。
当网络中某机器由于中毒进而引发大量的广播数据包在网络中洪泛时,网络管理员的唯一想法就是尽快地找到根源主机并把它从网络中暂时隔离开。
当网络的布置很随意时,任何用户只要插上网线,在任何位置都能够上网,这虽然使正常情况下的大多数用户很满意,但一旦发生网络故障,网管人员却很难快速准确定位根源主机。
希望通过一定的方法,固定每台计算机连接的交换机端口,方便网管员日常的维护与更新。
[实验目的]1、 了解什么是交换机的MAC 绑定功能;2、 熟练掌握MAC 与端口绑定的静态、动态方式。
【知识准备】通过端口绑定特性,网络管理员可以将用户的MAC 地址和IP 地址绑定到指定的端口上。
进行绑定操作后,交换机只对从该端口收到的指定MAC 地址和IP 地址的用户发出的报文进行转发,提高了系统的安全性,增强了对网络安全的监控。
我们通常说的MAC 地址与交换机端口绑定其实就是交换机端口安全功能。
端口安全功能能让您配置一个端口只允许一台或者几台确定的设备访问那个交换机;能根据MAC 地址确定允许访问的设备;允许访问的设备的MAC 地址既可以手工配置,也可以从交换机“学到”;当一个未批准的MAC 地址试图访问端口的时候,交换机会挂起或者禁用该端口等等。
【实验一】 二层交换机端口静态绑定MAC 地址1.1 实验设备1、2950-24交换机1台2、PC 机2台3、交叉线1根4、直通网线2根1.2 组网图PC1PC2SW01.3 实验设备IP 地址及要求PC1连接F0/1PC2连接F0/2端口,并且在F0/2上将PC2的MAC地址绑定,PC2能PING通交换机。
若将PC1更换到F0/2上,则不能PING通交换机。
同理PC2更换到F0/1上,也不能PING通交换机。
1.4配置过程和解释PC机上的IP地址请自行设置完成。
第一步:得到PC1主机的mac地址PC>ipconfig /allPhysical Address................: 00E0.A323.5CE1IP Address......................: 192.168.1.1Subnet Mask.....................: 255.255.255.0Default Gateway.................: 0.0.0.0DNS Servers.....................: 0.0.0.0我们得到了PC1主机的mac地址为:00E0.A323.5CE1第二步:配置交换机的IP地址Switch(config)#int vlan 1Switch(config-if)#ip add 192.168.1.11 255.255.255.0Switch(config-if)#no shutdownSwitch(config-if)#exit第三步:使能F0/1端口的MAC地址绑定功能Switch(Config)#interface F0/1Switch(config-if)#switchport mode access将端口模式设置为access模式Switch(config-if)#switchport port-security命令:switchport port-securityno switchport port-security功能:使能端口MAC地址绑定功能;本命令的no操作为关闭端口MAC地址绑定功能。
命令模式:端口配置模式缺省情况:交换机端口不打开MAC地址绑定功能。
使用指南:MAC地址绑定功能与802.1x、Spanning Tree、端口汇聚功能存在互斥关系,因此如果要打开端口的MAC地址绑定功能,就必须关闭端口上的802.1x、Spanning Tree、端口汇聚功能,且打开MAC地址绑定功能的端口不能是Trunk口。
Switch(config-if)#第四步:添加端口静态安全MAC地址,缺省端口最大安全MAC地址数为1 Switch(config-if)#switchport port-security mac-address 00E0.A323.5CE1命令:switchport port-security mac-address <mac-address>no switchport port-security mac-address <mac-address>功能:添加静态安全MAC地址;本命令的no操作为删除静态安全MAC地址。
命令模式:端口配置模式参数:<mac-address>为添加/删除的MAC地址。
使用指南:端口必须使能MAC地址绑定功能之后才能添加端口静态安全MAC地址。
第五步:配置违反MAC安全采取的措施Switch(config-if)#switchport port-security violation restrict命令:switchport port-security violation {protect | restrict | shutdown }no switchport port-security violation功能:当超过设定MAC地址数量的最大值,或访问该端口的设备MAC地址不是这个MAC地址表中该端口的MAC地址,或同一个VLAN中一个MAC地址被配置在几个端口上时,就会引发违反MAC地址安全。
命令模式:端口配置模式参数:protect(保护模式):丢弃数据包,不发警告。
restrict(限制模式):丢弃数据包,发警告,发出SNMP trap,同时被记录在syslog日志里。
shutdown(关闭模式):这是交换机默认模式,在这种情况下端口立即变为err-disable状态,并且关掉端口灯,发出SNMP trap,同时被记录在syslog日志里,除非管理员手工激活,否则该端口失效。
查看配置:Switch#show port-security address命令:show port-security address [interface <interface-id>]功能:显示端口安全MAC地址。
命令模式:特权配置模式参数:<interface-id> 指定的显示端口。
使用指南:本命令显示端口安全MAC地址信息,如果不指定端口则显示所有端口安全MAC地址。
显Secure Mac Address Table-------------------------------------------------------------------------------Vlan Mac Address Type Ports Remaining ge(mins)---- ----------- ---- ----- -------------1 00E0.A323.5CE1 DynamicConfigured FastEthernet0/1------------------------------------------------------------------------------验证配置:PC1连接在F0/1上,使能F0/1端口Switch(config)#int f0/1Switch(config-if)#shutdownSwitch(config-if)#no shutdownPC1与交换机的PING命令测试结果PC>ping 192.168.1.11Pinging 192.168.1.11 with 32 bytes of data:Reply from 192.168.1.11: bytes=32 time=31ms TTL=255Reply from 192.168.1.11: bytes=32 time=31ms TTL=255Reply from 192.168.1.11: bytes=32 time=31ms TTL=255Reply from 192.168.1.11: bytes=32 time=31ms TTL=255Ping statistics for 192.168.1.11:Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),Approximate round trip times in milli-seconds:Minimum = 31ms, Maximum = 31ms, Average = 31ms第六步:将PC2的MAC地址绑定在F0/2端口上配置命令与F0/1端口绑定PC1的MAC地址相同PC1连接在F0/2上,使能F0/2端口Switch(config)#int f0/2Switch(config-if)#shutdownSwitch(config-if)#no shutdownPC>ping 192.168.1.11Pinging 192.168.1.11 with 32 bytes of data:Request timed out.Request timed out.Request timed out.Reply from 192.168.1.11: bytes=32 time=32ms TTL=255Ping statistics for 192.168.1.11:Packets: Sent = 4, Received = 1, Lost = 3 (75% loss), Approximate round trip times in milli-seconds:Minimum = 32ms, Maximum = 32ms, Average = 32ms1.5完整的配置文档Switch#sho runBuilding configuration...…………!interface FastEthernet0/1switchport mode accessswitchport port-securityswitchport port-security mac-address 00E0.A323.5CE1!interface FastEthernet0/2switchport mode accessswitchport port-securityswitchport port-security mac-address 00D0.FFA4.BEB3!interface FastEthernet0/3!…………interface FastEthernet0/24!interface Vlan1ip address 192.168.1.11 255.255.255.0!End【实验二】在一个端口上静态绑定多个MAC地址2.1实验设备1、2950-24交换机1台2、PC机4台3、交叉线1根4、直通网线4根2.2组网图PC1PC2PC3PC4SW02.3实验设备IP地址及要求将PC1、PC2、PC3端口上都能PING 通交换机,但更换为PC4后则不能PING通交换机。