VnLamp

Go Back   VnLamp > Linux Resources > Linux Forums - Press Releases

Trả lời
 
LinkBack Ðiều Chỉnh Xếp Bài
Cấu hình transparent proxy sử dụng Squid
Old
  (#1 (permalink))
 
Status: Offline
Posts: 601
Tham gia: Dec 2007
^..^
 
hautp's Avatar
Post Cấu hình transparent proxy sử dụng Squid - 27-12-2007, 09:27 27-12-2007

1. Tập tin squid.conf:

Sao chép nội dung bên dưới vào /etc/squid/squid.conf

hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \?
no_cache deny QUERY
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 2 hours
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
acl all src 0.0.0.0/0.0.0.0
acl mynetwork src 192.168.1.0/255.255.255.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 563
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow mynetwork
http_access allow localhost
http_access deny all
http_reply_access allow all
icp_access allow all
httpd_accel_host virtual
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
coredump_dir /var/spool/squid

Bạn phải đổi hàng acl mynetwork src 192.168.1.0/255.255.255.0 với địa chỉ mạng nội bộ bạn muốn.

2. Chỉnh tường lửa:

a. Nếu bạn dùng Linux làm gateway và vnls là một máy riêng trong mạng đang chạy Squid:

Trên máy Linux gateway, gõ:

iptables -t nat -A PREROUTING -i eth0 -s ! địa_chỉ_máy_vnls -p tcp --dport 80 -j DNAT --to địa_chỉ_máy_vnlamp:3128

iptables -t nat -A POSTROUTING -o eth0 -s địa_chỉ_mạng_nội_bộ -d địa_chỉ_máy_vnls -j SNAT --to địa_chỉ_tường_lửa

iptables -A FORWARD -s địa_chỉ_mạng_nội_bộ -d địa_chỉ_máy_vnlamp -i eth0 -o eth0 -p tcp --dport 3128 -j ACCEPT

eth0 là thiết bị mạng nội bộ.

b. Nếu bạn dùng vnls làm gateway và chạy Squid trên cùng một máy:

Trên máy vnlamp, gõ:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128

eth0 là thiết bị mạng nội bộ

Reference:

http://www.tldp.org/HOWTO/TransparentProxy.html
   
Trả Lời Với Trích Dẫn
Old
  (#2 (permalink))
 
Status: Offline
Posts: 145
Tham gia: Dec 2007
Senior Member
 
meoluoi83's Avatar
Default 19-03-2008, 10:19 19-03-2008

chào anh hautp ,
Em giờ đang có 2 range IP
1. 192.168.1.0/24
2. 172.16.1.0/24

Bây giờ em muốn cấu hình squid hay squidGuard sau cho 2 range có thể đi internet được mình thường nhưng range thứ 2 không cho download file

Thân chào !
   
Trả Lời Với Trích Dẫn
Old
  (#3 (permalink))
 
Status: Offline
Posts: 601
Tham gia: Dec 2007
^..^
 
hautp's Avatar
Default 19-03-2008, 11:19 19-03-2008

chào bạn ,
trong file cấu hình squid.conf bạn thêm vào những dòng sau

Trích:
acl download_files urlpath_regex \.exe$ \.mp3$ \.wma$ ( bạn muốn thêm file nào cần chặn thì thêm vào đây )
acl download_deny src 172.16.1.0/24

http_access deny download_files download_deny
   
Trả Lời Với Trích Dẫn
Old
  (#4 (permalink))
 
Status: Offline
Posts: 48
Tham gia: Feb 2008
Member
Default 19-03-2008, 13:19 19-03-2008

còn file cò đuôi .zip và .rar thì như thế nào
   
Trả Lời Với Trích Dẫn
Old
  (#5 (permalink))
 
Status: Offline
Posts: 145
Tham gia: Dec 2007
Senior Member
 
meoluoi83's Avatar
Default 19-03-2008, 14:19 19-03-2008

@hautp : cám ơn anh , em đã làm được rồi
@trietnm : muốn thêm file .zip và .rar thì thêm vào acl download_files urlpath_regex như sau

Trích:
acl download_files urlpath_regex \.exe$ \.mp3$ \.wma$ \.zip$ \.rar$
thêm vào những file bạn muốn chặn tương ứng theo cú pháp \.tenfile$ thôi

thay đổi nội dung bởi: hautp, 19-03-2008 lúc 14:19 19-03-2008.
   
Trả Lời Với Trích Dẫn
Old
  (#6 (permalink))
 
Status: Offline
Posts: 48
Tham gia: Feb 2008
Member
Default 21-03-2008, 12:21 21-03-2008

Mình làm như Hautp nói rồi nhưng chặn đươc file .exe thôi.còn .zip va rar thi ko được

thay đổi nội dung bởi: hautp, 21-03-2008 lúc 15:21 21-03-2008.
   
Trả Lời Với Trích Dẫn
Old
  (#7 (permalink))
 
Status: Offline
Posts: 601
Tham gia: Dec 2007
^..^
 
hautp's Avatar
Default 21-03-2008, 15:21 21-03-2008

bạn vui lòng cho mình xem file cấu hình !
nó chặn lại và báo như thế nào , bạn chụp hình lại cho mình xem rồi post lên đây !
   
Trả Lời Với Trích Dẫn
Old
  (#8 (permalink))
 
Status: Offline
Posts: 48
Tham gia: Feb 2008
Member
Default 24-03-2008, 08:24 24-03-2008

file cấu hình của mình như vậy.

http_port 3128 transparent
visible_hostname admin
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
#acl apache rep_header Server ^Apache
#broken_vary_encoding allow apache
cache_mem 8 MB
cache_swap_low 90
cache_swap_high 95
maximum_object_size 4096 KB
minimum_object_size 0 KB
maximum_object_size_in_memory 8 KB
cache_dir ufs /var/spool/squid 500 16 256
access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log
request_header_max_size 20 KB
request_body_max_size 0 KB
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
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 to_localhost dst 127.0.0.0/8
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # 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 CONNECT method CONNECT
http_access allow localhost
#http_access deny all
http_reply_access allow all
icp_access allow all
################################################## #####################
acl all src 0.0.0.0/0.0.0.0
##############################String############## ###########################
acl denystring url_regex -i "/etc/squid/deny_string"
acl allowip1 src "/etc/squid/ip_string"
http_access deny denystring !allowip1
http_access allow allowip1
###############################google############# #########################
acl google dstdomain url_regex "/etc/squid/google"
acl ipgoogle src "/etc/squid/ipgoogle"
http_access allow ipgoogle google
#############################download############# ###################
acl download_file urlpath_regex \.exe$ \.mp3$ \.wma$ \.zip$ \.rar$
acl download_deny src 0.0.0.0/0.0.0.0
http_access deny download_file download_deny
   
Trả Lời Với Trích Dẫn
Old
  (#9 (permalink))
 
Status: Offline
Posts: 601
Tham gia: Dec 2007
^..^
 
hautp's Avatar
Default 24-03-2008, 09:24 24-03-2008

Đây là file của mình , mình test chạy okie đó bạn

acl download_files url_regex "/etc/squid/blocked_download_list.txt"
acl download_deny src 172.16.151.0/24
http_access deny download_files download_deny

file blocked_download_list.txt chứa nội dung sau

\.exe$
\.com$
\.mp3$
\.wma$
\.wmv$
\.zip$
\.rar$

Nếu vẫn kô được bạn cho mình cái hình chụp Access Deny lúc bạn download file .exe
   
Trả Lời Với Trích Dẫn
Old
  (#10 (permalink))
 
Status: Offline
Posts: 48
Tham gia: Feb 2008
Member
Default 24-03-2008, 11:24 24-03-2008

file exe thi bi chan con .zip va rar thi van down duoc binh thuong

ERROR
The requested URL could not be retrieved

--------------------------------------------------------------------------------

While trying to retrieve the URL: http://the.earth.li/~sgtatham/putty/.../x86/putty.exe

The following error was encountered:

Access Denied.
Access control configuration prevents your request from being allowed at this time. Please contact your service provider if you feel this is incorrect.

Your cache administrator is root.



--------------------------------------------------------------------------------

Generated Mon, 24 Mar 2008 00:29:13 GMT by chutich (squid/2.6.STABLE6)
   
Trả Lời Với Trích Dẫn
Trả lời


Ðiều Chỉnh
Xếp Bài

Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt
Trackbacks are Mở
Pingbacks are Mở
Refbacks are Mở


Múi giờ GMT. Hiện tại là 03:21 21-05-2012.