ACL通过一系列规则对数据包进行分类,这些规则应用到S9300接口上,S9300根据这些规则判断哪些数据包可以接收,哪些数据包需要拒绝。
介绍基本ACL的配置过程,包括配置URPF功能、配置基本ACL规则、配置流行为、流分类和流策略等。
如图5-282所示,Switch的GE1/0/1接口连接用户,GE2/0/1接口连接上层路由器。为防止基于源地址的欺骗,要求在GE1/0/1和GE2/0/1接口配置URPF严格检查模式,同时相信IP地址为10.0.0.2/24的用户A的流,对该用户的流去使能URPF检查功能。
采用如下的思路配置指定流去使能URPF功能:
为完成此配置举例,需要准备如下数据:
# 使能接口板的URPF功能。
system-view [Quidway] urpf slot 1 [Quidway] urpf slot 2
# 配置接口的URPF检查模式。
[Quidway] interface gigabitethernet 1/0/1 [Quidway-GigabitEthernet1/0/1] urpf strict [Quidway-GigabitEthernet1/0/1] quit [Quidway] interface gigabitethernet 2/0/1 [Quidway-GigabitEthernet2/0/1] urpf strict [Quidway-GigabitEthernet2/0/1] quit
# 定义ACL规则。
[Quidway] acl 2000 [Quidway-acl-basic-2000] rule permit source 10.0.0.2 0.0.0.255 [Quidway-acl-basic-2000] quit
# 配置流分类,定义基于ACL的匹配规则。
[Quidway] traffic classifier tc1 [Quidway-classifier-tc1] if-match acl 2000 [Quidway-classifier-tc1] quit
# 定义流行为,去使能流行为视图下URPF功能。
[Quidway] traffic behavior tb1 [Quidway-behavior-tb1] ip urpf disable [Quidway-behavior-tb1] quit
# 定义流策略,将流分类与流行为关联。
[Quidway] traffic policy tp1 [Quidway-trafficpolicy-tp1] classifier tc1 behavior tb1 [Quidway-trafficpolicy-tp1] quit
# 应用流策略到GE1/0/1接口。
[Quidway] interface gigabitethernet 1/0/1 [Quidway-GigabitEthernet1/0/1] traffic-policy tp1 inbound [Quidway-GigabitEthernet1/0/1] quit
# 查看ACL规则的配置信息
display acl 2000 Basic ACL 2000, 1 rule Acl's step is 5 rule 5 permit source 10.0.0.0 0.0.0.255 (0 times matched)
# 查看流分类的配置信息
display traffic classifier user-defined User Defined Classifier Information: Classifier: tc1 Precedence: 20 Operator: OR Rule(s) : if-match acl 2000
# 查看流策略的配置信息
display traffic policy user-defined tp1 User Defined Traffic Policy Information: Policy: tp1 Classifier: default-class Behavior: be -none- Classifier: tc1 Behavior: tb1 urpf switch: off
# urpf slot 1 urpf slot 2 # acl number 2000 rule 5 permit source 10.0.0.0 0.0.0.255 # traffic classifier tc1 if-match acl 2000 # traffic behavior tb1 ip urpf disable # traffic policy tp1 classifier tc1 behavior tb1 # interface GigabitEthernet1/0/1 urpf strict traffic-policy tp1 inbound # interface GigabitEthernet2/0/1 urpf strict # return
介绍高级ACL的配置过程,包括配置生效时间段、配置高级ACL规则、配置流行为、流分类和流策略等。
如图5-283所示,公司企业网通过Switch实现各部门之间的互连。要求正确配置IPv4 ACL,禁止研发部门和市场部门在上班时间(8:00至17:30)访问工资查询服务器(IP地址为10.164.9.9),而总裁办公室不受限制,可以随时访问。
采用如下的思路配置IPv4 ACL:
为完成此配置举例,需要准备如下数据:
# 配置接口加入VLAN,并配置VLANIF接口的IP地址。
规划GE1/0/1~GE1/0/3分别加入VLAN10、20、30,GE2/0/1加入VLAN100。VLANIF接口的地址取所在网段的第一个IP地址。下面配置以GE1/0/1接口为例,其他接口的配置与此类似,不再赘述。
system-view [Quidway] vlan batch 10 20 30 100 [Quidway] interface gigabitethernet 1/0/1 [Quidway-GigabitEthernet1/0/1] port link-type access [Quidway-GigabitEthernet1/0/1] port default vlan 10 [Quidway-GigabitEthernet1/0/1] quit [Quidway] interface vlanif 10 [Quidway-Vlanif10] ip address 10.164.1.1 255.255.255.0 [Quidway-Vlanif10] quit
# 配置8:00至17:30的周期时间段。
system-view [Quidway] time-range satime 8:00 to 17:30 working-day
# 配置市场部门到工资查询服务器的访问规则。
[Quidway] acl 3002 [Quidway-acl-adv-3002] rule deny ip source 10.164.2.0 0.0.0.255 destination 10.164.9.9 0.0.0.0 time-range satime [Quidway-acl-adv-3002] quit
# 配置研发部门到工资查询服务器的访问规则。
[Quidway] acl 3003 [Quidway-acl-adv-3003] rule deny ip source 10.164.3.0 0.0.0.255 destination 10.164.9.9 0.0.0.0 time-range satime [Quidway-acl-adv-3003] quit
# 配置流分类c_market,对匹配ACL 3002的报文进行分类。
[Quidway] traffic classifier c_market [Quidway-classifier-c_market] if-match acl 3002 [Quidway-classifier-c_market] quit
# 配置流分类c_rd,对匹配ACL 3003的报文进行分类。
[Quidway] traffic classifier c_rd [Quidway-classifier-c_rd] if-match acl 3003 [Quidway-classifier-c_rd] quit
# 配置流行为b_market,动作为拒绝报文通过。
[Quidway] traffic behavior b_market [Quidway-behavior-b_market] deny [Quidway-behavior-b_market] quit
# 配置流行为b_rd,动作为拒绝报文通过。
[Quidway] traffic behavior b_rd [Quidway-behavior-b_rd] deny [Quidway-behavior-b_rd] quit
# 配置流策略p_market,将流分类c_market与流行为b_market关联。
[Quidway] traffic policy p_market [Quidway-trafficpolicy-p_market] classifier c_market behavior b_market [Quidway-trafficpolicy-p_market] quit
# 配置流策略p_rd,将流分类c_rd与流行为b_rd关联。
[Quidway] traffic policy p_rd [Quidway-trafficpolicy-p_rd] classifier c_rd behavior b_rd [Quidway-trafficpolicy-p_rd] quit
# 将流策略p_market应用到GE1/0/2接口。
[Quidway] interface gigabitethernet 1/0/2 [Quidway-GigabitEthernet1/0/2] traffic-policy p_market inbound [Quidway-GigabitEthernet1/0/2] quit
# 将流策略p_rd应用到GE1/0/3接口。
[Quidway] interface gigabitethernet 1/0/3 [Quidway-GigabitEthernet1/0/3] traffic-policy p_rd inbound [Quidway-GigabitEthernet1/0/3] quit
# 查看ACL规则的配置信息。
display acl all Total nonempty ACL number is 2 Advanced ACL 3002, 1 rule Acl's step is 5 rule 5 deny ip source 10.164.2.0 0.0.0.255 destination 10.164.9.9 0 time-range satime (0 times matched)(Active) Advanced ACL 3003, 1 rule Acl's step is 5 rule 5 deny ip source 10.164.3.0 0.0.0.255 destination 10.164.9.9 0 time-range satime (0 times matched)(Active)
# 查看流分类的配置信息。
display traffic classifier user-defined User Defined Classifier Information: Classifier: c_market Precedence: 5 Operator: OR Rule(s) : if-match acl 3002 Classifier: c_rd Precedence: 10 Operator: OR Rule(s) : if-match acl 3003
# 查看流策略的配置信息。
display traffic policy user-defined tp1 User Defined Traffic Policy Information: Policy: p_market Classifier: default-class Behavior: be -none- Classifier: c_market Behavior: b_market Deny Policy: p_rd Classifier: default-class Behavior: be -none- Classifier: c_rd Behavior: b_rd Deny
# vlan batch 10 20 30 40 100 # time-range satime 08:00 to 17:30 working-day # acl number 3002 rule 5 deny ip source 10.164.2.0 0.0.0.255 destination 10.164.9.9 0 time-range satime # acl number 3003 rule 5 deny ip source 10.164.3.0 0.0.0.255 destination 10.164.9.9 0 time-range satime # traffic classifier c_market operator or precedence 5 if-match acl 3002 traffic classifier c_rd operator or precedence 10 if-match acl 3003 # traffic behavior b_market deny traffic behavior b_rd deny # traffic policy p_market classifier c_market behavior b_market traffic policy p_rd classifier c_rd behavior b_rd # interface Vlanif10 ip address 10.164.1.1 255.255.255.0 # interface Vlanif20 ip address 10.164.2.1 255.255.255.0 # interface Vlanif30 ip address 10.164.3.1 255.255.255.0 # interface Vlanif100 ip address 10.164.9.1 255.255.255.0 # interface GigabitEthernet1/0/1 port link-type access port default vlan 10 # interface GigabitEthernet1/0/2 port link-type access port default vlan 20 traffic-policy p_rd inbound # interface GigabitEthernet1/0/3 port link-type access port default vlan 30 traffic-policy p_rd inbound # interface GigabitEthernet2/0/1 port link-type access port default vlan 100 # return
介绍二层ACL的配置过程,包括配置二层ACL规则、配置流行为、流分类和流策略等。
如图5-284所示,Switch作为网关设备,下挂用户PC。要求配置ACL,禁止源MAC地址为00e0-f201-0101、目的MAC地址为0260-e207-0002的报文通过。
采用如下的思路配置二层ACL:
为完成此配置举例,需要准备如下数据:
# 配置符合要求的二层ACL。
[Quidway] acl 4000 [Quidway-acl-L2-4000] rule deny source-mac 00e0-f201-0101 ffff-ffff-ffff destination-mac 0260-e207-0002 ffff-ffff-ffff [Quidway-acl-L2-4000] quit
# 配置流分类tc1,对匹配ACL 4000的报文进行分类。
[Quidway] traffic classifier tc1 [Quidway-classifier-tc1] if-match acl 4000 [Quidway-classifier-tc1] quit
# 配置流行为tb1,动作为拒绝报文通过。
[Quidway] traffic behavior tb1 [Quidway-behavior-tb1] deny [Quidway-behavior-tb1] quit
# 配置流策略tp1,将流分类tc1与流行为tb1关联。
[Quidway] traffic policy tp1 [Quidway-trafficpolicy-tp1] classifier tc1 behavior tb1 [Quidway-trafficpolicy-tp1] quit
# 将流策略tp1应用到GE2/0/1接口。
[Quidway] interface gigabitethernet 2/0/1 [Quidway-GigabitEthernet2/0/1] traffic-policy tp1 inbound [Quidway-GigabitEthernet2/0/1] quit
# 查看ACL规则的配置信息。
display acl 4000 Ethernet frame ACL 4000, 1 rule Acl's step is 5 rule 5 deny source-mac 00e0-f201-0101 ffff-ffff-ffff destination-mac 0260-e207-0002 ffff-ffff-ffff(0 times matched)
# 查看流分类的配置信息。
display traffic classifier user-defined User Defined Classifier Information: Classifier: tc1 Precedence: 15 Operator: OR Rule(s) : if-match acl 4000
# 查看流策略的配置信息。
display traffic policy user-defined tp1 User Defined Traffic Policy Information: Policy: tp1 Classifier: default-class Behavior: be -none- Classifier: tc1 Behavior: tb1 Deny
#
acl number 4000
rule 5 deny source-mac 00e0-f201-0101 ffff-ffff-ffff destination-mac 0260-e207-0002 ffff-ffff-ffff
#
traffic classifier tc1 operator or precedence 15
if-match acl 4000
#
traffic behavior tb1
deny
#
traffic policy tp1
classifier tc1 behavior tb1
#
interface GigabitEthernet2/0/1
traffic-policy tp1 inbound
#
return
介绍用户自定义ACL的配置过程,包括配置用户自定义ACL规则、配置流行为、流分类和流策略等。
如图5-285所示,Switch的GE1/0/1接口连接用户,GE2/0/1接口连接上层路由器。要求在接口GE1/0/1下绑定用户自定义ACL,从二层报文头偏移14个字节开始匹配,拒绝匹配成功的报文通过,匹配的字符串内容为0x0180C200。
采用如下的思路配置用户自定义ACL:
为完成此配置举例,需要准备如下数据:
# 配置符合要求的用户自定义ACL。
[Quidway] acl 5000 [Quidway-acl-user-5000] rule deny l2-head 0x0180C200 0xFFFFFFFF 14 [Quidway-acl-user-5000] quit
# 配置流分类tc1,对匹配ACL 5000的报文进行分类。
[Quidway] traffic classifier tc1 [Quidway-classifier-tc1] if-match acl 5000 [Quidway-classifier-tc1] quit
# 配置流行为tb1,动作为拒绝报文通过。
[Quidway] traffic behavior tb1 [Quidway-behavior-tb1] deny [Quidway-behavior-tb1] quit
# 定义流策略,将流分类与流行为关联。
[Quidway] traffic policy tp1 [Quidway-trafficpolicy-tp1] classifier tc1 behavior tb1 [Quidway-trafficpolicy-tp1] quit
# 在接口GE1/0/1下应用流策略。
[Quidway] interface gigabitethernet 1/0/1 [Quidway-GigabitEthernet2/0/1] traffic-policy tp1 inbound [Quidway-GigabitEthernet2/0/1] quit
# 查看ACL规则的配置信息
display acl 5000 User ACL 5000, 1 rule Acl's step is 5 rule 5 permit 0x0180c200 0xffffffff 14
# 查看流分类的配置信息
display traffic classifier user-defined User Defined Classifier Information: Classifier: tc1 Precedence: 15 Operator: OR Rule(s) : if-match acl 5000
# 查看流策略的配置信息
display traffic policy user-defined tp1 User Defined Traffic Policy Information: Policy: tp1 Classifier: default-class Behavior: be -none- Classifier: tc1 Behavior: tb1 Deny
#
acl number 5000
rule 5 permit 0x0180c200 0xffffffff 14
#
traffic classifier tc1 operator or precedence 15
if-match acl 5000
#
traffic behavior tb1
deny
#
traffic policy tp1
classifier tc1 behavior tb1
#
interface GigabitEthernet1/0/1
traffic-policy tp1 inbound
#
return
介绍自反ACL的配置过程,包括配置高级ACL、使能接口下的自反ACL功能和配置自反ACL老化时间等。
如图5-286所示,Switch的接口GE1/0/1连接了内网的用户,接口GE2/0/1连接到Internet。在Switch的接口GE2/0/1的出方向上配置自反ACL功能,内网的主机先访问Internet中的服务器之后才允许Internet的服务器访问内网的主机。同时,在全局和接口GE2/0/1下配置自反ACL的老化时间,对自反ACL进行自动老化。
采用如下的思路配置自反ACL:
为完成此配置举例,需要准备以下数据:
system-view [Quidway] acl 3000 [Quidway-acl-adv-3000] rule permit udp [Quidway-acl-adv-3000] quit
[Quidway] interface gigabitethernet 2/0/1 [Quidway-GigabitEthernet2/0/1] traffic-reflect outbound acl 3000 timeout 600 [Quidway-GigabitEthernet2/0/1] quit
[Quidway] traffic-reflect timeout 900
如果接口上已经配置了自反ACL老化时间,则以接口上配置的时间为准;如果接口上没有配置自反ACL老化时间,则以该命令配置的全局老化时间为准。
在系统视图下执行display traffic-reflect命令可以查看自反ACL信息。
[Quidway] display traffic-reflect outbound acl 3000
Proto SP DP DIP SIP Count Timeout Interface
------------------------------------------------------------------------------
UDP 2 80 10.2.1.10 10.1.1.10 9 600(s) GigabitEthernet2/0/1
------------------------------------------------------------------------------
* Proto=Protocol,SIP=Source IP,DIP=Destination IP,Timeout=Time to cutoff,
* SP=Source port,DP=Destination port,Count=Packets count(data).
由显示信息可知,GE2/0/1接口下对UDP协议的报文进行了自反,并且对自反后的报文进行统计。
#
acl number 3000
rule 5 permit udp
#
interface GigabitEthernet2/0/1
traffic-reflect outbound acl 3000 timeout 600
#
traffic-reflect timeout 900
#
return
如图5-287所示,SwitchA通过GE接口与SwitchB相连。在SwitchA上配置ACL6规则,禁止源地址为3001::2/64的IPv6报文进入SwitchA的GE1/0/0接口。
采用如下的思路配置ACL6:
为完成此配置举例,需要准备如下数据:
# 配置SwitchA。
system-view [Quidway] sysname SwitchA [SwitchA] ipv6 [SwitchA] interface gigabitethernet 1/0/0 [SwitchA-GigabitEthernet1/0/0] port link-type trunk [SwitchA-GigabitEthernet1/0/0] port trunk allow-pass vlan 10 [SwitchA-GigabitEthernet1/0/0] quit [SwitchA] interface vlanif 10 [SwitchA-Vlanif10] ipv6 enable [SwitchA-Vlanif10] ipv6 address 3001::1 64 [SwitchA-Vlanif10] quit
# 配置SwitchA上的静态路由。
[SwitchA] ipv6 route-static 3002:: 64 3001::2
# 配置SwitchB。
system-view [Quidway] sysname SwitchB [SwitchB] ipv6 [SwitchB] interface loopback 2 [SwitchB-LoopBack2] ipv6 enable [SwitchB-LoopBack2] ipv6 address 3002::2 64 [SwitchB-LoopBack2] quit [SwitchB] interface gigabitethernet 1/0/0 [SwitchB-GigabitEthernet1/0/0] port link-type trunk [SwitchB-GigabitEthernet1/0/0] port trunk allow-pass vlan 10 [SwitchB-GigabitEthernet1/0/0] quit [SwitchB] interface vlanif 10 [SwitchB-Vlanif10] ipv6 enable [SwitchB-Vlanif10] ipv6 address 3001::2 64 [SwitchB-Vlanif10] quit
# 配置SwitchA。
[SwitchA] acl ipv6 number 3001 [SwitchA-acl6-adv-3001] rule deny ipv6 source 3001::2/64 [SwitchA-acl6-adv-3001] quit [SwitchA] traffic classifier class1 [SwitchA-classifier-class1] if-match ipv6 acl 3001 [SwitchA-classifier-class1] quit [SwitchA] traffic behavior behav1 [SwitchA-behavior-behav1] deny [SwitchA-behavior-behav1] quit [SwitchA] traffic policy policy1 [SwitchA-trafficpolicy-policy1] classifier class1 behavior behav1 [SwitchA-trafficpolicy-policy1] quit [SwitchA] interface gigabitethernet 1/0/0 [SwitchA-GigabitEthernet1/0/0] traffic-policy policy1 inbound [SwitchA-GigabitEthernet1/0/0] quit
# 查看ACL6的配置信息。
<SwitchA> display acl ipv6 3001
Advanced IPv6 ACL 3001, 1 rule
rule 0 deny ipv6 source 3001::2/64
# 查看流分类的配置信息。
<SwitchA> display traffic classifier user-defined
User Defined Classifier Information:
Classifier: class1
Precedence: 5
Operator: OR
Rule(s) : if-match IPv6 acl 3001
Total classifier number is 1
# 查看流策略的配置信息。
<SwitchA> display traffic policy user-defined
User Defined Traffic Policy Information:
Policy: policy1
Classifier: class1
Operator: OR
Behavior: behav1
Deny
Total policy number is 1
SwitchA的配置文件
# sysname SwitchA # ipv6 # acl ipv6 number 3001 rule 0 deny ipv6 source 3001::2/64 # traffic classifier class1 operator or if-match ipv6 acl 3001 # traffic behavior behav1 deny # traffic policy policy1 classifier class1 behavior behav1 # interface GigabitEthernet1/0/0 port link-type trunk port trunk allow-pass vlan 10 traffic-policy policy1 inbound # interface Vlanif10 ipv6 enable ipv6 address 3001::1/64 # ipv6 route-static 3002:: 64 3001::2 # return
SwitchB的配置文件
# sysname SwitchB # ipv6 # interface GigabitEthernet1/0/0 port link-type trunk port trunk allow-pass vlan 10 # interface Vlanif 10 ipv6 enable ipv6 address 3001::2/64 # interface LoopBack2 ipv6 enable ipv6 address 3002::2/64 # return