DỊCH VỤ SQUID PROXY
(Phùng Tấn Phát – Trần Quốc Khải)
-------------I.

CƠ BẢN VỀ DỊCH VỤ SQUID PROXY
1.1. Giới thiệu:
Squid là một proxy server, khả năng của squid là tiết kiệm băng thong
(bandwidth), cải tiến việc bảo mật, tăng tốc độ truy cập web cho người sử dụng
và trở thành một trong những proxy phổ biến được nhiều người biết đến. Hiện
nay, trên thị trường có rất nhiều chương trình proxy-server nhưng chúng lại có
hai nhược điểm, thứ nhất là phải trả tiền để sử dụng, thứ hai là hầu hết không hỗ
trợ ICP (ICP được sử dụng để cập nhật những thay đổi về nội dung của những
URL sẵn có trong cache – là nơi lưu trữ những trang web mà bạn đã từng đi
qua). Squid là sự lựa chọn tốt
nhất cho một proxy-cache server,
squid đáp ứng hai yêu cầu của
chúng ta là sử dụng miễn phí và
có thể sử dụng đặc trưng ICP.
Squid đưa ra kỹ thuật lưu
trữ ở cấp độ cao của các web
client, đồng thời hỗ trợ các dịch
vụ thông thường như FTP,
Gopher và HTTP. Squid lưu trữ
thông tin mới nhất của các dịch
vụ trên trong RAM, quản lý một
cơ sở dữ liệu lớn của các thông tin trên đĩa, có một kỹ thuật điều khiển truy cập
phức tạp, hỗ trợ giao thức SSL cho các kết nối bảo mật thông qua proxy. Hơn
nữa, squid có thể liên kết với các cache của các proxy server khác trong việc sắp
xếp lưu trữ các trang web một cách hợp lý.
1.2 Giao thức hỗ trợ trên Squid Proxy
Squid proxy hỗ trợ những giao thức sau:
- Proxying and caching of HTTP, FTP, and other URLs.
- Proxying for SSL.
- Cachinh hierarchies.
1
- ICP, HTTP, CARP, Cache Digests.
- Transparent caching.
- WCCP- Web Cache Communication Protocol
- Extensive access controls
- HTTP server acceleration
- SNMP
- Caching of DNS lookups.
1.3 Những điểm tối ưu mà Proxy mang lại:
Squid có khả năng chia sẽ dữ liệu giữa những cache với nhau.Việc chia sẻ
này mang lại những lợi ích như:
- User Base: Nếu số lượng client truy cập internet thông qua proxy
càngnhiều thì khả năng một đối tượng nào đó được yêu cầu 2 lần sẽ cao hơn.
- Giảm tải truy xuất cho đường truyền.
- Disk space: nếu bạn chuyển cân bằng giữa các cache với nhau sẽ tránh
được việc sao lại dữ liệu đã lưu. Dó đó dung lượng đĩa cứng dành cho việc lưu
trữ cache sẽ giảm.
1.4 Hệ thống file và thư mục của Squid Proxy:
- /usr/sbin: Lưu những thư viện của squid.
- /etc/squid: Lưu các tập tin cấu hình chính squid.
- /usr/local/squid: thư mục cài đặt squid
- /usr/local/squid/bin: thư mục lưu binary squid và những tool được hỗ trợ.
- /usr/local/squid/cache: thư mục lưu những dữ liệu được cache. Đây là thư
mục mặc định, bạn có thể thay đổi vị trí thư mục này.
- /usr/local/squid/etc: những tập tin cấu hình squid nằm trong thư mục này.
- /usr/local/squid/src: thư mục lưu source code squid được download từ net.
- /var/log/squid: Lưu các tập tin log của squid.
II. Nguyên tắc hoạt động
Squid xác định những yêu cầu từ client và quyết định đáp ứng hay không
đáp ứng, nếu yêu cầu được đáp ứng, nó sẽ kết nối với server thật thay cho client
2
và tiếp tục chuyển tiếp đến những yêu cầu từ client đến server, cũng như đáp
ứng những yêu cầu của server đến client. Vì vậy squid proxy giống cầu nối
trung gian giữa server và client.
Bên cạnh việc chuyển tiếp các yêu cầu từ phía client, nó cũng sẽ đồng
thời lưu lại trên đĩa những dữ liệu được trả về từ Internet Server – gọi là caching
(thường là nội dung các trang Web, các tập tin…). Nếu trong thời gian hiệu lực
mà một hay nhiều client cùng yêu cầu một nội dung thì squid proxy sẽ ngay lập
tức đáp ứng lại những yêu cầu từ phía client.
III. Cấu hình Squid
* Cài đặt squid:
apt-get install squid
* Cấu hình:
File cấu hình chính của Squid là squid.conf ( /etc/squid/squid.conf ) , mọi thay
đổi ở file này bạn cần restart lại squid để có hiệu lực.
để restart squid chúng ta dùng lệnh
/etc/init.d/squid restart
a.Hạn chế truy cập web theo thời gian:
Mở file squid.conf ra
# Add this to the bottom of the ACL section of squid.conf
acl home_network src 192.168.1.0/24
acl allow_hours time M T W H F 9:00-17:00
acl RestrictedHost src 192.168.1.23
# Add this at the top of the http_access section of squid.conf
http_access deny RestrictedHost
http_access allow home_network allow_hours
Nếu bạn có các dòng trên trong file squid.conf thì các máy trong mạng nội bộ
chỉ truy cập được vào mạng vào các ngày thứ 3 đến thứ 6 và trong thời gian 9h
đến 17h.
Trừ máy 192.168.1.23, vì bị cấm tất cả.

