新聞中心
在日常工作中,企業(yè)員工一般是通過公司內(nèi)部的網(wǎng)關(guān)服務(wù)器來訪問互聯(lián)網(wǎng),當將Squid服務(wù)程序部署為公司網(wǎng)絡(luò)的網(wǎng)關(guān)服務(wù)器后,Squid服務(wù)程序的訪問控制列表(ACL)功能將發(fā)揮它的用武之地。它可以根據(jù)指定的策略條件來緩存數(shù)據(jù)或限制用戶的訪問。比如很多公司會分時段地禁止員工逛淘寶、打網(wǎng)頁游戲,這些禁止行為都可以通過Squid服務(wù)程序的ACL功能來實現(xiàn)。大家如果日后在人員流動較大的公司中從事運維工作,可以牢記本節(jié)內(nèi)容,在公司網(wǎng)關(guān)服務(wù)器上部署的Squid服務(wù)程序中添加某些策略條件,禁止員工訪問某些招聘網(wǎng)站或競爭對手的網(wǎng)站,沒準還能有效降低員工的流失率。

目前成都創(chuàng)新互聯(lián)已為上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)站空間、網(wǎng)站運營、企業(yè)網(wǎng)站設(shè)計、汝州網(wǎng)站維護等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。
Squid服務(wù)程序的ACL是由多個策略規(guī)則組成的,它可以根據(jù)指定的策略規(guī)則來允許或限制訪問請求,而且策略規(guī)則的匹配順序與防火墻策略規(guī)則一樣都是由上至下;在一旦形成匹配之后,則立即執(zhí)行相應(yīng)操作并結(jié)束匹配過程。為了避免ACL將所有流量全部禁止或全部放行,起不到預(yù)期的訪問控制效果,運維人員通常會在ACL的最下面寫上deny all或者allow all語句,以避免安全隱患。
劉遄老師將通過下面的4個實驗向大家演示Squid服務(wù)程序的ACL功能有多么強大。
實驗1:只允許IP地址為192.168.10.20的客戶端使用服務(wù)器上的Squid服務(wù)程序提供的代理服務(wù),禁止其余所有的主機代理請求。
下面的配置文件依然是Squid服務(wù)程序的配置文件,但是需要留心配置參數(shù)的填寫位置。如果寫的太靠前,則有些Squid服務(wù)程序自身的語句都沒有加載完,也會導(dǎo)致策略無效。當然也不用太靠后,大約在26~32行的位置就可以,而且采用分行填寫的方式也便于日后的修改。
[root@linuxprobe ~]# vim /etc/squid/squid.conf
1 #
2 # Recommended minimum configuration:
3 #
4
5 # Example rule allowing access from your local networks.
6 # Adapt to list your (internal) IP networks from where browsing
7 # should be allowed
8 acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
9 acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
10 acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
11 acl localnet src fc00::/7 # RFC 4193 local private network range
12 acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) mac hines
13
14 acl SSL_ports port 443
15 acl Safe_ports port 80 # http
16 acl Safe_ports port 21 # ftp
17 acl Safe_ports port 443 # https
18 acl Safe_ports port 70 # gopher
19 acl Safe_ports port 210 # wais
20 acl Safe_ports port 1025-65535 # unregistered ports
21 acl Safe_ports port 280 # http-mgmt
22 acl Safe_ports port 488 # gss-http
23 acl Safe_ports port 591 # filemaker
24 acl Safe_ports port 777 # multiling http
25 acl CONNECT method CONNECT
26 acl client src 192.168.10.20
27 #
28 # Recommended minimum Access Permission configuration:
29 #
30 # Deny requests to certain unsafe ports
31 http_access allow client
32 http_access deny all
33 http_access deny !Safe_ports
34
[root@linuxprobe ~]# systemctl restart squid上面的配置參數(shù)其實很容易理解。首先定義了一個名為client的別名。這其實類似于13.6節(jié)講解的DNS分離解析技術(shù),當時我們分別定義了兩個名為china與american的別名變量,這樣當再遇到這個別名時也就意味著與之定義的IP地址了。保存配置文件后重啟Squid服務(wù)程序,這時由于客戶端主機的IP地址不符合我們的允許策略而被禁止使用代理服務(wù),如圖16-8所示。
圖16-8 使用代理服務(wù)瀏覽網(wǎng)頁失敗
實驗2:禁止所有客戶端訪問網(wǎng)址中包含linux關(guān)鍵詞的網(wǎng)站。
Squid服務(wù)程序的這種ACL功能模式是比較粗獷暴力的,客戶端訪問的任何網(wǎng)址中只要包含了某個關(guān)鍵詞就會被立即禁止訪問,但是這并不影響訪問其他網(wǎng)站。
[root@linuxprobe ~]# vim /etc/squid/squid.conf
1 #
2 # Recommended minimum configuration:
3 #
4
5 # Example rule allowing access from your local networks.
6 # Adapt to list your (internal) IP networks from where browsing
7 # should be allowed
8 acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
9 acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
10 acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
11 acl localnet src fc00::/7 # RFC 4193 local private network range
12 acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) mac hines
13
14 acl SSL_ports port 443
15 acl Safe_ports port 80 # http
16 acl Safe_ports port 21 # ftp
17 acl Safe_ports port 443 # https
18 acl Safe_ports port 70 # gopher
19 acl Safe_ports port 210 # wais
20 acl Safe_ports port 1025-65535 # unregistered ports
21 acl Safe_ports port 280 # http-mgmt
22 acl Safe_ports port 488 # gss-http
23 acl Safe_ports port 591 # filemaker
24 acl Safe_ports port 777 # multiling http
25 acl CONNECT method CONNECT
26 acl deny_keyword url_regex -i linux
27 #
28 # Recommended minimum Access Permission configuration:
29 #
30 # Deny requests to certain unsafe ports
31 http_access deny deny_keyword
33 http_access deny !Safe_ports
34
[root@linuxprobe ~]# systemctl restart squid劉遄老師建議大家在進行實驗之前,一定要先把前面實驗中的代碼清理干凈,以免不同的實驗之間產(chǎn)生沖突。在當前的實驗中,我們直接定義了一個名為deny_keyword的別名,然后把所有網(wǎng)址帶有l(wèi)inux關(guān)鍵詞的網(wǎng)站請求統(tǒng)統(tǒng)拒絕掉。當客戶端分別訪問帶有l(wèi)inux關(guān)鍵詞和不帶有l(wèi)inux關(guān)鍵詞的網(wǎng)站時,其結(jié)果如圖16-9所示。
圖16-9 當客戶端分別訪問帶有l(wèi)inux關(guān)鍵詞和不帶linux關(guān)鍵詞的網(wǎng)站時,所呈現(xiàn)的結(jié)果
實驗3:禁止所有客戶端訪問某個特定的網(wǎng)站。
在實驗2中,由于我們禁止所有客戶端訪問網(wǎng)址中包含linux關(guān)鍵詞的網(wǎng)站,這將造成一大批網(wǎng)站被誤封,從而影響同事們的正常工作。其實通過禁止客戶端訪問某個特定的網(wǎng)址,也就避免了誤封的行為。下面按照如下所示的參數(shù)配置Squid服務(wù)程序并重啟,然后進行測試,其測試結(jié)果如圖16-10所示。
[root@linuxprobe ~]# vim /etc/squid/squid.conf
24 acl Safe_ports port 777 # multiling http
25 acl CONNECT method CONNECT
26 acl deny_url url_regex http://www.linuxcool.com
27 #
28 # Recommended minimum Access Permission configuration:
29 #
30 # Deny requests to certain unsafe ports
31 http_access deny deny_url
33 http_access deny !Safe_ports
34
[root@linuxprobe ~]# systemctl restart squid
圖16-10 無法使用代理服務(wù)訪問這個特定的網(wǎng)站
實驗4:禁止員工在企業(yè)網(wǎng)內(nèi)部下載帶有某些后綴的文件。
在企業(yè)網(wǎng)絡(luò)中,總會有一小部分人利用企業(yè)網(wǎng)絡(luò)的高速帶寬私自下載資源(比如游戲安裝文件、電影文件等),從而對其他同事的工作效率造成影響。通過禁止所有用戶訪問.rar或.avi等后綴文件的請求,可以防止他們繼續(xù)下載資源,讓他們知難而退。下面按照如下所示的參數(shù)配置Squid服務(wù)程序并重啟,然后進行測試,其測試結(jié)果如圖16-11所示。
如果這些員工是使用迅雷等P2P下載軟件來下載資源的話,就只能使用專業(yè)級的應(yīng)用防火墻來禁止了。
[root@linuxprobe ~]# vim /etc/squid/squid.conf
24 acl Safe_ports port 777 # multiling http
25 acl CONNECT method CONNECT
26 acl badfile urlpath_regex -i \.mp3$ \.rar$
27 #
28 # Recommended minimum Access Permission configuration:
29 #
30 # Deny requests to certain unsafe ports
31 http_access deny badfile
33 http_access deny !Safe_ports
34
[root@linuxprobe ~]# systemctl restart squid
圖16-11 無法使用代理服務(wù)下載具有指定后綴的文件
網(wǎng)頁標題:創(chuàng)新互聯(lián)linux教程:16.3.2ACL訪問控制
當前鏈接:http://www.dlmjj.cn/article/coshihh.html


咨詢
建站咨詢
