配置基于ACL的流量统计示例
组网需求
如图9-6所示,PC1的MAC地址为0000-0000-0003,它连接在Switch的GE1/0/1端口上,实现与其他设备的互连互通。现希望Switch对源MAC为0000-0000-0003的报文进行流量统计。
配置思路
- 配置各接口,实现Switch与Router、PC1互通。
- 配置ACL规则,匹配源MAC为0000-0000-0003的报文。
- 在接口GE1/0/1入方向配置流量统计,对该接口收到的源MAC为0000-0000-0003的报文进行统计。
操作步骤
- 创建VLAN并配置各接口
# 在Switch上创建VLAN20。
<HUAWEI> system-view [HUAWEI] sysname Switch [Switch] vlan 20 [Switch-vlan20] quit
# 配置接口GE1/0/1为Access类型接口,接口GE1/0/2为Trunk类型接口,并将GE1/0/1和GE1/0/2加入VLAN20。
[Switch] interface gigabitethernet 1/0/1 [Switch-GigabitEthernet1/0/1] port link-type access [Switch-GigabitEthernet1/0/1] port default vlan 20 [Switch-GigabitEthernet1/0/1] quit [Switch] interface gigabitethernet 1/0/2 [Switch-GigabitEthernet1/0/2] port link-type trunk [Switch-GigabitEthernet1/0/2] port trunk allow-pass vlan 20 [Switch-GigabitEthernet1/0/2] quit
# 创建VLANIF20,并配置IP地址10.10.10.2/24。
[Switch] interface vlanif 20 [Switch-Vlanif20] ip address 10.10.10.2 24 [Switch-Vlanif20] quit
请配置Router与Switch对接的接口IP地址为10.10.10.1/24。
- 配置ACL规则
# 在Switch上创建编码为4000的二层ACL,匹配源MAC为0000-0000-0003的报文。
[Switch] acl 4000 [Switch-acl-L2-4000] rule permit source-mac 0000-0000-0003 ffff-ffff-ffff [Switch-acl-L2-4000] quit
- 配置流量统计
# 在接口GE1/0/1入方向配置基于ACL的流量统计。
[Switch] interface gigabitethernet 1/0/1 [Switch-GigabitEthernet1/0/1] traffic-statistic inbound acl 4000 by-bytes [Switch-GigabitEthernet1/0/1] quit
- 验证配置结果
# 查看设备接口入方向上应用的ACL规则和流动作信息。
[Switch] display traffic-applied interface gigabitethernet 1/0/1 inbound ----------------------------------------------------------- ACL applied inbound interface GigabitEthernet1/0/1 ACL 4000 rule 5 permit source-mac 0000-0000-0003 ACTIONS: statistic by bytes -----------------------------------------------------------
# 查看流量统计信息。
[Switch] display traffic-statistics interface gigabitethernet 1/0/1 inbound acl 4000 --------------------------------------------------------------------------- Interface GigabitEthernet1/0/1 ACL:4000 Rule:5 matched:681.575M Bytes, passed:681.575M Bytes, dropped:0 Bytes
配置文件
Switch的配置文件
# sysname Switch # vlan batch 20 # acl number 4000 rule 5 permit source-mac 0000-0000-0003 # interface Vlanif20 ip address 10.10.10.2 255.255.255.0 # interface GigabitEthernet1/0/1 port link-type access port default vlan 20 traffic-statistic inbound acl 4000 by-bytes # interface GigabitEthernet1/0/2 port link-type trunk port trunk allow-pass vlan 20 # return