实验十八、交换机端口与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根

四、 实验拓扑

交换机端口与MAC 绑定

五、 实验要求

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

Security Port MaxSecurityAddr CurrentAddr Security Action

(count) (count)

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

Ethernet0/0/1 1 1 Protect

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

Max Addresses limit per port :128

Total Addresses in System :1

switch#

switch#show port-security address

Security Mac Address Table

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

Vlan Mac Address Type Ports

1 00-a0-d1-d1-07-ff SecurityConfigured Ethernet0/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

Security Port MaxSecurityAddr CurrentAddr Security Action

(count) (count)

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

Ethernet0/0/1 4 4 Protect

--------------------------------------------------------------------------- Max Addresses limit per port :128

Total Addresses in System :4

switch#show port-security address

Security Mac Address Table

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

Vlan Mac Address Type Ports

1 00-a0-d1-d1-07-ff SecurityConfigured Ethernet0/0/1

1 aa-aa-aa-aa-aa-aa SecurityConfigured Ethernet0/0/1

1 aa-aa-aa-bb-bb-bb SecurityConfigured Ethernet0/0/1

1 aa-aa-aa-cc-cc-cc SecurityConfigured Ethernet0/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

Security Port MaxSecurityAddr CurrentAddr Security 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

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

Vlan Mac Address Type Ports

1 00-a0-d1-d1-07-ff SecurityConfigured Ethernet0/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 通