用訪問控制列表(ACL)實現包過濾
一.ACL概述
1.ACL(Access Control List,訪問控制列表)是用來實現數據包識別功能的
2.ACL可以應用於諸多方面
a>.b包過濾防火牆功能;
b>.NAT(Network Address Translation,網絡地址轉換);
c>.QoS(Quality of Service,服務質量)的數據分類;
d>.路由策略和過濾
e>.按需撥號
二.ACL包過濾原理
1.基於ACL的包過濾技術
a>.對進入的數據包逐個過濾,丟棄或允許通過;
b>.ACL應用於接口上,每個接口的出入雙向分別過濾;
c>.僅當數據包過濾經過一個接口是時,才會被此接口的此方向的ACL過濾;
2.入站包過濾工作流程
3.出站包過濾工作流程
4.通配符掩碼
a>.通配符掩碼和IP地址結合使用以描述一個地址范圍;
b>.通配符和子網掩碼相思,但含義不同:0表示對應位需要比較,1表示對應為不需要比較。
5. 通配符掩碼的應用示例
三.ACL分類
1.ACL的標識
a>.利用數字需要標識訪問控制列表;
詳細介紹:
1>.標准2000-2999:檢查數據包的源,根據數據包的源IP指定規則,允許或拒絕的是整個數據包的IP;(屬於基本ACL)
2>.擴展3000-3999:根據報文的源IP地址信息,目的IP地址信息,IP承載的協議類型,協議的特性等三,四層信息指定規則;(屬於高級ACL)
3>.二層ACL 4000-4999:根據報文的源MAC地址,目的MAC地址,VLAN優先級,二層協議類型等二層信息指定規則。
4>.用戶自定義ACL 5000-5999:可以以報文頭,IP頭等位基准,指定從第幾個字節開始於掩碼進行“與”操作,將報文提取出來的字符串和用戶定義的字符串進行比較,找到匹配的報文。
b>.可以給訪問控制列表指定名稱,便於維護;
四.配置ACL包過濾
在做實驗之前,需要將以下拓撲圖兩個機房配置通:
准備環境:要求亦庄機房的PC可以ping同高碑店的pc,我們可以用OSPF來做,配置過程如下:

1 "亦庄出口路由"配置如下: 2 [Huawei]sysname yizhuang 3 [yizhuang]interface Ethernet 0/0/0 4 [yizhuang-Ethernet0/0/1]ip address 172.30.1.254 24 5 [yizhuang-Ethernet0/0/1]undo shutdown 6 [yizhuang-Ethernet0/0/1]quit 7 [yizhuang]interface Ethernet 0/0/1 8 [yizhuang-Ethernet0/0/1]ip address 10.10.10.1 24 9 [yizhuang-Ethernet0/0/1]undo shutdown 10 [yizhuang-Ethernet0/0/1]quit 11 [yizhuang]ospf 200 12 [yizhuang-ospf-200]area 0 13 [yizhuang-ospf-200-area-0.0.0.0]network 10.10.10.1 0.0.0.0 14 [yizhuang-ospf-200-area-0.0.0.0]network 172.30.1.0 0.0.0.255 15 [yizhuang-ospf-200-area-0.0.0.0]quit 16 [yizhuang-ospf-200]quit 17 18 "高碑店出口路由"配置如下: 19 [Huawei]sysname gaobeidian 20 [gaobeidian]interface Ethernet 0/0/0 21 [gaobeidian-Ethernet0/0/0]ip address 192.168.1.254 24 22 [gaobeidian-Ethernet0/0/0]undo shutdown 23 [gaobeidian]interface Ethernet 0/0/1 24 [gaobeidian-Ethernet0/0/1]ip address 10.10.10.2 24 25 [gaobeidian-Ethernet0/0/1]undo shutdown 26 [gaobeidian-Ethernet0/0/1]quit 27 [gaobeidian]ospf 100 28 [gaobeidian-ospf-100]area 0 29 [gaobeidian-ospf-100-area-0.0.0.0]network 10.10.10.2 0.0.0.0 30 [gaobeidian-ospf-100-area-0.0.0.0]network 192.168.1.0 0.0.0.255 31 [gaobeidian-ospf-100-area-0.0.0.0]quit