3
M, T, W, H, F là viết tắt các ngày trong tuần ( chủ nhật : S, thứ bảy : A)
Có thể dùng D để thay bằng các ngày trong tuần ( M - F )
b.Hạn chế truy cập các website được ấn định trước :
Đầu tiên tạo 2 file ở trong thư mục /etc/squid là allowed-sites.squid và
restricted-sites.squid để chứa tên các domain cho phép truy cập và cấm truy cập.
# File: /squid/allowed-sites.squid
www.vickifcvn.net
fotech.org
# File: /etc/squid/restricted-sites.squid
www.sex.com
xxx.net
Nếu bạn muốn trong thời gian làm việc, cấm vào một số site và cho phép vào
một số site nó thì :
Mở file squid.conf ra :
# Add this to the bottom of the ACL section of squid.conf
acl home_network src 192.168.1.0/24
acl work_hours time M T W H F 9:00-17:00
acl GoodSites dstdomain "/etc/squid/allowed-sites.squid"
acl BadSites dstdomain "/etc/squid/restricted-sites.squid"
# Add this at the top of the http_access section of squid.conf
http_access deny BadSites
http_access allow home_network work_hours GoodSites
Bạn có thể dùng url_regex để hạn chế vào các domain name được ấn định:
# Add this to the bottom of the ACL section of squid.conf
acl domainname url_regex -i ^http://www
# Add this at the top of the http_access section of squid.conf
http_access deny domainname

4
c.Hạn chế truy cập web theo địa chỉ ip :
Bạn có thể tạo một access control list để hạn chế truy cập web trên một mạng
nào đó.
# Add this to the bottom of the ACL section of squid.conf
acl home_network src 192.168.1.0/255.255.255.0
acl localhost dst 127.0.0.0/8
# Add this at the top of the http_access section of squid.conf
http_access allow home_network
http_access allow localhost
d.Hạn chế nội dung các file download:
Tạo một file chứ nội dung các phần đuôi của các tập tin mà bạn muốn hạn chế là
blocks.files.acl nằm trong /etc/squid
.[Ee][Xx][Ee]$
.[Aa][Vv][Ii]$
.[Mm][Pp][Gg]$
.[Mm][Pp][Ee][Gg]$
.[Mm][Pp]3$
Thêm vào squid.conf dòng
# Add this to the bottom of the ACL section of squid.conf
acl blockfiles urlpath_regex “/etc/squid/blocks.files.acl”
# Add this at the top of the http_access section of squid.conf
http_access deny blockfiles
e.Hạn chế truy cập theo cổng :
vd
# Add this to the bottom of the ACL section of squid.conf
acl httpports port 80 8000-8010 8080
5
# Add this at the top of the http_access section of squid.conf
http_access allow httpports
Các bạn nên duy trì và allow một số cổng. Dưới đây là một số cổng được cho là
an toàn ( mặc định trong file squid.conf )
# Add this to the bottom of the ACL section of squid.conf
acl safe_ports port 80 # http
acl safe_ports port 21 # ftp
acl safe_ports port 443 563 # https snews
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 480 # gss-http
acl safe_ports port 591 # filemaker
acl safe_ports port 777 # multiling http
# Add this at the top of the http_access section of squid.conf
http_access deny !safe_ports

f.Hạn chế truy cập theo giao thức :
# Add this to the bottom of the ACL section of squid.conf
acl FTP proto FTP
# Add this at the top of the http_access section of squid.conf
http_access deny FTP
g.Dùng NCSA kiểm định password:
đầu tiên tạo một file password,vd /etc/squid/squid_passwd
touch /etc/squid/squid_passwd
chmod o+r /etc/squid/squid_passwd

6
Dùng htpasswd để add user vào pass vào file squid_passwd đó
htpasswd /etc/squid/squid_passwd vicki
New password:
Re-type new password:
Adding password for user vicki

giờ thêm vào file squid.conf
# Add this to the auth_param section of squid.conf
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/squid_passwd
# Add this to the bottom of the ACL section of squid.conf
acl ncsa_users proxy_auth REQUIRED
# Add this at the top of the http_access section of squid.conf
http_access allow ncsa_users

Như vậy phải dùng user và pass được add vào file squid_passwd mới có thể truy
cập vào internet được.
Cũng có thể kết hợp thời gian để bắt kiểm định pass vào mốc thời gian nhất định
( tham khảo đầu bài )

Nếu bạn muốn mọi deny đều có một thông báo cho người dùng biết thì :
Tạo một file deny.php với nội dung tùy bạn, đặt vào /var/www chẳng hạn.
acl blacklist url_regex yahoo.com vietnamnet.vn
http_access deny blacklist
deny_info domain/deny.php blacklist

7
PHỤ LỤC

