Skenario:
Internet:192.168.1.1 — eth1:192.168.1.5:CentOS Squid:eth0:192.168.0.254 — LAN
I.Setting Statik IP Address,DNS,Hostname:
Using wizard:
# system-config-network-tui
or manual setup IP Address:
-Setting IP Address Statik eth0
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
# Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+
# Xen Virtual Ethernet
DEVICE=eth0
BOOTPROTO=static
ONBOOT=yes
HWADDR=32:7a:f1:b0:31:e5
IPADDR=192.168.0.254
NETMASK=255.255.255.0
NETWORK=192.168.0.0
-Setting IP Address Statik eth1
# vi /etc/sysconfig/network-scripts/ifcfg-eth1
# Xen Virtual Ethernet
DEVICE=eth1
BOOTPROTO=static
ONBOOT=yes
HWADDR=0a:b7:40:a5:3d:82
IPADDR=192.168.1.5
NETMASK=255.255.255.248
NETWORK=192.168.1.0
GATEWAY=192.168.1.1
-Setting IP DNS:
# vi /etc/resolv.conf
search example.com
nameserver 192.168.0.250
nameserver 192.168.0.251
nameserver 8.8.8.8
-Setting hostname & disable ipv6:
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=cumi.example.com
-Update Server
# yum –y update
II. Setting NAT/Sebagai Router/Gateway
-Enable IP forwarding
# sysctl -w net.ipv4.ip_forward=1
-To enable it in system startup, edit the file /etc/sysctl.conf
# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1
-Enables packet forwarding by kernel
# echo 1 > /proc/sys/net/ipv4/ip_forward
Atau edit /proc/sys/net/ipv4/ip_forward , ganti angka 0 menjadi 1
-Setting iptables untuk NAT
# iptables --table nat --append POSTROUTING --out-interface eth1 -j MASQUERADE
# service iptables save
# service iptables restart
-Testing ping or browsing dari client
If work then your linux box has become a linux router now and ready for next step
III. Install & Setting Squid 2.7 rpm
-Install dependencies & needed packages
# yum -y install perl-URI
-Install Paket Squid 2.7 STABLE 9-1
# mkdir /tmp/squid2.7Stable9
# cd /tmp/squid2.7Stable9
Download untuk CentOS 5 64bit:
# wget http://people.redhat.com/jskala/squid/squid-2.7.STABLE9-1.el5/x86_64/squid-2.7.STABLE9-1.el5.x86_64.rpm
# rpm -ivh squid-2.7.STABLE9-1.el5.x86_64.rpm
Download untuk CentOS 5 32bit:
# wget http://people.redhat.com/jskala/squid/squid-2.7.STABLE9-1.el5/i386/squid-2.7.STABLE9-1.el5.i386.rpm
# rpm -ivh squid-2.7.STABLE9-1.el5.i386.rpm
-Cek apakah squid sudah terinstall atau belum
# rpm -qa |grep squid
-Konfigurasi Squid, edit /etc/squid.conf
# cp /etc/squid/squid.conf /etc/squid/squid.conf.asli
# vi /etc/squid/squid.conf
# Squid 2.7 Stable 9
# -----------------------
# 2. ACCESS CONTROLS(ACL)
# ------------------------------
# 2.b.SET WAKTU BLOK (Tag: ACL)
# ------------------------------
#acl jam_blok_pagi time MTWHF 09:00-11:00
#acl jam_blok_siang time MTWHF 13:00-15:30
#acl jam_blok_sabtu time A 09:30-12:00
#acl jam_blok_tes time SMTWHFA 15:00-20:00
# 2.b.SET ACL BOS/MAC ADDRESS&IP (Tag: ACL)
# ------------------------------
#acl ip_bowie src 192.168.0.30/255.255.255.255
#acl macaddress_bowie arp 00:1F:D0:A5:CA:14
#acl allow_mac arp "/etc/squid/macaddress/allow_mac.txt"
#acl deny_mac arp "/etc/squid/macaddress/deny_mac.txt"
#acl lanstaff src 192.168.0.30-192.168.0.200/32
acl ipserver src "/etc/squid/spesialip/ipserver.txt"
# 2.b.ACL URL & SITUS2 YG DIBLOCKED PERMANEN (Tag: ACL)
# ------------------------------------------------
#acl bloksitesurl url_regex -i "/etc/squid/blacklist/bloksitesurl.txt"
#acl bloksites dstdomain "/etc/squid/blacklist/bloksites.txt"
# 2.b.ACL SITUS2 PEMERINTAH INDONESIA & LOKAL
# ---------------------------------------------
#acl pemerintah urlpath_regex -i "/etc/squid/pemerintah.txt"
#acl asp urlpath_regex -i "/etc/squid/asp.txt"
# 2.b.ACL SITUS2 YG DIBLOCK BY TIME (Tag: ACL)
# ---------------------------------------------
#acl bloktimeurl url_regex -i "/etc/squid/blacklist/bloktimeurl.txt"
#acl bloktimesites dstdomain "/etc/squid/blacklist/bloktimesites.txt"
# 2.b.ACL WAKTU TIDAK BEBAS DOWNLOAD (Tag: ACL)
# ---------------------------------------------
#acl jam_tdkbebasdownload time MTWHF 09:30-16:30
#acl sabtu_tdkbebasdownload time A 09:30-13:00
#acl jam_tdkbebasdownload2 time MTWHFA 00:01-03:00
# 2.b.ACL FILE2 YG TIDAK BEBAS DOWNLOAD (Tag: ACL)
# ------------------------------------------------
# CONTOH:
#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
#acl blockfilesmulti urlpath_regex -i "/etc/squid/blacklist/block_files.txt"
#acl magic_words 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
acl download url_regex -i ftp .exe .mp3 .vqf .tar.gz .gz .tar .rpm .deb .zip .rar .avi .mpeg .mpe .mpg .qt .ram .rm .iso .raw .wav .mov .msi .mp4 .flv .3gp .pdf .wmv
# 2.b.SET IP ADDRESS NETWORK (Tag: ACL)
# --------------------------------------
acl all src all
acl localnet src 192.168.0.0/24
# 2.b.ACCESS CONTROLS (Tag: ACL)
# ------------------------------
acl manager proto cache_object
acl localhost src 127.0.0.1/32
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 563 # snews https juga
acl Safe_ports port 873 # rsync https lagi
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 10000 # webmin
acl Safe_ports port 873 # rsync
acl Safe_ports port 901 # SWAT
acl Safe_ports port 5050 # YM
acl Safe_ports port 110 # POP3
acl Safe_ports port 25 # SMTP
acl Safe_ports port 2095 2096 # webmail from cpanel
acl Safe_ports port 2082 2083 # cpanel
acl PURGE method PURGE
acl CONNECT method CONNECT
acl QUERY urlpath_regex cgi-bin \?
#acl QUERY1 urlpath_regex .asp .aspx
#acl asp urlpath_regex -i "/etc/squid/asp.txt"
acl asp urlpath_regex -i \.asp \.aspx
#2.c.ALLOW ACL IP ADDRESS (Tag: http_access)
# -------------------------------------------
#http_access allow ip_bowie !bloksitesurl
#http_access allow allow_mac !bloksites
#http_access deny deny_mac jam_blok_pagi
#http_access deny deny_mac jam_blok_siang
#http_access deny deny_mac jam_blok_sabtu
#http_access deny deny_mac jam_blok_tes
# 26.d. TAG: deny_info
#deny_info ERR_ACCESS_DENIED_TIME deny_mac jam_blok_tes
#deny_info ERR_ACCESS_DENIED_TIME deny_mac jam_blok_pagi
#deny_info ERR_ACCESS_DENIED_TIME deny_mac jam_blok_siang
#deny_info ERR_ACCESS_DENIED_TIME deny_mac jam_blok_sabtu
# 2.c.DENY THE BLOCKED PERMANEN VARIABLE (Tag: http_access)
# ---------------------------------------------------------
#http_access deny bloksites
#http_access deny bloksitesurl
# 2.c.DENY THE BLOCKED-TIME VARIABLE (Tag: http_access)
# -----------------------------------------------------
#http_access deny bloktimeurl jam_blok_pagi
#http_access deny bloktimeurl jam_blok_siang
#http_access deny bloktimeurl jam_blok_sabtu
#http_access deny bloktimeurl jam_blok_tes
# 26.d. TAG: deny_info
#deny_info ERR_ACCESS_DENIED_TIME blocktimesites jam_blok_tes
#deny_info ERR_ACCESS_DENIED_TIME blocktimesites jam_blok_pagi
#deny_info ERR_ACCESS_DENIED_TIME blocktimesites jam_blok_siang
#deny_info ERR_ACCESS_DENIED_TIME blocktimesites jam_blok_sabtu
# 2.c.DENY BLOCKED DOWNLOAD PADA JAM KERJA (Tag: http_access)
# -----------------------------------------------------------
#http_access deny blockfilesmulti jam_tdkbebasdownload
#http_access deny blockfilesmulti sabtu_tdkbebasdownload
#http_access deny blockfilesmulti jam_tdkbebasdownload2
# 26.d. TAG: deny_info
#deny_info ERR_BLOCKED_FILES blockfilesmulti jam_tdkbebasdownload2
#deny_info ERR_BLOCKED_FILES blockfilesmulti jam_tdkbebasdownload
#deny_info ERR_BLOCKED_FILES blockfilesmulti sabtu_tdkbebasdownload
# 2.k.DENY BLOCKED DOWNLOAD FILE GEDE PADA JAM KERJA (Tag: http_access)
# -------------------------------------
# Cancel download if file is bigger than 20MB=20480000 byte, 25 MB = 25000×1024 byte = 25600000 byte
#reply_body_max_size 20480000 deny magic_words jam_tdkbebasdownload
#reply_body_max_size 20480000 deny magic_words sabtu_tdkbebasdownload
#reply_body_max_size 25600000 deny magic_words
# 2.c.ALLOW THE IP ADDRESS (Tag: http_access)
# -------------------------------------------
#http_access deny QUERY1
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow ipserver
http_access allow localnet
http_access allow manager localhost
http_access allow localhost
http_access deny all
#http_reply_access allow all
#icp_access allow localnet
#icp_access allow localhost
#icp_access deny all
#htcp_access allow lanlocal
#htcp_access allow localhost
#htcp_access deny all
# ------------------
# 5. NETWORK OPTIONS
# ------------------
http_port 3128 transparent
# -----------------------------------------------------
# 6. OPTIONS WHICH AFFECT THE NEIGHBOR SELECTION ALGORITHM
# -----------------------------------------------------
#hierarchy_stoplist cgi-bin ?
hierarchy_stoplist .asp .aspx cgi-bin ?
# -----------------------------------------------------
# 7. MEMORY CACHE OPTIONS
# -----------------------------------------------------
cache_mem 8 MB
maximum_object_size_in_memory 8 KB
memory_replacement_policy heap GDSF
# 8. DISK CACHE OPTIONS
# -------------------------------------------------------------------------------
# cache_dir
# -------------------------------------------------------------------------------
## option cache have a methode for know the configuration,
## normally we use 80% for the /cache all, but never
## give a good performancy, so for the save configuration we
## use 50% for /cache
## x=50% for the /cache in KB
##(ex 50% X 12GB, so we use 6GB=~6,000,000KB)
## y=Average object size (use 13KB)
## z= 256 -> (((x / y) / 256) / 256) * 2 --this the method
## ex, we use 6 GB for /cache (50% ), so:
## 6,000,000 / 13 = 461538.5 / 256 = 1802.9 / 256 = 7 * 2 = 14
## So the row of cache_dir : cache_dir ufs 6000 14 256
# -------------------------------------------------------------------
cache deny QUERY
#cache deny QUERY1
cache deny asp
cache deny ipserver
cache_replacement_policy heap LFUDA
#cache_dir aufs /squidcache 6000 14 256
cache_dir aufs /squidcache 12000 28 256
minimum_object_size 0 KB
maximum_object_size 40960 KB
cache_swap_low 98
cache_swap_high 99
# ------------------
# 9. LOGFILE OPTIONS
# ------------------
access_log /var/log/squid/access.log squid
cache_log /var/log/squid/cache.log
#cache_store_log /var/log/squid/store.log
cache_store_log none
logfile_rotate 14
#emulate_httpd_log off
pid_filename /var/run/squid.pid
# OPTIONS FOR URL REWRITING
# -------------------------
# Options for squidGuard
url_rewrite_program /usr/bin/squidGuard -c /etc/squid/squidGuard.conf
# 13. OPTIONS FOR TUNING THE CACHE
# --------------------------------
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern (cgi-bin|\?) 0 0% 0
refresh_pattern . 0 20% 4320
refresh_pattern -i \.(gif|png|jpg|jpeg|ico)$ 10080 90% 43200 override-expire ignore-no-cache ignore-private
refresh_pattern -i \.(iso|avi|wav|mp3|mp4|mpeg|mpg|swf|flv|x-flv)$ 43200 90% 432000 override-expire ignore-no-cache ignore-private
refresh_pattern -i \.(deb|rpm|exe|ram|bin|pdf|ppt|doc|tiff)$ 10080 90% 43200 override-expire ignore-no-cache ignore-private
refresh_pattern -i \.(zip|gz|arj|lha|lzh|tar|tgz|cab|rar)$ 10080 95% 43200 override-expire ignore-no-cache ignore-private
#refresh_pattern -i \.(html|htm|css|js|php|asp|aspx|cgi) 1440 40% 40320
negative_ttl 1 minutes
# 14. HTTP OPTIONS
# -----------------------------------------------------------------------------
# 14.e. TAG: upgrade_http0.9
# Don't upgrade ShoutCast responses to HTTP
acl shoutcast rep_header X-HTTP09-First-Line ^ICY.[0-9]
upgrade_http0.9 deny shoutcast
# 14.h. TAG: broken_vary_encoding
#Default:
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
# 15. TIMEOUTS
# -----------------------------------------------------------------------------
forward_timeout 2 minutes
connect_timeout 1 minute
read_timeout 10 minutes
request_timeout 3 minutes
persistent_request_timeout 1 minutes
client_lifetime 1 day
half_closed_clients off
shutdown_lifetime 10 seconds
# 16. ADMINISTRATIVE PARAMETERS
# -----------------------------------------------------------------------------
cache_mgr triadi80@gmail.com
cache_effective_user squid
cache_effective_group squid
#httpd_suppress_version_string on
visible_hostname cumi.example.com
# 19. DELAY POOL PARAMETERS
# -----------------------------------------------------------------------------
# KONFIGURASI DELAY POOLS
# -----------------------
# 1 byte = 8 bits
# 1 kilobyte (K / Kb) = 2^10 bytes = 1,024 bytes
# 1 megabyte (M / MB) = 2^20 bytes = 1,048,576 bytes
# 1 gigabyte (G / GB) = 2^30 bytes = 1,073,741,824 bytes
# 1 terabyte (T / TB) = 2^40 bytes = 1,099,511,627,776 bytes
# 1 petabyte (P / PB) = 2^50 bytes = 1,125,899,906,842,624 bytes
# 1 exabyte (E / EB) = 2^60 bytes = 1,152,921,504,606,846,976 bytes
# 512 Kbps = 64 Kbytes = 64000 bytes
# 384 Kbps = 48 Kbytes = 48000 bytes
# 256 Kbps = 32 Kbytes = 32000 bytes
# 128 Kbps = 16 Kbytes = 16000 bytes
# 64 Kbps = 8 Kbytes = 8000 bytes
delay_pools 2
# aturan 1, tidak ada pembatasan
delay_class 1 2
delay_parameters 1 -1/-1 -1/-1
# aturan 2, setelah download 1024000 bytes maka download menjadi 30000 bytes/s
delay_class 2 2
delay_parameters 2 -1/1024000 30000/1024000
delay_access 2 allow download
delay_access 2 deny all
delay_access 1 deny download
delay_access 1 allow all
# 21. PERSISTENT CONNECTION HANDLING
# -----------------------------------------------------------------------------
#detect_broken_pconn on
# 23. SNMP OPTIONS
# -----------------------------------------------------------------------------
#snmp_port 3401
#acl snmpsquid snmp_community public
#snmp_access allow snmpsquid localhost
#snmp_access deny all
# 24. ICP OPTIONS
# -----------------------------------------------------------------------------
#icp_port 3130
# 26. ERROR PAGE OPTIONS
# -----------------------------------------------------------------------------
#error_directory /usr/share/squid/errors/id
# 27. OPTIONS INFLUENCING REQUEST FORWARDING
# -----------------------------------------------------------------------------
prefer_direct off
always_direct allow QUERY
always_direct allow ipserver
#always_direct allow QUERY1
always_direct allow asp
always_direct deny all
# 29. DNS OPTIONS
# -----------------------------------------------------------------------------
dns_retransmit_interval 2 seconds
dns_timeout 1 minutes
dns_defnames on
dns_nameservers 192.168.0.250 192.168.0.251
hosts_file /etc/hosts
ignore_unknown_nameservers on
ipcache_size 1024
ipcache_low 98
ipcache_high 99
fqdncache_size 1024
# 30. MISCELLANEOUS
# -----------------------------------------------------------------------------
forwarded_for off
#client_db on
retry_on_error on
uri_whitespace strip
coredump_dir /var/spool/squid
pipeline_prefetch on
-Set Permision Squid
# mkdir /squidcache (Note: better make it in a partition when installing CentOS)
# chown -R squid:squid /var/log/squid/
# chown -R squid:squid /squidcache/
# chown -R squid:squid /etc/squid/
-Membuat direktori cache squid,make it startup
# squid -z
# service squid restart
# chkconfig squid on
-Setting iptables for transparent proxy squid
# iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3128
# service iptables save
# service iptables restart
-Reboot Machine if you like
# reboot
References:
http://kusprayitna.staff.uii.ac.id/2009/01/05/membuat-server-centos-menjadi-gateway-dan-transparent-proxy-dengan-squid/
http://ugos.ugm.ac.id/wiki/panduan:centos_server:centos_sebagai_gateway_dan_proxy_server