« 在 XP Home Edition 安裝 IIS | 首頁 | Vista Transformation Pack »

2006年12月22日

squid.conf ACL Tag 備忘

環境: squid v2.5 as Transparent Proxy

acl 基本語法

acl aclname acltype string1 ...

acl aclname acltype "file" ...

常用的 acltype 有: src、time、dstdomain、url_regex...

直接寫參數: acl aclname acltype string1 string2 string3 (所有參數都在同一列)

以檔案代入的寫法: acl aclname acltype "/path/filename"
檔案內容: (一個項目獨立於一列)

string1
string2
string3

定義區域網路來源 IP 與目的 IP

語法

acl aclname src ip-address/netmask (clients IP address)

acl aclname src addr1-addr2/netmask (range of address)

acl aclname dst ip-address/netmask (URL host's IP address)

acl aclname arp mac-address (xx:xx:xx:xx:xx:xx notation)

範例

acl mylan src 192.168.0.0/16 #內部網路網段

acl special_user src 192.168.1.100-192.168.1.199/32 #一段內部 IP

acl badip dst 207.46.196.123/32 #www.windowsmedia.com 的 IP

acl baduser arp 00:11:22:33:44:55 #mac address

定義時間區段

語法

acl aclname time [day-abbrevs] [h1:m1-h2:m2]

h1:m1 必須小於 h2:m2

day-abbrevs:

S - Sunday 星期日
M - Monday 星期一
T - Tuesday 星期二
W - Wednesday 星期三
H - Thursday 星期四
F - Friday 星期五
A - Saturday 星期六

範例

acl oftime time MTWHF 8:00-17:30 #上班時間

acl bktime time 12:00-13:30 #中午午休時間

說明

MTWHF 表示星期一 ~ 星期五

省略 day-abbrevs 表示不設限星期幾

過濾上網網址

語法

#只檢查 URL 中 domain 的部份
acl aclname dstdomain .foo.com ...

#只要 URL 任一段內容符合即成立; -i 表示忽略大小寫
acl aclname url_regex [-i] regexp ...

範例

acl badserver dstdomain www.jianghu.info .love21cn.com .ttplayer.com
acl badurl url_regex -i gateway.dll sqmserver.dll meebo \.wma$ \.mp3$ \.mpg$

說明

.love21cn.com 表示 *.love21cn.com

\.mp3$ 應用於 http_access deny 表示禁止從網頁下載 mp3 檔案

其他 acl 運用

#禁止上傳檔案
acl aclname req_mime_type -i multipart/form-data

#禁止 IE 瀏覽器
acl aclname browser -i msie

#指定回應的訊息
#Usage: deny_info err_page_name acl (error page 使用 error_directory 定義)
#error_directory /usr/share/squid/errors/English → 繁體中文為 Traditional_Chinese
deny_info ERR_CUSTOM_MESSAGE badserver oftime

ps. 以上需配合 http_access deny aclname; deny_info 的 aclname 表示方法與 http_access 相同, 上例 badserver oftime 意為 badserver AND oftime (兩者須同時成立)

以 http_access 引用 acl 規則

語法

http_access allow|deny [!]aclname ...

兩個 aclname 以上者以空白隔開, 邏輯關係為 AND

範例 (acl 定義如前述)

#中午午休時間不設限
http_access allow mylan bktime

#上班時間禁止連入 badserver 所定義之網站
http_access deny badserver oftime

#上班時間過濾 URL 內容
http_access deny badurl oftime

#允許內部網路上網
http_access allow mylan

#不符合上列條件者全部禁止上網
http_access deny all


參考資料:

相關網頁:

Posted by Jamyy at 2006年12月22日 10:25

Trackback Pings

TrackBack URL for this entry:
http://cha.homeip.net/cgi-bin/mt/mt-tb.cgi/249