1 PC>ipconfig 2 3 Link local IPv6 address...........: fe80::5689:98ff:fe15:18c0 4 IPv6 address......................: :: / 128 5 IPv6 gateway......................: :: 6 IPv4 address......................: 172.30.1.1 7 Subnet mask.......................: 255.255.255.0 8 Gateway...........................: 172.30.1.254 9 Physical address..................: 54-89-98-15-18-C0 10 DNS server........................: 11 12 PC> 13 PC>ping 192.168.1.1 14 15 Ping 192.168.1.1: 32 data bytes, Press Ctrl_C to break 16 From 192.168.1.1: bytes=32 seq=1 ttl=126 time=62 ms 17 From 192.168.1.1: bytes=32 seq=2 ttl=126 time=62 ms 18 From 192.168.1.1: bytes=32 seq=3 ttl=126 time=32 ms 19 From 192.168.1.1: bytes=32 seq=4 ttl=126 time=62 ms 20 From 192.168.1.1: bytes=32 seq=5 ttl=126 time=31 ms 21 22 --- 192.168.1.1 ping statistics --- 23 5 packet(s) transmitted 24 5 packet(s) received 25 0.00% packet loss 26 round-trip min/avg/max = 31/49/62 ms 27 28 PC>
需求一:要求亦庄機房pc無法ping通高碑店機房pc.
我們在離高碑店機房pc的上聯路由或者交換機上做配置即可:
華為機器配置如下:
1 [gaobeidian]acl 2000 #定義基本策略 2 [gaobeidian-acl-basic-2000]rule 0 deny source 172.30.1.1 0.0.0.0 #寫一條拒絕的規則 3 [gaobeidian-acl-basic-2000]quit 4 [gaobeidian]traffic classifier deny_icmp #創建策略 5 [gaobeidian-classifier-deny_icmp]if-match acl 2000 #和條件綁定 6 [gaobeidian-classifier-deny_icmp]quit 7 [gaobeidian]traffic behavior deny #創建一個策略的動作, 8 [gaobeidian-behavior-deny]quit 9 [gaobeidian]traffic policy xianzhi #創建一個策略組 10 [gaobeidian-trafficpolicy-xianzhi]classifier deny_icmp behavior deny #關聯策略和動作 11 [gaobeidian-trafficpolicy-xianzhi]quit 12 [gaobeidian]interface Ethernet 0/0/1 13 [gaobeidian-Ethernet0/0/1]traffic-policy xianzhi inbound #在相應的如接口調用策略組
H3C配置如下:(你會發現這2個差距並不是很大,原理都是一樣的)

