Zentyal as Transparent Proxy

一般安裝及設定:

下載 http://www.zentyal.org/server 下的 community edition 64bit 免費社群版。本次安裝為 3.5 版, 主要供電腦教室作 proxy 代理伺服器使用。

利用: http://pulipuli.blogspot.tw/2014/06/zentyal-302-install-zentyal-302.html 所提到的方法安裝。在 vbox 中給予 2 CPUs 、2 張網卡、和 4G RAM。

安裝的時候一律選擇英文安裝,之後可以再中文化。

不同的 Zentyal 角色可用不同的硬體設定,請參考: https://wiki.zentyal.org/wiki/En/3.5/Installation

在 zentyal 這台虛擬伺服器上選擇 gateway 角色,選擇需要的套件後,按安裝。兩張網卡設定為 eth0 為 external 、eth1 為 internal。安裝後重開機 zentyal 會進入 firefox 的 https://localhost 管理介面,這時設定好 firewall > filtering rules from external to Zentyal 裏的設定值,加入 ssh、icmp、zentyal webadmin (https) 這三個連線允許開通就可以離開 vbox 的介面,由遠端電腦來管理。

為設定通透式 proxy 代理伺服器給電腦教室使用,請 zentyal 安裝時問網域不要設定學校網域,可隨意設一個網域,如 a.com 。dns 設定兩個:中華電信168.95.1.1 及google 8.8.8.8。

在另一台電腦上的瀏覽器上鍵入 https://IP ,登入即可看到管理介面 (zentyal webadmin)。可以 update system,試過沒什麼大問題。

中文化:

SNMP:

network > service > add > source any, target snmp udp port 161

firewall > packet filter > from external to zentyal > add new > source any to target snmp. 

依以下頁面設定 SNMP。

https://sites.google.com/site/wyvern2000/home/it/linux/ubuntu-1204-desktop-64bit

到 cacti 設定抓取 zentyal 的系統狀況圖表。

Traffic Shaping > interface rates > action: edit > 16384Kb/s 改為  1600384 Kb/s (上下行流量加大)

通透式 proxy 的設定及阻擋網站: 

硬體:學生電腦設定 gateway 為該proxy的 ip。然後zentyal 的 proxy選通透式。網路不經ip分享器。(ip分享器備而不用--實體線路的虛擬網段斷線,proxy有問題時,請學生將gateway修改為ip分享器位址,然後再將proxy的實體線路虛擬網段斷線,將ip分享器的實體線路接上hub。)

proxy中的AD BLOCKING不要打開,以免校網圖片顯示不正常。

https://wiki.zentyal.org/wiki/En/3.5/HTTP_Proxy_Service

勾選 transparent proxy。容量設 2048 mb。

https://forum.zentyal.org/index.php/topic,16841.msg66809.html#msg66809

transparent proxy 只能阻擋一般 http 網站 filter profile > tab1: settings > threshold > choose 'medium' 或 disable (選disable proxy反應速度會比較快)  > tab2: domain & urls > add new:add domain names (not started as www) 阻擋的結果是使用者的瀏覽器會跳出 zentyal 的阻擋訊息。

1. Create filter profile, under Domains and URL, type in facebook.com and facebook.x (whatever the county your in, mines facebook.dk) and last, set it to "Deny"

2. Go to Access rules, you should have a general rule "All time"

3. Edit the rule

4. Choose decision, set it to "Apply filter Profile"

6. Choose "whatevername you gave the profile" i choosed Facebook as the name.

註:proxy 只能 cache http 的資料, https 的資料無法 cache 也無法 block 處理。

阻檔遊戲網站:在 google 或 yahoo 鍵入關鍵字: game、遊戲、遊戲天堂、遊戲桃、遊戲口袋、遊戲討論、遊戲基地、遊戲鍋、優仕網、華義、智冠、英雄聯盟、神魔之塔、LOL、伊莉討論區、史萊姆、巴哈姆特……等,將遊戲的網址列入 filter profile > your filter name > domain and urls 裏,每個關鍵字我都用 google 搜尋到第四頁,慢慢加入 zentyal 裏,最後大約收集了一百三十個網址 (參考連結)。每半年可以依學生的流行遊戲來隨時更新。

擋 https 網站就不能靠網址,要找到 ip ,從 ip 擋。

