IPNAT+Ipfilter+Squid
Transparent Proxy 超級防火牆
Description :
安裝完防火牆之後感覺好像欠缺某些東西似的,對
了!少了 HTML 的過濾機智,ipfilter 只有針對各試各樣的通訊協定 ( tcp/udp/icmp...)
過濾,似乎不能滿足我們的需求,因此我們需要在防火牆內再加裝 Squid,以達到擁有 Transparent Proxy
的能力,這樣的防火牆才能真正稱的上是超級防火牆。
Setp 1.
安裝squid:
#cd
/usr/ports/www/squid
#make install
clean
設定squid.conf #vi
/usr/local/etc/squid/squid.conf 內容如下:
http_port 3128
cache_mem 8 MB
maximum_object_size 4096 KB
cache_dir ufs
/usr/local/squid/cache 100 16 256
cache_access_log
/usr/local/squid/logs/access.log
cache_log
/usr/local/squid/logs/cache.log
cache_store_log
/usr/local/squid/logs/store.log
#
cache_mgr admin@ntut.idv.tw
cache_effective_user nobody
cache_effective_group nogroup
#
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src
127.0.0.1/255.255.255.255
acl SSL_ports port 443 563
acl Safe_ports port 80 21 70
1025-65535
acl Valid_ports port 80 21 3128
8080 70 151 1-1024
acl CONNECT method CONNECT
acl lan-a src 10.10.10.0/24
acl hotmail dstdomain .hotmail.com
acl msn dstdomain .msn.com
#
http_access deny msn
http_access deny hotmail
http_access allow manager localhost
http_access deny manager
http_access allow lan-a
http_access deny all
#
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
squid.conf 設定說明:
http_port 3128 # squid
Listen於3128這個port。也就是說,只要將Client端browser內的proxy指向,指向這台的 IP,port 為
3128,Client即可透過這台Squid Server上網。
cache_mem 8 MB #
設定squid所使用的記憶體最大為8 MB。您可以依自己的須求,調整其大小。如:您的實體記憶體為256 MB,您可將此調整為64 MB
cache_dir ufs /usr/local/squid/cache
100 16 256 # 設定 cache 要放在/usr/local/squid/cache 之下,最多佔 100
MB 的硬碟容量,第一層子目錄的 最大數量為 16 個,第二層子目錄的最大數量為 256 個。
cache_access_log
/usr/local/squid/logs/access.log # 哪些 IP
去過哪些網址,記錄在/usr/local/squid/logs/access.log 檔內 . ( 此檔會很大 , 若無需要 , 可將之轉向到
/dev/null 內。
cache_log
/usr/local/squid/logs/cache.log # 把 cache
內,檔案的增減,記錄在/usr/local/squid/logs/cache.log 檔案之內。
cache_store_log
/usr/local/squid/logs/store.log #
把從哪些網址捉下哪些檔案,記錄在/usr/local/squid/logs/store.log 的檔案之內。
reference_age 1 week #
設定網頁留在cache內最多可以保留多久。時間越長,效果越顯著,但看到過期網頁的機會越大。可改成:reference_age 8
hours、reference_age 1 day、reference_age 3 week、reference_age 5
months、reference_age 1 year。
cache_mgr admin@ntut.idv.tw
# 設定管理者的E-Mail信箱。
acl lan-a src 10.10.10.0/24
# 宣告一個名為lan-a的群組,範圍屬於10.10.10.0/24這個網段。
http_access allow lan-a #
設定lan-a 這個群組可以使用 Squid Proxy Server。
http_access deny all #
(有先後順序)除了前面設定allow或deny的群組之外,其它的全部都不能使用 Squid Proxy Server。
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
# 這四行為Transparent proxy 設定
squid 常用指令:
#squid -z
# 建立cache_dir
#chown -R
nobody:nogroup /usr/local/squid/logs # 更改logs權限
#chown -R
nobody:nogroup /usr/local/squid/cache #
更改cache權限
#/usr/local/etc/rc.d/squid.sh
start # 開啟squid
#squid -k
reconfigure # 不必重新啟動squid即可重讀squid.conf
Setp 2.
設定 ipfilter 的 ipnat.rules 加入下面這行 ipfilter 即可運作 Transparent mode
rdr de1 0.0.0.0/0 port 80 ->
10.10.10.254 port 3128 tcp/udp
參考資料:
http://w.yi.org/weblog/41_0_1_0.html
http://linux.vbird.org/linux_server/0420squid.php
http://turtle.ee.ncku.edu.tw/~tung/proxy/