频道栏目
首页 > 资讯 > 交换机 > 正文

交换机实验教程:交换机端口与MAC绑定

18-04-11        来源:[db:作者]  
收藏   我要投稿

交换机端口与MAC绑定

一、实验目的

1、了解什么是交换机的MAC绑定功能;

2、熟练掌握MAC与端口绑定的静态、动态方式。

二、应用环境

1、当网络中某机器由于中毒进而引发大量的广播数据包在网络中洪泛时,网络管理员的唯一想法就是尽快地找到根源主机并把它从网络中暂时隔离开。当网络的布置很随意时,任何用户只要插上网线,在任何位置都能够上网,这虽然使正常情况下的大多数用户很满意,但一旦发生网络故障,网管人员却很难快速准确定位根源主机,就更谈不上将它隔离了。端口与地址绑定技术使主机必须与某一端口进行绑定,也就是说,特定主机只有在某个特定端口下发出数据帧,才能被交换机接收并传输到网络上,如果这台主机移动到其他位置,则无法实现正常的连网。这样做看起来似乎对用户苛刻了一些,而且对于有大量使用便携机的员工的园区网并不适用,但基于安全管理的角度考虑,它却起到了至关重要的作用。

2、为了安全和便于管理,需要将MAC地址与端口进行绑定,即,MAC地址与端口绑定后,该MAC地址的数据流只能从绑定端口进入,不能从其他端口进入。该端口可以允许其他MAC地址的数据流通过。但是如果绑定方式采用动态lock的方式会使该端口的地址学习功能关闭,因此在取消lock之前,其他MAC的主机也不能从这个端口进入。

三、实验设备

1、DCS-3926S交换机1台

2、PC机2台

3、Console线1根

4、直通网线2根

四、实验拓扑

五、实验要求

1、交换机IP地址为192.168.1.11/24,PC1的地址为192.168.1.101/24;PC2的地址为192.168.1.102/24。

2、在交换机上作MAC与端口绑定;

3、PC1在不同的端口上ping交换机的IP,检验理论是否和实验一致。

4、PC2在不同的端口上ping交换机的IP,检验理论是否和实验一致。

六、实验步骤

第一步:得到PC1主机的mac地址

Microsoft Windows XP [版本5.1.2600]

(C)版权所有1985-2001 Microsoft Corp.

C:\>ipconfig/all

Windows IP Configuration

Host Name . . . . . . . . . . . . : xuxp

Primary Dns Suffix. . . . . . . : digitalchina.com

Node Type . . . . . . . . . . . . : Broadcast

IP Routing Enabled. . . . . . . . : No

WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter本地连接:

Connection-specific DNS Suffix. :

Description . . . . . . . . . . . : Intel(R) PRO/100 VE Network Connecti

on

Physical Address. . . . . . . . . :00-A0-D1-D1-07-FF

Dhcp Enabled. . . . . . . . . . . : Yes

Autoconfiguration Enabled . . . . : Yes

Autoconfiguration IP Address. . . : 169.254.27.232

Subnet Mask . . . . . . . . . . . : 255.255.0.0

Default Gateway . . . . . . . . . :

C:\>

我们得到了PC1主机的mac地址为:00-A0-D1-D1-07-FF。

第二步:交换机全部恢复出厂设置,配置交换机的IP地址

switch(Config)#interface vlan 1

switch(Config-If-Vlan1)#ip address 192.168.1.11 255.255.255.0

switch(Config-If-Vlan1)#no shut

switch(Config-If-Vlan1)#exit

switch(Config)#

第三步:使能端口的MAC地址绑定功能

switch(Config)#interface ethernet 0/0/1

switch(Config-Ethernet0/0/1)#switchport port-security

switch(Config-Ethernet0/0/1)#

第四步:添加端口静态安全MAC地址,缺省端口最大安全MAC地址数为1

switch(Config-Ethernet0/0/1)#switchport port-security mac-address 00-a0-d1-d1-07-ff

验证配置:

switch#show port-security

SecurityPortMaxSecurityAddrCurrentAddrSecurity Action

(count)(count)

---------------------------------------------------------------------------

Ethernet0/0/111Protect

---------------------------------------------------------------------------

Max Addresses limit per port :128

Total Addresses in System :1

switch#

switch#show port-security address

Security Mac Address Table

---------------------------------------------------------------------------

VlanMac AddressTypePorts

