组网需求  
 
 
 如 
 图 
 2-15 
 所示,用户网络 
 1 
 通过 
 LSW1 
 与 
 Switch 
 相连, 
 Switch 
 的接口为 
 GE0/0/1 
 。用户网络2通过 
 LSW2 
 与 
 Switch 
 相连, 
 Switch 
 的接口为 
 GE0/0/2 
 。 
 GE0/0/1 
 、 
 GE0/0/2 
 同属于 VLAN2。为控制接入用户数,对 
 VLAN2 
 进行 
 MAC 
 地址学习的限制。  
 
 
 
 图  
 2-15  
 配置基于  
 VLAN  
 的  
 MAC  
 地址学习限制组网图 
 
 
 
 
  配置思路  
 
 
  
  采用如下的思路配置基于 
  VLAN 
  的 
  MAC 
  地址学习限制:  
 
 
  
  1.  
  创建 
  VLAN 
  ,并将接口加入到 
  VLAN 
  中,实现二层转发功能。  
 
 
  
  2.  
  配置 
  VLAN 
  的 
  MAC 
  地址学习限制,实现防止 
  MAC 
  地址攻击,控制接入用户数量。  
 
 
  
  
   操作步骤  
  
 
   
   步骤 
   1  
   配置 
   MAC 
   地址学习限制  
  
 
   
   #  
   将 
   GigabitEthernet0/0/1 
   、 
   GigabitEthernet0/0/2 
   加入 
   VLAN2 
   。  
  
 
   
   <HUAWEI>  
   system-view  
  
 
   
   [HUAWEI]  
   sysname Switch  
  
 
   
   [Switch] 
    vlan 2  
  
 
   
   [Switch-vlan2]  
   quit  
  
 
   
   [Switch]  
   interface gigabitethernet 0/0/1  
  
 
   
   [Switch-GigabitEthernet0/0/1]  
   port link-type hybrid  
  
 
   
   [Switch-GigabitEthernet0/0/1]  
   port hybrid pvid vlan 2  
  
 
   
   [Switch-GigabitEthernet0/0/1]  
   port hybrid untagged vlan 2  
  
 
   
   [Switch-GigabitEthernet0/0/1]  
   quit  
  
 
   
   [Switch]  
   interface gigabitethernet 0/0/2  
  
 
   
   [Switch-GigabitEthernet0/0/2]  
   port link-type hybrid  
  
 
   
   [Switch-GigabitEthernet0/0/2]  
   port hybrid pvid vlan 2  
  
 
   
   [Switch-GigabitEthernet0/0/2]  
   port hybrid untagged vlan 2  
  
 
   
   [Switch-GigabitEthernet0/0/2]  
   quit  
  
 
   
   #  
   在 
   VLAN2 
   上配置 
   MAC 
   地址学习限制规则:最多可以学习 
   100 
   个 
   MAC 
   地址,超过最大  
  
 
   
   MAC 
   地址学习数量的报文丢弃并进行告警提示。  
  
 
   
   [Switch]  
   vlan 2  
  
 
   
   [Switch-vlan2]  
   mac-limit maximum 100 alarm enable  
  
 
   
   [Switch-vlan2]  
   return  
  
 
   
   
   步骤 
   2  
   验证配置结果  
  
 
   
   #  
   在任意视图下执行 
   display mac-limit 
   命令,查看 
   MAC 
   地址学习限制规则是否配置成  
  
 
   
   功。  
  
 
   
   <Switch>  
   display mac-limit  
  
 
   
   MAC limit is enabled  
  
 
   
   Total MAC limit rule count : 1  
  
 
   
   PORT VLAN/VSI SLOT Maximum Rate(ms) Action Alarm  
  
 
   
   ----------------------------------------------------------------------------  
  
 
   
   - 2 - 100 - forward enable  
  
 
   
   ---- 
   结束  
  
 
   
   
   配置文件  
  
 
   
   以下仅给出 
   Switch 
   的配置文件。  
  
 
   
   #  
  
 
   
   sysname Switch  
  
 
   
   #  
  
 
   
   vlan batch 2  
  
 
   
   #  
  
 
   
   vlan 2  
  
 
   
   mac-limit maximum 100  
  
 
   
   #  
  
 
   
   interface GigabitEthernet0/0/1  
  
 
   
   port link-type hybrid  
  
 
   
   port hybrid pvid vlan 2  
  
 
   
   port hybrid untagged vlan 2  
  
 
   
   #  
  
 
   
   interface GigabitEthernet0/0/2  
  
 
   
   port link-type hybrid  
  
 
   
   port hybrid pvid vlan 2  
  
 
   
   port hybrid untagged vlan 2 
  
 
   
    #  
   
 
    
    return 
   
 
  


















