Friday, June 8, 2012

Transparent SQUID 2.6 Configuration on Centos

SQUID 2.6 (Transparent PROXY SERVER)

Main benefit of setting transparent proxy is you do not have to setup up individual browsers to work with proxies.

Server: bhagwat-desktop (192.168.1.5 Local Network IP)
Client: Linux & Windows XP//Vista/7
Default Port NO: 8080


Please change this Setting for automatic forwarding

vi /etc/sysctl.conf
net.ipv4.ip_forward=0    >>    net.ipv4.ip_forward=1

Installation Of Required Packages:

Install the squid package with yum

yum install squid

Configure SQUID config file:

NOTE: Modify squid.conf file (Before Modifying any Files take one backup copy)

vi /etc/squid/squid.conf


#Recommended minimum configuration:
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 9100
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 Safe_ports port 9100    #  Network Printer
acl CONNECT method CONNECT
acl freesites url_regex "/etc/squid/freesites"
http_access allow freesites
acl blockfiles urlpath_regex "/etc/squid/blocks.files.acl"
http_access deny blockfiles
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
acl our_networks src 192.168.1.0/24
http_access allow our_networks
http_access allow localhost
http_access deny all
icp_access allow all
http_port 192.168.1.5:8080 transparent
hierarchy_stoplist cgi-bin ?
access_log /var/log/squid/access.log squid
ftp_passive on
acl QUERY urlpath_regex cgi-bin \?
cache deny QUERY
refresh_pattern ^ftp:        1440    20%    10080
refresh_pattern ^gopher:    1440    0%    1440
refresh_pattern .        0    20%    4320
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
visible_hostname my_squid_bhagwat
coredump_dir /var/spool/squid

Now start Squid server & also add in start up
/etc/init.d/squid start

chkconfig squid on

Now run this command to redirect all traffic on squid

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

/etc/init.d/iptables save
/etc/init.d/iptables start

Check it with this command
iptables -t nat -L


You do not have to setup up individual browsers to work with proxies.


Problems and Solution with FTP

Add following line in /etc/rc.local

/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_conntrack_irc
/sbin/modprobe iptable_nat
/sbin/modprobe ip_nat_ftp

save with :wq

then run 

/etc/rc.local

& it's done

Starting httpd: (98) Address already in use: make_sock: could not bind to address 0.0.0.0:443

Starting httpd: (98)Address already in use: make_sock: could not bind to address 0.0.0.0:443
no listening sockets available, shutting down
Unable to open logs!

Solution
netstat -ptnl | grep 443
tcp        0      0 :::443                      :::*                        LISTEN      953/sshd

Kill the process (kill -9 process_id)

check error log
tail -f /var/lof/httpd/error.log