buat proxy dengan murah

Written By Unknown on Sabtu, 23 Februari 2013 | 19.53

Dengan modal Rp 400.000,00 beli sebuah PC tua (tanpa monitor, mouse, dan keyboard. Cuman 1 kotak PC doank ama jeroan di dalamnya :D ). Berikut spesifikasi si PC tua ini :
1.) Processor Intel Pentium 3 800 MHz
2.) Memory (SDRAM) 256 MB (2 slot).
3.) Harddisk 20 GB
4.) LAN Card SMC 10/100 2 buah (untuk eth0 dan eth1).
5.) Sistem operasi CentOS.
Pertama kali, tentu saja instalasi CentOS di PC tua tadi, pilih instalasi mode minimal (tanpa GUI). CentOS sendiri adalah distro turunan Red Hat, masih sodaraan dengan Fedora yang saya pakai di PC :D Kemudian tambahkan paket rpmbuild yang akan digunakan saat mengkompile paket source rpm squid.
Kemudian melakukan setting IP untuk kedua LAN card (eth0 dan eth1) yang terpasang. a.) Pada etho (menghubungkan proxy server dengan modem ADSL Speedy), diberikan settingan sebagai berikut :
IP Address : 192.168.1.2
Netmask : 255.255.255.0
Gateway : 192.168.1.1 (alamat IP modem ADSL)
Primary DNS : 202.134.0.155 (ISP Telkom)
Secondary DNS : 202.134.2.5 (ISP Telkom)
b.) Pada eth1 (terhubung ke switch, menghubungkan proxy server dengan client lainnya), diberikan settingan sebagai berikut :
IP Address : 192.168.50.99
Netmask : 255.255.255.0
Kemudian dilakukan otentikasi MAC Address (access control) di Squid, sehingga hanya MAC Adrress yang terdaftar saja yang bisa menggunakan layanan internet ini.
Langkah-langkahnya sebagai berikut :
1.) Unduh filenya di ftp://ftp.redhat.com/pub/redhat/linux/enterprise/5Server/en/os/SRPMS/squid-2.6.STABLE6-5.el5_1.3.src.rpm
2.) Install file rpm tadi dengan cara :
rpm -ivh squid-2.6.STABLE6-5.el5_1.3.src.rpm
3.) Ketik updatedb
4.) Edit file squid.spec (saya menggunakan vim, silahkan gunakan sesuai selera anda, misal nano, kedit, atau lainnya).
vim /usr/src/redhat/SPECS/squid.spec
5.) Tambahkan 2 baris ini di bagian paling bawah dari isi file squid.spec :
enable-arp
enable-arp-acl
6.) Lakukan perintah berikut ini :
rpmbuild -ba /usr/src/redhat/SPECS/squid.spec
Dan tunggu sampai selesai :D
7.) Kemudian lanjutkan dengan meload file rpm :
rpm -ivh /usr/src/redhat/RPMS/i386/squid-2.6.STABLE6-5.3.i386.rpm
Kemudian lakukan konfigurasi pada file squid.conf (vim /etc/squid/squid.conf) :
============= isi file konfigurasi ===============
#SQUID 2.6.STABLE6
#Author by: http://fxekobudi.net
# OPTION JARINGAN
# —————————————————————————–
http_port 3128
icp_port 0
# OPTION UKURAN CACHE
# —————————————————————————–
cache_mem 64 MB
cache_swap_low 94
cache_swap_high 96
maximum_object_size 16384 KB
minimum_object_size 4 KB
maximum_object_size_in_memory 2048 KB
fqdncache_size 1024
cache_replacement_policy heap GDSF
memory_replacement_policy heap GDSF
# DIREKTORI LOG DAN CACHE
# —————————————————————————–
cache_dir aufs /var/spool/squid 9000 16 256
access_log /var/log/squid/access.log squid
cache_log /var/log/squid/cache.log
cache_store_log none
# TUNING CACHE PROXY
# —————————————————————————–
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320
negative_ttl 1 minutes
# TIMEOUT
# —————————————————————————–
half_closed_clients off
# ————————————-
# Memblok situs terlarang (blacklist)secara manual
# ————————————-
#acl noblacklist dstdomain “/etc/squid/blacklist/no-blacklist.txt”
#acl katablacklist url_regex -i “/etc/squid/blacklist/kata-blacklist.txt”
#acl domainblacklist dstdomain “/etc/squid/blacklist/domain-blacklist.txt”
#acl ipblacklist dst “/etc/squid/blacklist/ip-blacklist.txt”
# AKSES KONTROL
# —————————————————————————–
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
# ————————————-
# Daftar IP address
# ————————————-
#acl lab1 src 192.168.254.1-192.168.254.40/255.255.255.255
#acl staf-it src 192.168.254.41-192.168.254.42/255.255.255.255
#acl lab2 src 192.168.254.43-192.168.254.44/255.255.255.255
#acl ruang1 src 192.168.1.1-192.168.1.8/255.255.255.255
#acl ruang2 src 192.168.1.11-192.168.1.17/255.255.255.255
# ————————————-
# Daftar MAC address
# ————————————-
acl MACAstina arp 00:C0:4A:02:18:CD 00:11:2F:67:7A:43 00:1B:FC:D8:22:15
# ————————————-
# Memblok situs terlarang secara manual
# ————————————-
#http_access allow noblacklist
#http_access deny katablacklist
#http_access deny domainblacklist
#http_access deny ipblacklist
http_access allow manager localhost
http_access deny manager
# ————————————-
# Rule yang saya terapkan
# ————————————-
http_access allow MACAstina
# ————————————-
# Membatasi download
# ————————————-
acl bebasdownload time 01:00-08:00
acl magic_words2 url_regex -i ftp .exe .mp3 .vqf .tar.gz .gz .tar.bz2 .bz2 .rpm .zip .rar .avi .mpeg .mpe .mpg .qt .ram .rm .raw .wav .iso
delay_pools 2
delay_class 1 2
delay_access 1 allow magic_words2 !bebasdownload
delay_access 1 deny all
delay_parameters 1 125000/125000 5000/125000
delay_class 2 2
delay_access 2 allow MACAstina
delay_access 2 deny all
delay_parameters 1 -1/-1 -1/-1
# Cancel download if file is bigger than 2 MB = 2000×1024 byte = 2048000 byte
#reply_body_max_size 2048000 allow magic_words2 tdkbebasdownload
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost
http_access deny all
http_reply_access allow all
icp_access allow all
# PARAMETER ADMINISTRATOR
# —————————————————————————–
cache_mgr ptlibra16@gmail.com
cache_effective_user squid
cache_effective_group squid
visible_hostname ASTINA
# PESAN ERROR DALAM BAHASA INDONESIA
# —————————————————————————–
error_directory /usr/share/squid/errors/Indonesian
============= isi file konfigurasi ===============
Kemudian dilanjutkan dengan konfigurasi firewall menggunakan IPTables agar client dapat mengakses internet Speedy via proxy server, dengan port yang digunakan 3128.
Berikut isi shell script yang dinamakan firewall.sh
=========== isi file firewall.sh ==================
#vi firewall.sh
#!/bin/sh
LAN=”eth1″
INTERNET=”eth0″
IPTABLES=”/sbin/iptables”
# Kernel monitoring support
# More information:
# /usr/src/linux-`uname -r`/Documentation/networking/ip-sysctl.txt
# http://www.linuxgazette.com/book/view/1645
# http://www.spirit.com/Network/net0300.html
# Drop ICMP echo-request messages sent to broadcast or multicast addresses
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
# Drop source routed packets
echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
# Enable TCP SYN cookie protection from SYN floods
echo 1 > /proc/sys/net/ipv4/tcp_syncookies
# Don’t accept ICMP redirect messages
echo 0 > /proc/sys/net/ipv4/conf/all/accept_redirects
# Don’t send ICMP redirect messages
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
# Enable source address spoofing protection
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
# Log packets with impossible source addresses
echo 1 > /proc/sys/net/ipv4/conf/all/log_martians
# Needed for FTP (specifically, to allow incoming ftp-data connections)
/sbin/modprobe ip_conntrack_ftp
# Flush all chains
$IPTABLES –flush
# Allow unlimited traffic on the loopback interface
$IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A OUTPUT -o lo -j ACCEPT
# Set default policies
$IPTABLES –policy INPUT DROP
$IPTABLES –policy OUTPUT DROP
$IPTABLES –policy FORWARD DROP
# Previously initiated and accepted exchanges bypass rule checking
$IPTABLES -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A OUTPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
# Allow incoming port 22 (ssh) connections on LAN interface
$IPTABLES -A INPUT -i $LAN -p tcp –destination-port 22 -m state \
–state NEW -j ACCEPT
# Allow incoming port 3128 (squid) connections on LAN interface
$IPTABLES -A INPUT -i $LAN -p tcp –destination-port 3128 -m state \
–state NEW -j ACCEPT
# Allow ICMP ECHO REQUESTS on LAN interface
$IPTABLES -A INPUT -i $LAN -p icmp –icmp-type echo-request -j ACCEPT
# Allow DNS resolution
$IPTABLES -A OUTPUT -o $INTERNET -p udp –destination-port 53 -m state \
–state NEW -j ACCEPT
$IPTABLES -A OUTPUT -o $INTERNET -p tcp –destination-port 53 -m state \
–state NEW -j ACCEPT
# Allow ntp synchronization
$IPTABLES -A OUTPUT -o $LAN -p udp –destination-port 123 -m state \
–state NEW -j ACCEPT
# Allow ssh on LAN interface
$IPTABLES -A OUTPUT -o $LAN -p tcp –destination-port 22 -m state \
–state NEW -j ACCEPT
# Allow Squid to proxy ftp, http, https, and AIM traffic
$IPTABLES -A OUTPUT -o $INTERNET -p tcp –destination-port 21 -m state \
–state NEW -j ACCEPT
$IPTABLES -A OUTPUT -o $INTERNET -p tcp –destination-port 80 -m state \
–state NEW -j ACCEPT
$IPTABLES -A OUTPUT -o $INTERNET -p tcp –destination-port 443 -m state \
–state NEW -j ACCEPT
$IPTABLES -A OUTPUT -o $INTERNET -p tcp –destination-port 5190 -m state \
–state NEW -j ACCEPT
# Create a LOGDROP chain to log and drop packets
$IPTABLES -N LOGDROP
$IPTABLES -A LOGDROP -j LOG
$IPTABLES -A LOGDROP -j DROP
# Drop all other traffic
$IPTABLES -A INPUT -j LOGDROP
# Have these rules take effect when iptables is started
/sbin/service iptables save
=========== isi file firewall.sh ==================
Berikan permission pada file firewall.sh tadi agar bisa dieksekusi :
# chmod +x firewall.sh
Lalu jalankan dengan cara ./firewall.sh
Pada kondisi ini, PC telah siap menjadi sebuah proxy server untuk kosan. Permasalahn kemudian muncul, yaitu, mengingat ini adalah sebuah PC biasa yang disetup menjadi server proxy untuk 19 client, keterbatasannya (termasuk juga keterbatasan modem ADSL Speedy) jika dihidupkan terus 24 jam x 7 hari setiap bulan, maka saya dan anak-anak rapat kembali dan memutuskan bahawa dalam seminggu ada 2 kali jadwal “pemadaman” server proxy, masing-masing 6 jam, sehingga kedua benda itu (PC dan modem) bisa istirahat sebentar. nah, agar saat setelah masa istirahat itu squid dapat langsung berjalan otomatis saat PC dihidupkan, maka ditambahkan command berikut :
#echo “/usr/sbin/squid -D” >> /etc/rc.local
Demikian sedikit pengalaman saat mensetup PC biasa menjadi sebuah proxy server untuk internet Speedy di kosan :)
NB :
Berikut beberapa command di Squid :
1.) Menjalankan Squid:
#/sbin/service squid start
2.) Menghentikan Squid
#/sbin/service squid stop
3.) Restart Squid
#/sbin/service squid restart
4.) Monitoring delay pool level via cache manager interface. Request delay page dari CGI interface atau squidclient utility.
# /usr/sbin/squidclient mgr:delay | less

0 komentar:

Posting Komentar

komentar