ACL概述

随着网络的飞速发展,网络安全和网络服务质量QoS(Quality of Service)问题日益突出。访问控制列表(ACL,Access Control List)是与其紧密相关的一个技术。

ACL可以通过对网络中波报文流的精确识别,与其他技术结合,达到控制网络访问行为、防止网络攻击和提高网络带宽利用率的目的,从而切实保障网络环境的安全性和网络服务质量的可靠性。

ACL是由一系列permit或deny语句组成的、有序规则的列表。

ACL是一个匹配工具,能够对报文进行匹配和区分。

ACL的应用场景如下:

  • 匹配IP流量
  • 在Traffic-filter中被调用
  • 在NAT(Network Address Translation)中被调用
  • 在路由策略中被调用
  • 在防火墙的策略部署中被调用
  • 在QoS中被调用

报文五元组:源IP地址、目的IP地址、源端口、目的端口、协议类型。

image-1

ACL的基本概念和工作原理

ACL的组成

ACL由若干条permit或deny语句组成。每条语句就是该ACL的一条规则,每条语句中的permit或deny就是与这条规则相对应的处理动作。

image-2

规则编号

规则编号(Rule ID):一个ACL中的每一条规则都有一个相应的编号。

步长(Step):步长是系统自动为ACL规则分配编号时,每个相邻规则编号之间的差值,缺省值为5。步长的作用是为了方便后续在旧规则之间插入新的规则。

Rule ID分配规则:系统为ACL中首条未手工指定编号的规则分配编号时,使用步长值(例如步长=5,首条规则编号为5)作为该规则的起始编号;为后续规则分配编号时,则使用大于当前ACL内最大规则编号且是步长整数倍的最小整数作为规则编号。

image-3

ACL的分裂与标识

  • 基于ACL规则定义方式的分类
分类 编号范围 规则定义描述
基本ACL 2000~2999 仅使用报文的源IP地址、分片信息和生效时间段来定义规则
高级ACL 3000~3999 可使用IPv4报文的源IP地址、目的IP地址、IP协议类型、ICMP类型、TCP源/目的端口号、UDP源/目的端口号、生效时间段等来自定义规则。
二层ACL 4000~4999 使用报文的以太网帧头信息来自定义规则,如根据源MAC地址、目的MAC地址、二层协议类型等。
用户自定义ACL 5000~5999 使用报文头、偏移位置、字符串掩码和用户自定义字符串来定义规则。
用户ACL 6000~6999 既可使用IPv4报文的源IP地址或源UCL(User Control List)组,也可使用目的IP地址或目的UCL组、IP协议类型、ICMP类型、TCP源端口/目的端口、UDP源端口/目的端口号等来自定义规则。
  • 基于ACL标识方法的分类
分类 规则定义描述
数字型ACL 传统的ACL标识方法。创建ACL是,指定一个唯一的数字标识该ACL。
命名型ACL 通过名称代替编号来标识ACL。

ACL的匹配位置

根据报文的流向,确定出站和入站的方向。

image-4

ACL的基础配置及应用

案例

配置需求:

在Router上部署基本ACL后,ACL将试图穿越Router的源地址为192.168.1.0/24网段的数据包过滤掉,并放行其他流量,从而禁止192.168.1.0/24网段的用户访问Router右侧的服务器网络。

image-5

1.Router已完成IP地址和路由的相关配置

2.在Router上创建基本ACL,禁止192.168.1.0/24网段访问服务器网络。

1
2
3
acl 2000
rule deny source 192.168.1.0 0.0.0.255
rule permit source any

3.由于从接口GE0/0/1进入Router,所以在接口GE0/0/1的入方向配置流量过滤。

1
2
3
int g0/0/1
traffic-filter inbound acl 2000
quit

image-6

1、配置基本ACL,实现client1能访问server1,client2不能访问server1

SW1配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
sys
sysname SW1
undo info-center enable
vlan batch 2 10 20
int g0/0/1
port link-type access
port default vlan 10
int g0/0/2
port link-type access
port default vlan 20
int vlanif 10
ip add 10.0.10.254 24
int vlanif 20
ip add 10.0.20.254 24
int vlanif 2
ip 10.0.11.1 24
int g0/0/3
port link-type access
port default vlan 2
quit
ospf 1
area 0
network 10.0.10.254 0.0.0.0
network 10.0.20.254 0.0.0.0
network 10.0.11.1 0.0.0.0
quit
quit