作法先 create 一個 object ,在 object 裏加 ip range 然後到 firewall 將這些 ip 阻檔 https 的流量 (action > block, source > any, destination > destination object > your object name > service https):

I blocked facebook by first creating a network object in Zentyal that includes all facebook IP ranges:

Zentyal Web Interface > Network > Objects

List of IP ranges:

http://stackoverflow.com/questions/11164672/list-of-ip-space-used-by-facebook

Then I added a packet filter rule under:

Zentyal Web Interface > Firewall > Packet Filter > Filtering rules for internal networks

This rule blocks all https traffic destined to the facebook object I created. It is fine for them to go to http://facebook.com because it immediately forwards them to 

https://facebook.com which is blocked by the rule.

阻擋的結果是瀏覽器連 facebook 會很慢,最後出現「這個網頁無法使用」。

註: zentyal 的 network > tool 裏有 DNS 查詢功能,可善加利用。

由於 facebook 會導向 https ,所以要用 ip 去擋。

facebook ips: http://stackoverflow.com/questions/11164672/list-of-ip-space-used-by-facebook

facebook 的 ip 可以定期用 ubuntu 裏的 whois 指令查詢:

sudo whois -h whois.radb.net -- '-i origin AS32934' | awk '/^route:/ {print $2;}' | sort | uniq

https://doc.pfsense.org/index.php/Blocking_websites

YOUTUBE 的 ip

sudo whois -h whois.radb.net -- '-i origin AS15169' | awk '/^route:/ {print $2;}' | sort | uniq

簡單一點的指令,fb:

sudo whois -h whois.radb.net '!gAS32934'

http://stackoverflow.com/questions/11164672/list-of-ip-space-used-by-facebook

youtube:

sudo whois -h whois.radb.net '!gAS15169'

2014-07 的 facebook ip range:

103.4.96.0/22

173.252.64.0/18

173.252.64.0/19

173.252.70.0/24

173.252.96.0/19

179.60.192.0/22

179.60.192.0/24

179.60.193.0/24

179.60.194.0/24

179.60.195.0/24

185.60.216.0/22

204.15.20.0/22

31.13.24.0/21

31.13.64.0/18

31.13.64.0/19

31.13.64.0/24

31.13.65.0/24

31.13.66.0/24

31.13.67.0/24

31.13.68.0/24

31.13.69.0/24

31.13.70.0/24

31.13.71.0/24

31.13.72.0/24

31.13.73.0/24

31.13.74.0/24

31.13.75.0/24

31.13.76.0/24

31.13.77.0/24

31.13.78.0/24

31.13.79.0/24

31.13.80.0/24

31.13.81.0/24

31.13.82.0/24

31.13.83.0/24

31.13.84.0/24

31.13.85.0/24

31.13.86.0/24

31.13.87.0/24

31.13.88.0/24

31.13.89.0/24

31.13.90.0/24

31.13.91.0/24

31.13.92.0/24

31.13.93.0/24

31.13.94.0/24

31.13.95.0/24

31.13.96.0/19

45.64.40.0/22

66.220.144.0/20

66.220.144.0/21

66.220.152.0/21

66.220.159.0/24

69.171.224.0/19

69.171.224.0/20

69.171.239.0/24

69.171.240.0/20

69.171.253.0/24

69.171.255.0/24

69.63.176.0/20

69.63.176.0/21

69.63.176.0/24

69.63.178.0/24

69.63.184.0/21

69.63.186.0/24

74.119.76.0/22

寫成 script 更新 blacklist (但是 zentyal 待試):

# Bloqueio facebook

for ip in `whois -h whois.radb.net '!gAS32934' | grep /`

do

  iptables -A FORWARD -p all -d $ip -j REJECT

done

沒有 whois 指令,可以用以下指令安裝 https://www.digitalocean.com/community/questions/whois-command-not-working

sudo apt-get install python-software-properties

sudo add-apt-repository ppa:nathan-renniewaldock/ppa 

sudo apt-get update 

sudo apt-get install whois

利用 Categorized Lists 來阻擋網站:

利用 shallalist (一套收集分類好的網站清單),來作內容控管,請至:

http://www.shallalist.de/

右側下載 list (shallalist.tar.gz)。然後到 zentyal 介面上:

註: import/export settings 可以把機器的設定值全部備份出來。定期進入 zentyal 的介面將設定值備份起來。