RHEL 6.0 爲局域網提供上網代理,並做相應的限制。

用環境:RHEL 6.0 x86_64 squid-3.1.4-1.el6.x86_64(自帶) 爲局域網提供上網代理;並做相應的限制,限制如下:
上班時間段禁止訪問娛樂淘寶等網站,禁止下載mp3、exe等類型文件,採購部門需要上淘寶等某些限制網站(高級代理),
能代理上網站、QQ等功能;限制同一ip請求連接數,週六週日不受限制上網……

squid.conf配置內容如下:
#more /etc/squid/squid.conf |grep -v "^#"
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl localhost src ::1/128
acl to_localhost dst 127.0.0.0/8 0.0.0.0/32
acl to_localhost dst ::1/128
acl localnet src 192.168.0.0/16                                                                                                  #定義本地內網網段
acl SSL_ports port 443          #SSL
acl Safe_ports port 80          # http
acl Safe_ports port 21          # ftp
acl Safe_ports port 443 563     # https
acl Safe_ports port 70          # gopher
acl Safe_ports port 210         # wais
acl Safe_ports port 1025-65535  # unregistered ports
acl Safe_ports port 280         # http-mgmt
acl Safe_ports port 488         # gss-http
acl Safe_ports port 591         # filemaker
acl Safe_ports port 777         # multiling http
acl RestTime time MTWHF 00:00-8:29                                                                                 #定義休息時間段1(週六週日除外,下同)
acl WorkTime time MTWHF 8:30-11:29                                                                                #定義工作時間段1
acl workTime time MTWHF 12:30-17:29                                                                               #定義工作時間段2
acl RestTime time MTWHF 17:30-23:59                                                                                #定義休息時間段2
acl CONNECT method CONNECT
acl OverConnlimit maxconn 25                                                                                            #定義客戶端最大連接數   
http_access allow localhost                                                                                                 #允許本地連接
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports                                                                                    #拒絕非安全端口的連接 
http_access deny CONNECT !SSL_ports                                                                      #拒絕非443的安全連接端口              
acl deny_ip src "/etc/squid/deny_ip"                                                                           #拒絕的客戶端ip列表
acl qqgame dst "/etc/squid/policy/qqgame.list"                                                            #拒絕的QQ遊戲ip列表
acl love_ip src "/etc/squid/vip_ip"                                                                                #應用vip高級代理 
acl allowurl url_regex "/etc/squid/allow.list"                                                                  #允許的URL地址列表(優於denyurl列表) 
acl denyurl url_regex "/etc/squid/denyurl.list"                                                                #拒絕訪問的URL列表
acl Black_URL url_regex -i ^rtsp:// ^mms:// ^emule://                                                 #拒絕類似電驢的請求      
acl danger url_regex -i \.exe$ \.bat$ \.vbs$ \.zip$ \.mp3$ \.rm$ \.rar$                             #拒絕下載這些類似的文件
http_access deny deny_ip                                                                                           #應用拒絕的客戶端列表       
http_access deny qqgame                                                                                         #應用拒絕我QQ遊戲列表
http_access allow vip_ip                                                                                          #應用vip代理   
http_access deny danger 
http_access deny OverConnLimit                                                                            #應用拒絕超過連接數的代理   
http_access allow allowurl                                                                                    #允許例外的網站列表
http_access deny Black_URL         
http_access deny denyurl WorkTime                                                                    #工作時間拒絕上denyurl中的網站 (當然高級代理除外)
http_access allow denyurl RestTime                                                                     #休息時間不限
http_access allow all         
http_access allow localnet
http_access allow localhost
http_access deny all
http_port 3128                                                                                         #tcp 3128端口作爲代理上網端口(可自行定義)
hierarchy_stoplist cgi-bin ?
coredump_dir /var/spool/squid
cache_mgr IT_Administrators
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .;              0       20%     4320

客戶端的配置:

1、瀏覽器的配置,這裏以IE爲例:Internet選項-->"連接"-->"局域網設置"

2、代理QQ上網


說明:如果公司是單網段剛可以配置透明代理,這不是文章的重點,如果是多網段不用透明代理,有微軟的域系統,可以利用域策略自動配置IE的代理
這機有點類似走了透明代理,但網關還是自己網段的,只是瀏覽器的代理被域策略配置成代理服務器的ip和端口(實際上筆者所在的公司就是這麼實現的);

deny_ip 列表如下:(請根據自己公司的局域網網段構建列表)   

#網段IP       電腦使用人        電腦名
#-------------2網段ip地址-------------------------------------------
192.168.2.2
192.168.2.3
192.168.2.4
192.168.2.5
192.168.2.6
192.168.2.7
192.168.2.8
192.168.2.9
#192.168.2.10   #張三         xxb-04
#192.168.2.11   #李四         TL2-03
#192.168.2.13   #王五         TL1-04
#192.168.2.14   #趙六        ERP-01
#192.168.2.15   #郭七         tl1-09
#192.168.2.16   #程咬金
#192.168.2.17   #劉老要         TL2-04
#192.168.2.18   #鳳平         pp-02
#192.168.2.19   #陳佳        TL-10
說明:deny_ip列表在默認註釋掉的纔是有效的,即可以上網的,沒有註釋掉的就是拒絕上網的;
高級vip_ip列表也類似,只要在vip_ip列表中就不受上班時間限制上網denyurl中的網站,也不受限制下載;真是方便;另外實踐中
以上配置能正常代理上網上QQ包括QQ遠程協助,但是QQ不能發送圖片,經查資料,原因是默認情況 下http_access deny CONNECT !SSL_ports  起的作用
如果想讓QQ能發送圖片,那麼請把這條註釋掉!
denyurl.list和allow.list內容如下(可自行定義名稱和添加內容)
http://bbs.wdtc520.com
http://creditcard.ccb.com/loginFrm.html
http://www.abchina.com/update/down/powerenterabc32.exe
http://jobs.12333sh.gov.cn/dwdl/showInfo.jsp?number=75
http://mail.qq.com/cgi-bin/
mail.qq.com/cgi-bin/
http://www.hao123.com/
http://www.sh.10086.cn/
說明:這兩個列表既可以只填寫關鍵字,也可以填寫完整的URL,但必須是一行一個條目,這裏定義的規則是
是allow.list列表是優於denyurl.list列表的,例如,如果denyurl.list中有2345,那麼所有的url中只要包含2345
字段那麼非vip用戶在非休息時間是不能訪問的,代理會提示網站內容不合法,請聯繫管理員等提示,
但是如果在在allow.list中有www.2345.com這個條目,那麼客戶端在受限制時間內(非vip客戶)還是可以訪問www.2345.com這個網站的~
這就是這兩個列表的妙處~

參考文章來源於www.wdtc520.com http://www.wdtc520.com/thread-1182-1-1.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章