AR1配置

1
2
3
4
5
6
7
8
9
10
11
12
13
sys
sysname AR1
int g0/0/0
ip add 10.0.11.254 24
int g0/0/1
ip add 10.0.12.1 24
quit
ospf 1
area 0
network 10.0.11.254 0.0.0.0
network 10.0.12.1 0.0.0.0
quit
quit

AR2配置

1
2
3
4
5
6
7
8
9
10
11
12
13
sys
sysname AR2
int g0/0/0
ip add 10.0.12.2 24
int g0/0/1
ip add 10.0.30.254 24
quit
ospf 1
area 0
network 10.0.12.2 0.0.0.0
network 10.0.30.254 0.0.0.0
quit
quit

SW1配置ACL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[SW1]acl 2000
[SW1-acl-basic-2000]rule permit source 10.0.10.0 0.0.0.255
[SW1-acl-basic-2000]rule deny source 10.0.20.0 0.0.0.255
[SW1-acl-basic-2000]dis this
#
acl number 2000
rule 5 permit source 10.0.10.0 0.0.0.255
rule 10 deny source 10.0.20.0 0.0.0.255
#
return
[SW1-acl-basic-2000]quit
[SW1]int g0/0/3
[SW1-GigabitEthernet0/0/3]traffic-filter outbound acl 2000
[SW1-GigabitEthernet0/0/3]quit

验证测试

client1访问server1

image-7

client2访问server1

image-8

2、配置高级ACL实现client1只能够访问server1的http服务,client2只能够访问server1的ftp服务

在ensp模拟器的交换机中使用高级acl设置会有bug,但是真机不会有,目前实验的高级acl配置改在AR1上进行。

AR1配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
[AR1]acl 3000
[AR1-acl-adv-3000]rule den
[AR1-acl-adv-3000]rule deny ?
<1-255> Protocol number
gre GRE tunneling(47)
icmp Internet Control Message Protocol(1)
igmp Internet Group Management Protocol(2)
ip Any IP protocol
ipinip IP in IP tunneling(4)
ospf OSPF routing protocol(89)
tcp Transmission Control Protocol (6)
udp User Datagram Protocol (17)
[AR1-acl-adv-3000]rule deny tcp source 10.0.10.0 0.0.0.255 destination 10.0.30.1
0 destination-port eq 21
[AR1-acl-adv-3000]rule deny tcp source 10.0.20.0 0.0.0.255 destination 10.0.30.1
0 destination-port eq 80
[AR1-acl-adv-3000]dis this
[V200R003C00]
#
acl number 3000
rule 5 deny tcp source 10.0.10.0 0.0.0.255 destination 10.0.30.1 0 destination-
port eq ftp
rule 10 deny tcp source 10.0.20.0 0.0.0.255 destination 10.0.30.1 0 destination
-port eq www
#
return
[AR1]int g0/0/1
[AR1-GigabitEthernet0/0/1]traffic-filter outbound acl 3000

验证测试

client1访问server1的ftp服务

image-9

client1访问server1的http服务

image-10

client2访问server1的http服务

image-11

client2访问server1的ftp服务

image-12

如果想要某个时间段进行访问或者某个时间段禁止访问可以设置time-range。

设置一个每天的time-range,时间段为凌晨12点到晚上6点,在高级a

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[AR1]time-range daily-policy ?
<hh:mm> Starting time
from The beginning point of the time range
[AR1]time-range daily-policy 00:00 ?
to The ending point of periodic time-range
[AR1]time-range daliy-policy 00:00 to 18:00 ?
<0-6> Day of the week(0 is Sunday)
Fri Friday
Mon Monday
Sat Saturday
Sun Sunday
Thu Thursday
Tue Tuesday
Wed Wednesday
daily Every day of the week
off-day Saturday and Sunday
working-day Monday to Friday
[AR1]time-range daily-policy 00:00 to 18:00 daily
[AR1]acl 3000
[AR1-acl-adv-3000]rule permit tcp source 10.0.10.0 0.0.0.255 destination 10.0.30
.0 0 destination-port eq 80 time-range daliy-policy