现在开始配置!

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

 

第二步:配置交换机的IP地址

Switch>en
Switch>enable
Switch#conf
Switch#configure
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#in vl
Switch(config)#in vlan 1
Switch(config-if)#ip add 192.168.1.4 255.255.255.0
Switch(config-if)#no shu
Switch(config-if)#no shutdown
%LINK-5-CHANGED: Interface Vlan1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan1, changed state to up
Switch(config-if)#ex
第三步:使能端口的 MAC 地址绑定功能,添加端口静态安全 MAC 地址,缺省端口最大安全 MAC 地址数为 1
Switch(config)#in f0/1
Switch(config-if)#sw
Switch(config-if)#switchport m
Switch(config-if)#switchport mode a
Switch(config-if)#switchport mode access
Switch(config-if)#sw
Switch(config-if)#switchport po
Switch(config-if)#switchport port-security   《===========这步也是一条命令,不要忘记加
Switch(config-if)#sw
Switch(config-if)#switchport po
Switch(config-if)#switchport port-security mac  
Switch(config-if)#switchport port-security mac-address 0030.F2B6.B546
Switch(config-if)#ex
配置完成后结果图是

这是F0/1连接刚绑定过MAC地址的主机0

如果不是连接主机0 结果图会是这样

 


现在来配置在一个以太口上静态捆绑多个MAC

 

第一步:获取所需绑定的主机MAC地址

第二步:在交换机上配置相关命令(当然我们刚开始已经绑定单个MAC地址了)

Switch(config)#in f0/1
Switch(config-if)#sw
Switch(config-if)#switchport po
Switch(config-if)#switchport port-security max
Switch(config-if)#switchport port-security maximum 3
Switch(config-if)#sw
Switch(config-if)#switchport po
Switch(config-if)#switchport port-security mac
Switch(config-if)#switchport port-security mac-address 000C.85BB.4610
Switch(config-if)#sw
Switch(config-if)#switchport p
Switch(config-if)#switchport po
Switch(config-if)#switchport port-security mac
Switch(config-if)#switchport port-security mac-address 000C.CF24.140B
Switch(config-if)#ex
Switch(config)#
%LINK-5-CHANGED: Interface FastEthernet0/2, changed state to down

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/2, changed state to down
结果图以单个MAC地址结果图一样.

 


那么有没有一种办法让它将接入到此端口的MAC地址自动绑定到这个MAC地址中呢?

下面是配置过程:

Switch>enable
Switch#conf
Switch#configure
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line.  End with CNTL/Z.

Switch(config)#in f0/2
Switch(config-if)#sw
Switch(config-if)#switchport m
Switch(config-if)#switchport mode a
Switch(config-if)#switchport mode access
Switch(config-if)#sw
Switch(config-if)#switchport po
Switch(config-if)#switchport port-security
Switch(config-if)#sw
Switch(config-if)#switchport po
Switch(config-if)#switchport port-security max
Switch(config-if)#switchport port-security maximum 3
Switch(config-if)#switchport port-security mac-address sticky
Switch(config-if)#ex
Switch(config)#

我这里是配置的是将前三个接入到这个端口的计算机的MAC地址自动的加入到MAC地址表