สำหรับผู้ที่กำลังจะทำ Proxy ไว้ใช้ในองค์กรขนาดเล็ก บวกกับ DHCP แบบง่าย ๆ มาดูวิธีการติดตั้งและ Configure กันครับ
1. ติดตั้ง ubuntu
ใช้ ubuntu server หรือ ubuntu desktop ก็ได้ครับ แต่ที่ผมทำ ใช้ linuxmint (ubuntu 8.10) สำหรับวิธีการติดตั้ง คงไม่ได้กล่าวนะครับ
2. ติดตั้ง DHCP3-server
sudo aptitude update
sudo aptitude install dhcp3-server
หากเครื่องนี้มีการ์ดแลน 2 ใบ เช่น
eth0 connect to Router
eth1 connect to Switch (Local LAN)
Set Network
sudo vim /etc/network/interfaces
auto lo
auto eth0
iface eth0 inet static
address 192.168.0.13
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.254
gateway 192.168.0.11
auto eth1
iface eth1 inet dhcp
iface lo inet loopback
save & restart serverice
แก้ไข ip_forward
#vim /etc/sysctl.conf
เปิดใช้งาน net/ipv4/ip_forward=1
#echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
Configure DHCP3-server
มี 2 จุดที่ต้องแก้ไข คือ
1. sudo vim /etc/default/dhcp3-server
INTERFACES="eth1"
ผมเลือกใช้ eth1 เป็นตัวแจก DHCP
2. Edit dhcpd.conf
ส่วนนี้เราสามารถกำหนดได้ว่าจะให้เครื่อง Client ใด หรือ Server ใด ใช้ไอพีที่ต้องต้องการได้ เพื่อนำไปปรับใช้กับโปรแกรม Squid ในการกำหนดให้ Client เล่นเอ็ม ห้ามเข้าเว็บไซต์ หรือห้ามดาวน์โหลดไฟล์พวก exe เป็นต้น
ก่อนอื่นก็ต้องแบ็คอัพ File เดิมเอาไว้ก่อน ดังนี้
sudo cp /etc/dhcp3/dhcpd.conf /etc/dhcp3/dhcpd.conf.bak
sudo vim /etc/dhcp3/dhcpd.conf
แก้ไขด้านล่างต่อไปนี้
option domain-name-servers 202.170.119.9, 203.144.207.29;
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.135 192.168.0.230;
option domain-name-servers 202.170.119.9, 203.144.207.29;
option routers 192.168.0.13;
option broadcast-address 192.168.0.254;
default-lease-time 600;
max-lease-time 7200;
}
# กำหนดให้เครื่อง Client fix ip ตามที่เราต้องการ
host akom-linuxmint {
hardware ethernet 00:11:2f:e8:97:21;
fixed-address 192.168.0.3;
}
host proxyserver {
hardware ethernet 00:01:29:4b:44:94;
fixed-address 192.168.0.13;
}
save & restart DHCP service
3. ติดตั้ง Squid Transparent
sudo aptitude install squid squid-common
Configure
ก่อนอื่นต้องแบ็คอัพค่า configure เดิมไว้ก่อน
sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.bak
sudo vim /etc/squid/squid.conf
http_port 3128 transparent
visible_hostname proxyserver
cache_mem 32 MB
maximum_object_size_in_memory 8 KB
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^http:// 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
#auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid.passwd
#auth_param basic children 5
#auth_param basic realm NFYE Squid proxy-caching web server
#auth_param basic credentialsttl 3 hours
#auth_param basic casesensitive off
acl all src 0.0.0.0/0.0.0.0
acl internal_network src 192.168.0.0/24
# Block MsN
acl msn_user src "/etc/squid/msn_user_list.txt"
acl msn_server req_mime_type application/x-msn-messenger
acl msn_server2 req_mime_type ^application/x-msn-messenger$
acl msn_url url_regex -i gateway.dll
# Block web
acl lockweb url_regex '/etc/squid/lockweb.txt'
#acl users proxy_auth REQUIRED
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 # https, snews
acl SSL_ports port 873 # rsync
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 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl Safe_ports port 631 # cups
acl Safe_ports port 873 # rsync
acl Safe_ports port 901 # SWAT
#acl sectionx proxy_auth REQUIRED
acl purge method PURGE
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny !msn_user msn_server
http_access deny !msn_user msn_url
http_access deny !msn_user msn_server2
http_access deny lockweb
http_access deny manager
http_access deny purge
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
#http_access allow users
http_access allow internal_network
http_access allow purge localhost
http_access allow localhost
http_access deny all
http_reply_access allow all
icp_access allow all
coredump_dir /var/spool/squid
cache_dir ufs /var/spool/squid 1024 16 256
access_log /var/log/squid/access.log squid
cache_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log
# Banwidht Control
acl bcsc_local url_regex -i 192.168
acl bcsc_admin src 192.168.0.13 192.168.0.3
acl bcsc_download url_regex -i ftp .3gp .aac .ac3 .act .aif .aiff .amr .asf .au .avi .b5t .bin .bwt .cab .ccd .cdi .cue .dat .dct .div .divx .dss .exe .flac .fli .flv .gho .gsm .gz .ifo .img .iso .m4a .mp2 .mp3 .mp4 .mov .mpe .mpga .mpg .mpeg .mds .nrg .ogg .pdi .qt .ra .ram .rar .raw .rcd .rec .rm .rmvb .rmj .rpm .sea .shn .sri .swf .tar .tgz .vob .vox .vqf .wav .wmv .wma .zip .7z
acl bcsc_unlimit_bandwidth time MTWHFAS 09:00-16:00
acl bcsc_upload url_regex -i .com .avi .mpg .iso .wav .wma .dat .cda .wm .mid .midi .mp3
delay_pools 3
delay_class 1 2
delay_parameters 1 -1/-1 -1/-1
delay_access 1 allow bcsc_local
delay_access 1 allow !bcsc_unlimit_bandwidth
delay_access 1 allow bcsc_admin
delay_class 2 2
delay_parameters 2 256000/256000 256000/512000
delay_access 2 allow bcsc_download
delay_class 3 2
delay_parameters 3 20480/20480 20480/40960
delay_access 3 allow bcsc_upload
delay_access 2 deny !bcsc_unlimit_bandwidth
delay_access 2 allow bcsc_admin
สร้างไฟล์ /etc/squid/msn_user_list.txt ใส่ไอพี่ที่ให้เล่นเอ็มได้ลงไป ดังนี้
192.168.0.3
.
.
เสร็จแล้วก็ save & restart squid
squid -k reconfigure # เมื่อมีการแก้ไขค่าต่าง ๆ ใน squid ให้ใช้คำสั่งนี้ สำหรับให้อ่านค่าคอนฟิก
tail -F /var/log/squid/access.log | awk '{print $3 "\t" $4 "\t" $7}'
tail -f /var/log/squid/access.log | awk '{print$3 " " $8 " " $7}'
ดู Log File เพื่อให้แสดงส่วนท้ายของไฟล์ access.log คอลัมน์ที่ 3 4และ 7
---------------------------------------
192.168.0.26 TCP_REFRESH_HIT/200 http://gossipstar.mthai.com/css/ie7.css
192.168.0.26 TCP_REFRESH_HIT/200 http://gossipstar.mthai.com/css/main.css,style.css,option_index.css,switcher.css
192.168.0.26 TCP_REFRESH_HIT/200 http://gossipstar.mthai.com/js/ie7.js
192.168.0.26 TCP_REFRESH_HIT/200 http://gossipstar.mthai.com/js/switcher.js
192.168.0.26 TCP_HIT/200 http://gossipstar.mthai.com/css/index/bg.gif
---------------------------------------
จบแล้วครับ