100-a0-d1-d1-07-ffSecurityConfiguredEthernet0/0/1

---------------------------------------------------------------------------

Total Addresses in System :1

Max Addresses limit in System :128

switch#

第五步:使用ping命令验证

PC

端口

Ping

结果

原因

PC1

0/0/1

192.168.1.11

 

PC1

0/0/7

192.168.1.11

不通

 

PC2

0/0/1

192.168.1.11

 

PC2

0/0/7

192.168.1.11

 

第六步:在一个以太口上静态捆绑多个MAC

Switch(Config-Ethernet0/0/1)#switchport port-security maximum 4

Switch(Config-Ethernet0/0/1)#switchport port-security mac-address aa-aa-aa-aa-aa-aa

Switch(Config-Ethernet0/0/1)#switchport port-security mac-address aa-aa-aa-bb-bb-bb

Switch(Config-Ethernet0/0/1)#switchport port-security mac-address aa-aa-aa-cc-cc-cc

验证配置:

switch#show port-security

SecurityPortMaxSecurityAddrCurrentAddrSecurity Action

(count)(count)

---------------------------------------------------------------------------

Ethernet0/0/144Protect

---------------------------------------------------------------------------

Max Addresses limit per port :128

Total Addresses in System :4

switch#show port-security address

Security Mac Address Table

---------------------------------------------------------------------------

VlanMac AddressTypePorts

100-a0-d1-d1-07-ffSecurityConfiguredEthernet0/0/1

1aa-aa-aa-aa-aa-aaSecurityConfiguredEthernet0/0/1

1aa-aa-aa-bb-bb-bbSecurityConfiguredEthernet0/0/1

1aa-aa-aa-cc-cc-ccSecurityConfiguredEthernet0/0/1

---------------------------------------------------------------------------

Total Addresses in System :4

Max Addresses limit in System :128

switch#

上面使用的都是静态捆绑MAC的方法,下面介绍动态mac地址绑定的基本方法,首先清空刚才做过的捆绑。

第七步:清空端口与MAC绑定

switch(Config)#

switch(Config)#int ethernet 0/0/1

switch(Config-Ethernet0/0/1)#no switchport port-security

switch(Config-Ethernet0/0/1)#exit

switch(Config)#exit

验证配置:

switch#show port-security

SecurityPortMaxSecurityAddrCurrentAddrSecurity Action

(count)(count)

---------------------------------------------------------------------------

---------------------------------------------------------------------------

Max Addresses limit per port :128

Total Addresses in System :0

第八步:使能端口的MAC地址绑定功能,动态学习MAC并转换

switch(Config)#interface ethernet 0/0/1

switch(Config-Ethernet0/0/1)#switchport port-security

switch(Config-Ethernet0/0/1)#switchport port-security lock

switch(Config-Ethernet0/0/1)#switchport port-security convert

switch(Config-Ethernet0/0/1)#exit

验证配置:

switch#show port-security address

Security Mac Address Table

---------------------------------------------------------------------------

VlanMac AddressTypePorts

100-a0-d1-d1-07-ffSecurityConfiguredEthernet0/0/1

---------------------------------------------------------------------------

Total Addresses in System :1

Max Addresses limit in System :128

switch#

第九步:使用ping命令验证

PC

端口

Ping

结果

原因

PC1

0/0/1

192.168.1.11

 

PC1

0/0/7

192.168.1.11

不通

 

PC2

0/0/1

192.168.1.11

不通

 

PC2

0/0/7

192.168.1.11

 

七、注意事项和排错

1、如果出现端口无法配置MAC地址绑定功能的情况,请检查交换机的端口是否运行了Spanning-tree,802.1x,端口汇聚或者端口已经配置为Trunk端口。MAC绑定在端口上与这些配置是互斥的,如果该端口要打开MAC地址绑定功能,就必须首先确认端口下的上述功能已经被关闭。

2、当动态学习MAC时,无法执行“convert”命令时,请检查PC机网卡是否和该端口正确连接。

3、端口Lock之后,该端口MAC地址学习功能被关闭,不允许其他的MAC进入该端口。

八、配置序列

九、课后练习

1、使用三台PC测试端口与MAC绑定功能。

2、实现多个端口统一绑定。

十、相关配置命令详解

switchport port-security

命令:switchport port-security

no switchport port-security