1 firewall enable #啟用防火牆 2 firewall default permit #設置默認規則為允許 3 acl number 2000 4 rule 0 deny source 172.30.1.1 0.0.0.0 5 quit 6 interface Ethenet 0/0/1 7 firewall packer-filter 2000 inbound #綁定策略
實驗測試結果如下:
1 PC>ping 192.168.1.1 2 3 Ping 192.168.1.1: 32 data bytes, Press Ctrl_C to break 4 From 192.168.1.1: bytes=32 seq=1 ttl=126 time=93 ms 5 From 192.168.1.1: bytes=32 seq=2 ttl=126 time=109 ms 6 From 192.168.1.1: bytes=32 seq=3 ttl=126 time=93 ms 7 From 192.168.1.1: bytes=32 seq=4 ttl=126 time=62 ms 8 From 192.168.1.1: bytes=32 seq=5 ttl=126 time=78 ms 9 10 --- 192.168.1.1 ping statistics --- 11 5 packet(s) transmitted 12 5 packet(s) received 13 0.00% packet loss 14 round-trip min/avg/max = 62/87/109 ms 15 16 PC>ping 192.168.1.1 17 18 Ping 192.168.1.1: 32 data bytes, Press Ctrl_C to break 19 Request timeout! 20 Request timeout! 21 Request timeout! 22 Request timeout! 23 Request timeout! 24 25 --- 192.168.1.1 ping statistics --- 26 5 packet(s) transmitted 27 0 packet(s) received 28 100.00% packet loss 29 30 PC>ipconfig 31 32 Link local IPv6 address...........: fe80::5689:98ff:fe80:32ad 33 IPv6 address......................: :: / 128 34 IPv6 gateway......................: :: 35 IPv4 address......................: 172.30.1.1 36 Subnet mask.......................: 255.255.255.0 37 Gateway...........................: 172.30.1.254 38 Physical address..................: 54-89-98-80-32-AD 39 DNS server........................: 40 41 PC>
注意:
可能ENSP模擬的路由器在寫ACL上存在BUG,我這里建議更換交換機測試,或者在路由器和電腦之前加個交換機,在交換機上做策略也好使,已經實測。
需求二.使得亦庄路由器無法telnet高碑店路由器.
拓撲圖如下:
配置過程如下:
1 #高碑店路由器配置: 2 [gaobeidain]telnet server enable 3 [gaobeidain]user-interface vty 0 4 4 [gaobeidain-ui-vty0-4]authentication-mode none 5 [gaobeidain-ui-vty0-4]user privilege level 3 6 7 8 #亦庄路由器測試: 9 <Huawei>telnet 10.10.10.2 10 Trying 10.10.10.2 ... 11 Press CTRL+K to abort 12 Connected to 10.10.10.2 ... 13 14 Info: The max number of VTY users is 10, and the number 15 of current VTY users on line is 1. 16 The current login time is 2017-04-19 00:15:06. 17 <gaobeidain> 18 19 “三層交換機”配置如下: 20 [Huawei]acl number 3000 21 [Huawei-acl-adv-3000]rule 0 deny tcp source 10.10.10.1 0 destination 10.10.10.2 0 destination-port eq 22 telnet #拒絕訪問10.10.10.2的路由器的telnet功能 23 [Huawei-acl-adv-3000]quit 24 [Huawei]traffic classifier deny_telnet 25 [Huawei-classifier-deny_telnet]if-match acl 3000 26 [Huawei-classifier-deny_telnet]quit 27 [Huawei]traffic behavior deny #定義一個動作 28 [Huawei-behavior-deny]quit #動作內容為空,直接退出即可 29 [Huawei]traffic policy xianzhi 30 [Huawei-trafficpolicy-xianzhi]classifier deny_telnet behavior deny 31 [Huawei-trafficpolicy-xianzhi]quit
拓撲圖如下:
准備環境:
1 “魯谷機房”配置如下: 2 [Huawei]sysname lugu 3 [lugu]interface Ethernet 0/0/1 4 [lugu-Ethernet0/0/1]ip address 10.10.10.2 24 5 [lugu-Ethernet0/0/1]quit 6 [lugu]interface LoopBack 1 7 [lugu-LoopBack1]ip address 192.168.1.1 24 8 [lugu-LoopBack1]quit 9 [lugu]ip route-static 0.0.0.0 0.0.0.0 10.10.10.1 10 [lugu]user-interface vty 0 4 11 [lugu-ui-vty0-4]authentication-mode none 12 [lugu-ui-vty0-4]user privilege level 3 13 14 15 "策略交換機"配置如下: 16 [Huawei]sysname celue 17 [celue]interface Ethernet 0/0/1 18 [celue-Ethernet0/0/1]port link-type trunk 19 [celue-Ethernet0/0/1]quit 20 21 22 “兆維機房”配置如下: 23 [Huawei]sysname zhaowei 24 [zhaowei]interface LoopBack 1 25 [zhaowei-LoopBack1]ip address 172.30.1.1 24 26 [zhaowei-LoopBack1]quit 27 [zhaowei]interface Ethernet 0/0/1 28 [zhaowei-Ethernet0/0/1]ip address 10.10.10.1 24 29 [zhaowei-Ethernet0/0/1]undo shutdown 30 [zhaowei-Ethernet0/0/1]quit 31 [zhaowei]ip route-static 0.0.0.0 0.0.0.0 10.10.10.2 32 <zhaowei>telnet 192.168.1.1 #鏈接魯谷機房pc 33 Trying 192.168.1.1 ... 34 Press CTRL+K to abort 35 Connected to 192.168.1.1 ... 36 37 Info: The max number of VTY users is 10, and the number 38 of current VTY users on line is 1. 39 The current login time is 2017-04-19 11:11:19. 40 <lugu>
策略限制如下:
1 “魯谷機房”配置如下: 2 3 [lugu]acl 3000 4 [lugu-acl-adv-3000]rule 0 deny tcp source 172.30.1.1 0 5 6 destination 192.168.1.1 0 destination-port eq 7 telnet #定義一條拒絕telnet的策略 8 [lugu]user-interface vty 0 4 9 [lugu-ui-vty0-4]authentication-mode none #驗證方式為空 10 [lugu-ui-vty0-4]acl 3000 inbound #綁定策略
測試結果如下:
1 <zhaowei>telnet 192.168.1.1 2 Trying 192.168.1.1 ... 3 Press CTRL+K to abort 4 Error: Failed to connect to the remote host. 5 <zhaowei>
以上操作用的是ENSP配置,如果要配置H3C的話請參考:
實驗十 配置ACL包過濾
【實驗目的】
l 掌握訪問控制列表的簡單的工作原理
l 掌握訪問控制列表的基本配置方法
l 掌握訪問控制列表的常用配置命令
【實驗要求】
分別使用ACL禁止PC1訪問PC2和禁止從PC1到網絡192.168.3.0/24的FTP數據流。
【實驗設備】
路由器兩台、PC機兩台、網線三根、console
【實驗拓撲】
【實驗過程】
實驗過程一、配置基本的ACL
1、路由器接口IP地址以及PC機的IP地址規划
設備名稱 |
接口 |
IP地址 |
網關 |
RT1 |
G0/0/1 |
192.168.1.1 |
-- |
G0/0/0 |
192.168.2.1 |
-- |
|
looback |
1.1.1.1.1/32 |
|
|
RT2 |
G0/0/0 |
192.168.2.2 |
-- |
G0/0/1 |
192.168.3.1 |
-- |
|
looback |
2.2.2.2./32 |
|
|
PC1 |
-- |
192.168.1.2 |
192.168.1.1 |
PC2 |
-- |
192.168.3.2 |
192.168.3.1 |
2、使用RIP協議使全網互通(也可以使用OSPF以及靜態路由)
RT1
[RT1]rip
[RT1-rip-1]network 192.168.1.0
[RT1-rip-1]network 192.168.2.0
[RT1-rip-1]quit
[RT1]
RT2
[RT2]rip
[RT2-rip-1]network 192.168.2.0
[RT2-rip-1]network 192.168.3.0
[RT2-rip-1]quit
[RT2]
3、PC1 ping PC2驗證網絡的連通性
4、配置ACL並且應用
防火牆功能需要在路由器上啟動后才能生效
[RT1]firewall enable
設置防火牆的默認過濾方式是Permit
[RT1]firewall default permit
配置基本ACL,並指定ACL序號
[RT1]acl number 2000
定義ACL定義規則
[RT1-acl-basic-2000]rule deny source 192.168.1.2 0.0.0.0[w1]
[RT1-acl-basic-2000]quit
進入接口並在接口上應用接口上
[RT1]interface g0/0/1
[RT1-GigabitEthernet0/0/1]firewall packet-filter 2000 inbound[w2]
[RT1-GigabitEthernet0/0/1]qu
[RT1]
5、PC1 ping PC2測試主機間的連通性,測試結果應該是不可達,如下
6、查看ACL以及防火牆的狀態和統計
可以看到,有數據報文命中了ACL中定義的額規則。
實驗過程二 配置擴展的ACL
1、PC組網圖和IP地址規划同實驗一基本的ACL
2、配置ACL規則
[RT1]acl number 3000
[RT1-acl-adv-3000]rule deny tcp source 192.168.1.2 0.0.0.0 destination 192.168.3.0 0.0.0.255 destination-port eq ftp
[RT1-acl-adv-3000]rule permit ip source 192.168.1.2 0.0.0.0 destination 192.168.2.0 0.0.0.255
[RT1-acl-adv-3000]quit
[RT1]interface g0/0/1
[RT1-GigabitEthernet0/0/1]firewall packet-filter 3000 inbound
[RT1-GigabitEthernet0/0/1]quit
[RT1]
3、做完之后銅須門可以自己試一下PC1 ping PC2能否ping通,如果能ping通過則說明什么?
4、在PC2上開啟FTP服務,然后再PC1上使用FTP客戶端軟件連接到PC2,看一下結果是被拒絕還是允許?
【思考拓展】
在實驗二高級ACL應用中,可以把ACL應用在RTB上嗎?
指定動作是Permit揮着Deny
制定要匹配的源IP地址范圍
Inbound:過濾接口接收的數據包
Outbound :過濾接口轉發的數據包
五.ACL包過濾的注意事項