MỘT SỐ VÍ DỤ KHÁC VỀ ACL SQUID
Hạn chế truy cập web theo thời gian và cấm các IP chỉ định đi web
acl home_network src 192.168.1.0/24
acl allow_hours time M T W H F 9:00-17:00
acl RestrictedHost src 192.168.1.200
http_access deny RestrictedHost
http_access allow home_network allow_hours
Hạn chế truy cập web theo thời gian và loại trừ IP của các sếp
acl home_network src 192.168.1.0/24
acl allow_hours time M T W H F 9:00-17:00
acl AllowHost src "/etc/squid/AllowHost.txt"
http_access allow AllowHost
http_access allow home_network allow_hours
# vi /etc/squid/AllowHost.txt
192.168.1.100
192.168.1.200
Tự động redirect sang website ấn định trước khi truy cập những website ko được phép
acl home_network src 192.168.1.0/24
acl denywebsite dstdom_regex "/etc/squid/denywebsite.txt"
http_access deny denywebsite
deny_info http://vnlamp-test.vn/deny.html denywebsite >> tất nhiên đã cấu hình dns & httpd
#deny_info http://www.google.com.vn denywebsite >> redirect tới google
# deny_info TCP_RESET denywebsite >> reset the TCP connection (blank page)
http_access allow home_network
# vi /var/www/html/deny.html
"This site has restricted by administrator"
Hạn chế tên tập tin download
acl home_network src 192.168.1.0/24
acl blockfiles urlpath_regex "/etc/squid/block.files.acl"
http_access deny blockfiles
http_access allow home_network
hoặc
acl home_network src 192.168.1.0/24
acl denyfiletypes url_regex -i .mp3$ .mpg$ .mpeg$ .mp2$ .avi$ .wmv$ .wma$ .exe$
http_access deny denyfiletypes
http_access allow home_network
Dùng htpasswd để add user và pass vào file squid_passwd mới tạo
# htpasswd /etc/squid/squid_passwd u1
New password:
8
Re-type new password:
Adding password for user u1
# Edit file squid.conf
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/squid_passwd
acl ncsa_users proxy_auth REQUIRED
http_access allow ncsa_users
Cho phép một range IP chỉ truy cập vào những trang web cố định
acl allow_domains dstdomain url_regex "/etc/squid/local/access-local.txt"
acl ip-local src "/etc/squid/ip-local.txt"
http_access deny ip-local !allow_domains
http_access allow ip-local
# vi /etc/squid/local/access-local.txt
.vnexpress.net
.tuoitre.com.vn
# vi /etc/squid/local/ip-local.txt
192.168.1.0/24
Cấm truy cập vào yahoo
acl aclyahoo dstdomain pager.yahoo.com
acl aclyahoo dstdomain shttp.msg.yahoo.com
acl aclyahoo dstdomain update.pager.yahoo.com
acl aclyahoo dstdomain scsa.yahoo.com
acl aclyahoo dstdomain msg.yahoo.com
http_access deny aclyahoo
Cấm download file có dung lượng >=10MB
acl home_network src 192.168.2.0/24
acl denywebsite dstdom_regex "/etc/squid/denywebsite.txt"
http_access deny denywebsite
deny_info http://www.google.com.vn denywebsite
reply_body_max_size 10000000 allow home_network
http_access allow home_network
http_access deny all
icp_access allow all
Cấu hình Squid Proxy Server để điều khiển băng thông
Bước 1: Thêm vào trong file cấu hình squid một số phần như sau:
# vi /etc/squid/squid.conf
# Add Control Bandwith
acl ip src "/etc/squid/ip.txt" # ip trong file ip.txt bị giới hạn
acl all src 0.0.0.0/0.0.0.0
# Add Control Bandwith
delay_pools 1
delay_class 1 2
delay_access 1 allow ip
9
delay_access 1 deny all
delay_parameters 1 -1/-1 15000/15000
Với delay_parameters 1 -1/-1 15000/15000 ta sẽ giới hạn băng thông cho các client không thể
vượt quá 15000 tương đương 15Kbps
Bước 2: Tạo file ip.txt như sau:
# vi /etc/squid/ip.txt
192.168.1.33
192.168.1.34
Vậy các IP trong file ip.txt sẽ có băng thông tối đa là 15Kbps
# Block online streaming of Audio/Video
acl BlockExt url_regex -i .mp3$ .asx$ .wma$ .wmv$ .avi$ .mpeg$ .mpg$ .qt$ .ram$
.rm$ .iso$ .wav$ .exe$
acl webRadioReq1 req_mime_type -i ^video/x-ms-asf$
acl webRadioReq2 req_mime_type -i ^application/vnd.ms.wms-hdr.asfv1$
acl webRadioReq3 req_mime_type -i ^application/x-mms-framed$
acl webRadioRep1 rep_mime_type -i ^video/x-ms-asf$
acl webRadioRep2 rep_mime_type -i ^application/vnd.ms.wms-hdr.asfv1$
acl webRadioRep3 rep_mime_type -i ^application/x-mms-framed$
acl WMP browser Windows-Media-Player/*
http_access deny BlockExt !UtentiGold
http_access deny WMP all
http_access deny webRadioReq1 all
http_access deny webRadioReq2 all
http_access deny webRadioReq3 all
http_reply_access deny webRadioRep1 all
http_reply_access deny webRadioRep2 all
http_reply_access deny webRadioRep3 all
( 1. Added the extensions .wma and .wmv at the following line, so it's impossible to
dowlonload these file types acl BloccoExt url_regex -i .mp3$ .asx$ .wma$ .wmv$
.avi$ .mpeg$ .mpg$ .qt$ .ram$ .rm$ .iso$ .wav$ .exe$
2. Created acl for the other two 2 mime types (maybe not necessary) acl webRadioReq1
req_mime_type -i ^video/x-ms-asf$ acl webRadioReq2 req_mime_type -i
^application/vnd.ms.wms-hdr.asfv1$ acl webRadioReq3 req_mime_type -i ^application/xmms-framed$ acl webRadioRep1 rep_mime_type -i ^video/x-ms-asf$ acl webRadioRep2
rep_mime_type -i ^application/vnd.ms.wms-hdr.asfv1$ acl webRadioRep3 rep_mime_type -i
10
^application/x-mms-framed$
3. Added this too... acl WMP browser Windows-Media-Player/*
4. Created following rules http_access deny BloccoExt !UtentiGold http_access deny WMP !
UtentiGold http_access deny webRadioReq1 !UtentiGold http_access deny webRadioReq2 !
UtentiGold http_access deny webRadioReq3 !UtentiGold
http_reply_access deny webRadioRep1 !UtentiGold http_reply_access deny webRadioRep2 !
UtentiGold http_reply_access deny webRadioRep3 !UtentiGold
Notes:UtentiGold is an ip list of privileged users (CEO, ecc.)
In this mode, if I'm not a privileged user, I'm not able to open web radio (example
http://bbwms.libero.it/lifegate) with IE6 and WMP9, clicking on a link or typing the url )

11

More Related Content

PPT
Hệ Thống DNS
PDF
Đồ án thực tập cơ sở các kĩ thuật tấn công SQL injection và cách phòng chống
PDF
Bài 6: Bảo mật trong SQL SERVER 2008 - Giáo trình FPT
PDF
Bài tập lớn Phát triển phần mềm hướng dịch vụ PTIT
PPT
Chuong 05 de quy
DOCX
Nghiên cứu và triển khai hệ thống ISA Server 2006
DOCX
7. tìm hiểu hàm băm md5 và ứng dụng
DOC
Bài giảng Công Nghệ Phần Mềm
Hệ Thống DNS
Đồ án thực tập cơ sở các kĩ thuật tấn công SQL injection và cách phòng chống
Bài 6: Bảo mật trong SQL SERVER 2008 - Giáo trình FPT
Bài tập lớn Phát triển phần mềm hướng dịch vụ PTIT
Chuong 05 de quy
Nghiên cứu và triển khai hệ thống ISA Server 2006
7. tìm hiểu hàm băm md5 và ứng dụng
Bài giảng Công Nghệ Phần Mềm

What's hot (20)

PDF
Bài 8: Triển khai bảo mật sử dụng chính sách nhóm (Group policy) - Giáo trình...
PDF
Hadoop trong triển khai Big Data
PDF
BigData_TP2: Design Patterns dans Hadoop
PPT
Mang vpn
DOC
Luận văn Thạc sĩ Nghiên cứu triển khai giải pháp đảm bảo an ninh mạng trên nề...
PDF
Đề tài: Phần mềm quản lý thông tin sinh viên, HOT, 9đ
PDF
alphorm.com - Formation Linux LPIC-1/Comptia Linux+
PDF
Đề tài: Hệ thống quản lý học viên cho trung tâm Anh ngữ, HAY
PPT
Slide Hệ Quản Trị Cơ sở dữ liệu - CHƯƠNG 1
PDF
Splunk
PPTX
FreeIPA - Attacking the Active Directory of Linux
PDF
Tấn công ARP Cache Poisoning (Man In The Middle) Attacks
PDF
Tieu Luan - Mang may tinh voi Packet tracer
DOC
Nghiên cứu một số hình thức tấn công website phổ biến và các giải pháp phòng ...
PDF
ĐỒ ÁN XÂY DỰNG WEBSITE BÁN HÀNG BẰNG WORDPRESS
DOCX
Kịch bản demo phát hiện xâm nhập sử dụng snort ids
PDF
Lưu trữ và xử lý dữ liệu trong điện toán đám mây
PDF
Linux practicals T.Y.B.ScIT
Bài 8: Triển khai bảo mật sử dụng chính sách nhóm (Group policy) - Giáo trình...
Hadoop trong triển khai Big Data
BigData_TP2: Design Patterns dans Hadoop
Mang vpn
Luận văn Thạc sĩ Nghiên cứu triển khai giải pháp đảm bảo an ninh mạng trên nề...
Đề tài: Phần mềm quản lý thông tin sinh viên, HOT, 9đ
alphorm.com - Formation Linux LPIC-1/Comptia Linux+
Đề tài: Hệ thống quản lý học viên cho trung tâm Anh ngữ, HAY
Slide Hệ Quản Trị Cơ sở dữ liệu - CHƯƠNG 1
Splunk
FreeIPA - Attacking the Active Directory of Linux
Tấn công ARP Cache Poisoning (Man In The Middle) Attacks
Tieu Luan - Mang may tinh voi Packet tracer
Nghiên cứu một số hình thức tấn công website phổ biến và các giải pháp phòng ...
ĐỒ ÁN XÂY DỰNG WEBSITE BÁN HÀNG BẰNG WORDPRESS
Kịch bản demo phát hiện xâm nhập sử dụng snort ids
Lưu trữ và xử lý dữ liệu trong điện toán đám mây
Linux practicals T.Y.B.ScIT
Ad

Viewers also liked (6)

PPTX
Squid proxy linux
PPT
Fire wall
DOC
Cai dat squid proxy trong suot
 
PPTX
Monitoring event 20130525_chinhsua
PPTX
Trình bày các tác vụ quản lý Domain với Windows Server 2008
PPTX
Slide nagios
Squid proxy linux
Fire wall
Cai dat squid proxy trong suot
 
Monitoring event 20130525_chinhsua
Trình bày các tác vụ quản lý Domain với Windows Server 2008
Slide nagios
Ad

Similar to Dịch vụ squid server (20)

DOCX
Tổng quan về Access List
PPSX
Linux web hosting (Thuyet trinh)
PPSX
Linux web hosting (Thuyet trinh)
PDF
TỰ HỌC LPI 2
PDF
Hướng Dẫn Cài Đặt Proxy Để Truy Cập Internet.pdf
PPTX
Báo cáo thực tập doanh nghiệp-Athena
DOCX
PDF
Cac buochackserver tech24_vn
PDF
Lab linux phan iv
PDF
Giao trinh-php
PPTX
Báo cáo cuối kỳ
PDF
Lab linux phần iv- Internet Services
PDF
Kỹ thuật tìm IP Server nằm sau CloudFlare
PPTX
Apache http server
PDF
các bước hack server
PDF
Cac buochackserver
DOCX
Cau hinh i ptables nang cao
PPT
19 web server
DOCX
Báo cáo thực tập tuần - VPS
Tổng quan về Access List
Linux web hosting (Thuyet trinh)
Linux web hosting (Thuyet trinh)
TỰ HỌC LPI 2
Hướng Dẫn Cài Đặt Proxy Để Truy Cập Internet.pdf
Báo cáo thực tập doanh nghiệp-Athena
Cac buochackserver tech24_vn
Lab linux phan iv
Giao trinh-php
Báo cáo cuối kỳ
Lab linux phần iv- Internet Services
Kỹ thuật tìm IP Server nằm sau CloudFlare
Apache http server
các bước hack server
Cac buochackserver
Cau hinh i ptables nang cao
19 web server
Báo cáo thực tập tuần - VPS

Recently uploaded (20)

DOCX
Ôn tập Văn học phương đông tài liệu tham khảo
PDF
TeétOrganicChemistryFromVietNamVeryHardd
PPTX
Chương 5 của Tâm lí học - Tâm Lí Học Giáo Dục Đạo Đức
PDF
BÀI TẬP TEST FOR UNIT TIẾNG ANH LỚP 6 GLOBAL SUCCESS CẢ NĂM THEO TỪNG ĐƠN VỊ ...
PDF
TUYỂN TẬP ĐỀ KIỂM TRA HÓA HỌC HỮU CƠ THI THỬ OLYMPIC HÓA HỌC QUỐC TẾ (VÒNG 2)...
PDF
CHUYÊN ĐỀ DẠY THÊM HÓA HỌC LỚP 11 CẢ NĂM THEO FORM THI MỚI BGD - CÓ ÔN TẬP + ...
PDF
CHUYÊN ĐỀ DẠY THÊM HÓA HỌC LỚP 12 CẢ NĂM THEO FORM THI MỚI BGD - CÓ ÔN TẬP + ...
PDF
Bản phân loại thực vật môn thực vật dược
DOCX
LUẬN VĂN GROUP ĐỀ BÀI ĐÁNH GIÁ GIAO TIẾP SƯ PHẠM
PPTX
Bai 28 Cau tao chat Thuyet dong hoc phan tu chat khi.pptx
PDF
bai giang an toan thong tin ke toan nam 2020
PPTX
CASE LÂM SÀNG MỤN TRỨNG CÁd (final, BS Vân Thanh)-SV tai lop.pptx
DOCX
Ôn tập văn học phương đông thi giữa kì ..
PDF
CHUYÊN ĐỀ DẠY THÊM HÓA HỌC LỚP 12 CẢ NĂM THEO FORM THI MỚI BGD - CÓ ÔN TẬP + ...
PDF
CHUYÊN ĐỀ DẠY THÊM HÓA HỌC LỚP 10 CẢ NĂM THEO FORM THI MỚI BGD - CÓ ÔN TẬP + ...
PPTX
Bai 11.1 Tuan hoan mau.cấu tạo và vai trò pptx
PPTX
Slide chương 3 môn thẩm định tài chính dự án
PPTX
VNR202 LỊCH SỬ ĐẢNG, MÔN HỌC CẦN THIẾT C
PDF
Sách không hôi fyjj ịuk gtyi yu> ướt jiii iiij
PDF
bo-trac-nghiem-toan-11 dành cho cả năm học
Ôn tập Văn học phương đông tài liệu tham khảo
TeétOrganicChemistryFromVietNamVeryHardd
Chương 5 của Tâm lí học - Tâm Lí Học Giáo Dục Đạo Đức
BÀI TẬP TEST FOR UNIT TIẾNG ANH LỚP 6 GLOBAL SUCCESS CẢ NĂM THEO TỪNG ĐƠN VỊ ...
TUYỂN TẬP ĐỀ KIỂM TRA HÓA HỌC HỮU CƠ THI THỬ OLYMPIC HÓA HỌC QUỐC TẾ (VÒNG 2)...
CHUYÊN ĐỀ DẠY THÊM HÓA HỌC LỚP 11 CẢ NĂM THEO FORM THI MỚI BGD - CÓ ÔN TẬP + ...
CHUYÊN ĐỀ DẠY THÊM HÓA HỌC LỚP 12 CẢ NĂM THEO FORM THI MỚI BGD - CÓ ÔN TẬP + ...
Bản phân loại thực vật môn thực vật dược
LUẬN VĂN GROUP ĐỀ BÀI ĐÁNH GIÁ GIAO TIẾP SƯ PHẠM
Bai 28 Cau tao chat Thuyet dong hoc phan tu chat khi.pptx
bai giang an toan thong tin ke toan nam 2020
CASE LÂM SÀNG MỤN TRỨNG CÁd (final, BS Vân Thanh)-SV tai lop.pptx
Ôn tập văn học phương đông thi giữa kì ..
CHUYÊN ĐỀ DẠY THÊM HÓA HỌC LỚP 12 CẢ NĂM THEO FORM THI MỚI BGD - CÓ ÔN TẬP + ...
CHUYÊN ĐỀ DẠY THÊM HÓA HỌC LỚP 10 CẢ NĂM THEO FORM THI MỚI BGD - CÓ ÔN TẬP + ...
Bai 11.1 Tuan hoan mau.cấu tạo và vai trò pptx
Slide chương 3 môn thẩm định tài chính dự án
VNR202 LỊCH SỬ ĐẢNG, MÔN HỌC CẦN THIẾT C
Sách không hôi fyjj ịuk gtyi yu> ướt jiii iiij
bo-trac-nghiem-toan-11 dành cho cả năm học

Dịch vụ squid server

  • 1. DỊCH VỤ SQUID PROXY (Phùng Tấn Phát – Trần Quốc Khải) -------------I. CƠ BẢN VỀ DỊCH VỤ SQUID PROXY 1.1. Giới thiệu: Squid là một proxy server, khả năng của squid là tiết kiệm băng thong (bandwidth), cải tiến việc bảo mật, tăng tốc độ truy cập web cho người sử dụng và trở thành một trong những proxy phổ biến được nhiều người biết đến. Hiện nay, trên thị trường có rất nhiều chương trình proxy-server nhưng chúng lại có hai nhược điểm, thứ nhất là phải trả tiền để sử dụng, thứ hai là hầu hết không hỗ trợ ICP (ICP được sử dụng để cập nhật những thay đổi về nội dung của những URL sẵn có trong cache – là nơi lưu trữ những trang web mà bạn đã từng đi qua). Squid là sự lựa chọn tốt nhất cho một proxy-cache server, squid đáp ứng hai yêu cầu của chúng ta là sử dụng miễn phí và có thể sử dụng đặc trưng ICP. Squid đưa ra kỹ thuật lưu trữ ở cấp độ cao của các web client, đồng thời hỗ trợ các dịch vụ thông thường như FTP, Gopher và HTTP. Squid lưu trữ thông tin mới nhất của các dịch vụ trên trong RAM, quản lý một cơ sở dữ liệu lớn của các thông tin trên đĩa, có một kỹ thuật điều khiển truy cập phức tạp, hỗ trợ giao thức SSL cho các kết nối bảo mật thông qua proxy. Hơn nữa, squid có thể liên kết với các cache của các proxy server khác trong việc sắp xếp lưu trữ các trang web một cách hợp lý. 1.2 Giao thức hỗ trợ trên Squid Proxy Squid proxy hỗ trợ những giao thức sau: - Proxying and caching of HTTP, FTP, and other URLs. - Proxying for SSL. - Cachinh hierarchies. 1
  • 2. - ICP, HTTP, CARP, Cache Digests. - Transparent caching. - WCCP- Web Cache Communication Protocol - Extensive access controls - HTTP server acceleration - SNMP - Caching of DNS lookups. 1.3 Những điểm tối ưu mà Proxy mang lại: Squid có khả năng chia sẽ dữ liệu giữa những cache với nhau.Việc chia sẻ này mang lại những lợi ích như: - User Base: Nếu số lượng client truy cập internet thông qua proxy càngnhiều thì khả năng một đối tượng nào đó được yêu cầu 2 lần sẽ cao hơn. - Giảm tải truy xuất cho đường truyền. - Disk space: nếu bạn chuyển cân bằng giữa các cache với nhau sẽ tránh được việc sao lại dữ liệu đã lưu. Dó đó dung lượng đĩa cứng dành cho việc lưu trữ cache sẽ giảm. 1.4 Hệ thống file và thư mục của Squid Proxy: - /usr/sbin: Lưu những thư viện của squid. - /etc/squid: Lưu các tập tin cấu hình chính squid. - /usr/local/squid: thư mục cài đặt squid - /usr/local/squid/bin: thư mục lưu binary squid và những tool được hỗ trợ. - /usr/local/squid/cache: thư mục lưu những dữ liệu được cache. Đây là thư mục mặc định, bạn có thể thay đổi vị trí thư mục này. - /usr/local/squid/etc: những tập tin cấu hình squid nằm trong thư mục này. - /usr/local/squid/src: thư mục lưu source code squid được download từ net. - /var/log/squid: Lưu các tập tin log của squid. II. Nguyên tắc hoạt động Squid xác định những yêu cầu từ client và quyết định đáp ứng hay không đáp ứng, nếu yêu cầu được đáp ứng, nó sẽ kết nối với server thật thay cho client 2
  • 3. và tiếp tục chuyển tiếp đến những yêu cầu từ client đến server, cũng như đáp ứng những yêu cầu của server đến client. Vì vậy squid proxy giống cầu nối trung gian giữa server và client. Bên cạnh việc chuyển tiếp các yêu cầu từ phía client, nó cũng sẽ đồng thời lưu lại trên đĩa những dữ liệu được trả về từ Internet Server – gọi là caching (thường là nội dung các trang Web, các tập tin…). Nếu trong thời gian hiệu lực mà một hay nhiều client cùng yêu cầu một nội dung thì squid proxy sẽ ngay lập tức đáp ứng lại những yêu cầu từ phía client. III. Cấu hình Squid * Cài đặt squid: apt-get install squid * Cấu hình: File cấu hình chính của Squid là squid.conf ( /etc/squid/squid.conf ) , mọi thay đổi ở file này bạn cần restart lại squid để có hiệu lực. để restart squid chúng ta dùng lệnh /etc/init.d/squid restart a.Hạn chế truy cập web theo thời gian: Mở file squid.conf ra # Add this to the bottom of the ACL section of squid.conf acl home_network src 192.168.1.0/24 acl allow_hours time M T W H F 9:00-17:00 acl RestrictedHost src 192.168.1.23 # Add this at the top of the http_access section of squid.conf http_access deny RestrictedHost http_access allow home_network allow_hours Nếu bạn có các dòng trên trong file squid.conf thì các máy trong mạng nội bộ chỉ truy cập được vào mạng vào các ngày thứ 3 đến thứ 6 và trong thời gian 9h đến 17h. Trừ máy 192.168.1.23, vì bị cấm tất cả. 3
  • 4. M, T, W, H, F là viết tắt các ngày trong tuần ( chủ nhật : S, thứ bảy : A) Có thể dùng D để thay bằng các ngày trong tuần ( M - F ) b.Hạn chế truy cập các website được ấn định trước : Đầu tiên tạo 2 file ở trong thư mục /etc/squid là allowed-sites.squid và restricted-sites.squid để chứa tên các domain cho phép truy cập và cấm truy cập. # File: /squid/allowed-sites.squid www.vickifcvn.net fotech.org # File: /etc/squid/restricted-sites.squid www.sex.com xxx.net Nếu bạn muốn trong thời gian làm việc, cấm vào một số site và cho phép vào một số site nó thì : Mở file squid.conf ra : # Add this to the bottom of the ACL section of squid.conf acl home_network src 192.168.1.0/24 acl work_hours time M T W H F 9:00-17:00 acl GoodSites dstdomain "/etc/squid/allowed-sites.squid" acl BadSites dstdomain "/etc/squid/restricted-sites.squid" # Add this at the top of the http_access section of squid.conf http_access deny BadSites http_access allow home_network work_hours GoodSites Bạn có thể dùng url_regex để hạn chế vào các domain name được ấn định: # Add this to the bottom of the ACL section of squid.conf acl domainname url_regex -i ^http://www # Add this at the top of the http_access section of squid.conf http_access deny domainname 4
  • 5. c.Hạn chế truy cập web theo địa chỉ ip : Bạn có thể tạo một access control list để hạn chế truy cập web trên một mạng nào đó. # Add this to the bottom of the ACL section of squid.conf acl home_network src 192.168.1.0/255.255.255.0 acl localhost dst 127.0.0.0/8 # Add this at the top of the http_access section of squid.conf http_access allow home_network http_access allow localhost d.Hạn chế nội dung các file download: Tạo một file chứ nội dung các phần đuôi của các tập tin mà bạn muốn hạn chế là blocks.files.acl nằm trong /etc/squid .[Ee][Xx][Ee]$ .[Aa][Vv][Ii]$ .[Mm][Pp][Gg]$ .[Mm][Pp][Ee][Gg]$ .[Mm][Pp]3$ Thêm vào squid.conf dòng # Add this to the bottom of the ACL section of squid.conf acl blockfiles urlpath_regex “/etc/squid/blocks.files.acl” # Add this at the top of the http_access section of squid.conf http_access deny blockfiles e.Hạn chế truy cập theo cổng : vd # Add this to the bottom of the ACL section of squid.conf acl httpports port 80 8000-8010 8080 5
  • 6. # Add this at the top of the http_access section of squid.conf http_access allow httpports Các bạn nên duy trì và allow một số cổng. Dưới đây là một số cổng được cho là an toàn ( mặc định trong file squid.conf ) # Add this to the bottom of the ACL section of squid.conf acl safe_ports port 80 # http acl safe_ports port 21 # ftp acl safe_ports port 443 563 # https snews 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 480 # gss-http acl safe_ports port 591 # filemaker acl safe_ports port 777 # multiling http # Add this at the top of the http_access section of squid.conf http_access deny !safe_ports f.Hạn chế truy cập theo giao thức : # Add this to the bottom of the ACL section of squid.conf acl FTP proto FTP # Add this at the top of the http_access section of squid.conf http_access deny FTP g.Dùng NCSA kiểm định password: đầu tiên tạo một file password,vd /etc/squid/squid_passwd touch /etc/squid/squid_passwd chmod o+r /etc/squid/squid_passwd 6
  • 7. Dùng htpasswd để add user vào pass vào file squid_passwd đó htpasswd /etc/squid/squid_passwd vicki New password: Re-type new password: Adding password for user vicki giờ thêm vào file squid.conf # Add this to the auth_param section of squid.conf auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/squid_passwd # Add this to the bottom of the ACL section of squid.conf acl ncsa_users proxy_auth REQUIRED # Add this at the top of the http_access section of squid.conf http_access allow ncsa_users Như vậy phải dùng user và pass được add vào file squid_passwd mới có thể truy cập vào internet được. Cũng có thể kết hợp thời gian để bắt kiểm định pass vào mốc thời gian nhất định ( tham khảo đầu bài ) Nếu bạn muốn mọi deny đều có một thông báo cho người dùng biết thì : Tạo một file deny.php với nội dung tùy bạn, đặt vào /var/www chẳng hạn. acl blacklist url_regex yahoo.com vietnamnet.vn http_access deny blacklist deny_info domain/deny.php blacklist 7
  • 8. PHỤ LỤC MỘT SỐ VÍ DỤ KHÁC VỀ ACL SQUID Hạn chế truy cập web theo thời gian và cấm các IP chỉ định đi web acl home_network src 192.168.1.0/24 acl allow_hours time M T W H F 9:00-17:00 acl RestrictedHost src 192.168.1.200 http_access deny RestrictedHost http_access allow home_network allow_hours Hạn chế truy cập web theo thời gian và loại trừ IP của các sếp acl home_network src 192.168.1.0/24 acl allow_hours time M T W H F 9:00-17:00 acl AllowHost src "/etc/squid/AllowHost.txt" http_access allow AllowHost http_access allow home_network allow_hours # vi /etc/squid/AllowHost.txt 192.168.1.100 192.168.1.200 Tự động redirect sang website ấn định trước khi truy cập những website ko được phép acl home_network src 192.168.1.0/24 acl denywebsite dstdom_regex "/etc/squid/denywebsite.txt" http_access deny denywebsite deny_info http://vnlamp-test.vn/deny.html denywebsite >> tất nhiên đã cấu hình dns & httpd #deny_info http://www.google.com.vn denywebsite >> redirect tới google # deny_info TCP_RESET denywebsite >> reset the TCP connection (blank page) http_access allow home_network # vi /var/www/html/deny.html "This site has restricted by administrator" Hạn chế tên tập tin download acl home_network src 192.168.1.0/24 acl blockfiles urlpath_regex "/etc/squid/block.files.acl" http_access deny blockfiles http_access allow home_network hoặc acl home_network src 192.168.1.0/24 acl denyfiletypes url_regex -i .mp3$ .mpg$ .mpeg$ .mp2$ .avi$ .wmv$ .wma$ .exe$ http_access deny denyfiletypes http_access allow home_network Dùng htpasswd để add user và pass vào file squid_passwd mới tạo # htpasswd /etc/squid/squid_passwd u1 New password: 8
  • 9. Re-type new password: Adding password for user u1 # Edit file squid.conf auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/squid_passwd acl ncsa_users proxy_auth REQUIRED http_access allow ncsa_users Cho phép một range IP chỉ truy cập vào những trang web cố định acl allow_domains dstdomain url_regex "/etc/squid/local/access-local.txt" acl ip-local src "/etc/squid/ip-local.txt" http_access deny ip-local !allow_domains http_access allow ip-local # vi /etc/squid/local/access-local.txt .vnexpress.net .tuoitre.com.vn # vi /etc/squid/local/ip-local.txt 192.168.1.0/24 Cấm truy cập vào yahoo acl aclyahoo dstdomain pager.yahoo.com acl aclyahoo dstdomain shttp.msg.yahoo.com acl aclyahoo dstdomain update.pager.yahoo.com acl aclyahoo dstdomain scsa.yahoo.com acl aclyahoo dstdomain msg.yahoo.com http_access deny aclyahoo Cấm download file có dung lượng >=10MB acl home_network src 192.168.2.0/24 acl denywebsite dstdom_regex "/etc/squid/denywebsite.txt" http_access deny denywebsite deny_info http://www.google.com.vn denywebsite reply_body_max_size 10000000 allow home_network http_access allow home_network http_access deny all icp_access allow all Cấu hình Squid Proxy Server để điều khiển băng thông Bước 1: Thêm vào trong file cấu hình squid một số phần như sau: # vi /etc/squid/squid.conf # Add Control Bandwith acl ip src "/etc/squid/ip.txt" # ip trong file ip.txt bị giới hạn acl all src 0.0.0.0/0.0.0.0 # Add Control Bandwith delay_pools 1 delay_class 1 2 delay_access 1 allow ip 9
  • 10. delay_access 1 deny all delay_parameters 1 -1/-1 15000/15000 Với delay_parameters 1 -1/-1 15000/15000 ta sẽ giới hạn băng thông cho các client không thể vượt quá 15000 tương đương 15Kbps Bước 2: Tạo file ip.txt như sau: # vi /etc/squid/ip.txt 192.168.1.33 192.168.1.34 Vậy các IP trong file ip.txt sẽ có băng thông tối đa là 15Kbps # Block online streaming of Audio/Video acl BlockExt url_regex -i .mp3$ .asx$ .wma$ .wmv$ .avi$ .mpeg$ .mpg$ .qt$ .ram$ .rm$ .iso$ .wav$ .exe$ acl webRadioReq1 req_mime_type -i ^video/x-ms-asf$ acl webRadioReq2 req_mime_type -i ^application/vnd.ms.wms-hdr.asfv1$ acl webRadioReq3 req_mime_type -i ^application/x-mms-framed$ acl webRadioRep1 rep_mime_type -i ^video/x-ms-asf$ acl webRadioRep2 rep_mime_type -i ^application/vnd.ms.wms-hdr.asfv1$ acl webRadioRep3 rep_mime_type -i ^application/x-mms-framed$ acl WMP browser Windows-Media-Player/* http_access deny BlockExt !UtentiGold http_access deny WMP all http_access deny webRadioReq1 all http_access deny webRadioReq2 all http_access deny webRadioReq3 all http_reply_access deny webRadioRep1 all http_reply_access deny webRadioRep2 all http_reply_access deny webRadioRep3 all ( 1. Added the extensions .wma and .wmv at the following line, so it's impossible to dowlonload these file types acl BloccoExt url_regex -i .mp3$ .asx$ .wma$ .wmv$ .avi$ .mpeg$ .mpg$ .qt$ .ram$ .rm$ .iso$ .wav$ .exe$ 2. Created acl for the other two 2 mime types (maybe not necessary) acl webRadioReq1 req_mime_type -i ^video/x-ms-asf$ acl webRadioReq2 req_mime_type -i ^application/vnd.ms.wms-hdr.asfv1$ acl webRadioReq3 req_mime_type -i ^application/xmms-framed$ acl webRadioRep1 rep_mime_type -i ^video/x-ms-asf$ acl webRadioRep2 rep_mime_type -i ^application/vnd.ms.wms-hdr.asfv1$ acl webRadioRep3 rep_mime_type -i 10
  • 11. ^application/x-mms-framed$ 3. Added this too... acl WMP browser Windows-Media-Player/* 4. Created following rules http_access deny BloccoExt !UtentiGold http_access deny WMP ! UtentiGold http_access deny webRadioReq1 !UtentiGold http_access deny webRadioReq2 ! UtentiGold http_access deny webRadioReq3 !UtentiGold http_reply_access deny webRadioRep1 !UtentiGold http_reply_access deny webRadioRep2 ! UtentiGold http_reply_access deny webRadioRep3 !UtentiGold Notes:UtentiGold is an ip list of privileged users (CEO, ecc.) In this mode, if I'm not a privileged user, I'm not able to open web radio (example http://bbwms.libero.it/lifegate) with IE6 and WMP9, clicking on a link or typing the url ) 11