功能:使能端口MAC地址绑定功能;本命令的no操作为关闭端口MAC地址绑定功能。

命令模式:端口配置模式

缺省情况:交换机端口不打开MAC地址绑定功能。

使用指南:MAC地址绑定功能与802.1x、Spanning Tree、端口汇聚功能存在互斥关系,因此如果要打开端口的MAC地址绑定功能,就必须关闭端口上的802.1x、Spanning Tree、端口汇聚功能,且打开MAC地址绑定功能的端口不能是Trunk口。

举例:使能端口1的MAC地址绑定功能。

Switch(Config)#interface Ethernet 0/0/1

Switch(Config-Ethernet0/0/1)#switchport port-security

switchport port-security convert

命令:switchport port-security convert

功能:将端口学习到的动态MAC地址转化为静态安全MAC地址。

命令模式:端口配置模式

使用指南:必须在安全端口锁定之后才能执行端口动态MAC地址转化命令。执行此命令之后,端口学习到的动态MAC地址将转化为静态安全MAC地址。该命令没有配置保留。

举例:将端口1的MAC地址转化为静态安全MAC地址。

Switch(Config)#interface Ethernet 0/0/1

Switch(Config-Ethernet0/0/1)#switchport port-security convert

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

switchport port-security timeout

命令:switchport port-security timeout

no switchport port-security timeout

功能:设置端口锁定的定时器;本命令的no操作为恢复缺省值。

参数:锁定时器时间间隔,取值范围为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

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

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

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

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上限的时候,端口将被关闭,用户可以通过no shutdown命令手工打开该端口。

举例:设置端口1的违背模式为shutdown。

Switch(Config)#interface Ethernet 0/0/1

Switch(Config-Ethernet0/0/1)#switchport port-security violation shutdown

show port-security

命令:show port-security

功能:显示全局安全端口配置情况。

命令模式:特权配置模式

缺省情况:交换机不显示安全端口配置情况。

使用指南:本命令显示交换机当前已经配置为安全端口的端口信息。

举例:

Switch#show port-security

SecurityPortMaxSecurityAddrCurrentAddrSecurity Action

(count)(count)

-----------------------------------------------------------------

Ethernet0/0/311Protect

Ethernet0/0/4101Protect

Ethernet0/0/510Protect

-----------------------------------------------------------------

Total Addresses in System :2

Max Addresses limit in System :128

显示信息

解释

SecurityPort

配置为安全端口的端口名

MaxSecurityAddr

安全端口设置的最大安全MAC地址数

CurrentAddr

安全端口当前安全MAC地址数

Security Action

端口设置的违背模式

Total Addresses in System

系统中当前安全MAC地址数

Max Addresses limit in System

系统中最大安全MAC地址数

show port-security interface

命令:show port-security interface

功能:显示安全端口配置情况。

命令模式:特权配置模式

参数:指定的显示端口。

缺省情况:交换机不显示安全端口配置情况。

使用指南:本命令显示交换机安全端口的详细配置信息。

举例:

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

显示信息

解释

Port Security :

端口是否使能为安全端口

Port status :

端口安全状态

Violation mode :

端口设置的违背模式

Maximum MAC Addresses :

端口设置的安全MAC地址上限

Total MAC Addresses :

端口当前安全MAC地址数

Configured MAC Addresses :

端口静态配置的安全MAC地址数

Lock Timer

端口是否开启锁定的定时器(定时器时间)

Mac-Learning function

端口MAC地址学习功能是否打开

show port-security address

命令:show port-security address [interface]

功能:显示端口安全MAC地址。

命令模式:特权配置模式

参数:指定的显示端口。

使用指南:本命令显示端口安全MAC地址信息,如果不指定端口则显示所有端口安全MAC地址。显示内容举例如下:

Switch#show port-security address interface ethernet 0/0/1

Security Mac Address Table

------------------------------------------------------------------------

VlanMac AddressTypePorts

10000.0000.1111SecureConfiguredEthernet0/0/3

------------------------------------------------------------------------

Total Addresses :1

显示信息

解释

Vlan

安全MAC地址的VLAN ID

Mac Address

安全MAC地址

Type

安全MAC地址类型

Ports

安全MAC地址所属端口

Total Addresses

系统中当前安全MAC地址数


相关TAG标签
上一篇:交换机实验教程:交换机恢复出厂设置及其基本配置
下一篇:编程开发不容易系列之一
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站