环境

  • Cisco Packet Tracer 5.3
  • Windows 10

    操作

    操作:按照如图所示连接拓扑图
    image.png
    1、进入相应的接口
    (以端口1设置Mac地址绑定,PC0接1端口举例)
    1. Switch>enable
    2. Switch#config
    3. Configuring from terminal, memory, or network [terminal]?
    4. Enter configuration commands, one per line. End with CNTL/Z.
    5. Switch(config)#
    6. Switch(config)#interface fastEthernet 0/1
    2、接口设为access模式
    1. Switch(config-if)#switchport mode access

3、启用安全端口

  1. Switch(config-if)#switchport port-security
  2. (查看mac-address绑定的几种方式,分别为静态绑定和粘滞绑定)
  3. Switch(config-if)#switchport port-security mac-address ?
  4. H.H.H 48 bit mac address
  5. sticky Configure dynamic secure addresses as sticky

第一种:动态配置

第二种:静态配置

(其中代码的最后一列为主机的Mac地址。寻找方法:单击主机→配置→fastEthernet→mac地址。)

  1. Switch(config-if)#switchport port-security mac-address 0001.C94E.1321

设置完成后,用主机pc0 ping pc2,然后可以在特权模式下通过以下命令查看以下(ctrl+z,快速回到特权模式下)

  1. Switch#show port-security address

若将pc0与端口1的连线断掉,改用pc3接端口1。在进行 pc3 ping pc2 不通(图示如下)
image.png
改回pc1依然不通,需重启路由器该端口

  1. Switch(config-if)#shutdown
  2. %LINK-5-CHANGED: Interface FastEthernet0/1, changed state to administratively down
  3. Switch(config-if)#no shutdown
  4. %LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
  5. %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
  6. Switch(config-if)#

实验工程

交换机端口与Mac地址绑定.zip