Squid. Setup and Configuration.

Our environment:

Ubuntu Server 7.04 ( Feisty Fawn )

Hostname: Server.

LAMP: Already Installed.

Bind9: Already Installed.

Dhcp3-server: Already Installed.

NICs: 2 NICs.

eth0:Internet. IP:192.168.0.60

eth1:LAN. IP:192.168.1.1

All commands is executed under root user.

1. Setup

a. Make an update to Ubuntu.

apt-get update

b. Setup Squid

apt-get install squid

c. Setup iptables for transferring data to SQUID

c. 1. Create /etc/squid/iptablesquid.sh and save with content

#!/bin/sh
# squid server IP
SQUID_SERVER="192.168.1.1"
# Interface connected to Internet
INTERNET="eth0"
# Interface connected to LAN
LAN_IN="eth1"
# Squid port
SQUID_PORT="3128"
# DO NOT MODIFY BELOW
# Clean old firewall
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
# Load IPTABLES modules for NAT and IP conntrack support
modprobe ip_conntrack
modprobe ip_conntrack_ftp
# For win xp ftp client
modprobe ip_nat_ftp
echo 1 > /proc/sys/net/ipv4/ip_forward
# Setting default filter policy
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
# Unlimited access to loop back
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
# Allow UDP, DNS and Passive FTP
iptables -A INPUT -i $INTERNET -m state --state ESTABLISHED,RELATED -j ACCEPT
# set this system as a router for Rest of LAN
iptables --table nat --append POSTROUTING --out-interface $INTERNET -j MASQUERADE
iptables --append FORWARD --in-interface $LAN_IN -j ACCEPT
# unlimited access to LAN
iptables -A INPUT -i $LAN_IN -j ACCEPT
iptables -A OUTPUT -o $LAN_IN -j ACCEPT
# DNAT port 80 request coming from LAN systems to squid 3128 ($SQUID_PORT) aka transparent proxy
iptables -t nat -A PREROUTING -i $LAN_IN -p tcp --dport 80 -j DNAT --to $SQUID_SERVER:$SQUID_PORT
# if it is same system
iptables -t nat -A PREROUTING -i $INTERNET -p tcp --dport 80 -j REDIRECT --to-port $SQUID_PORT
# DROP everything and Log it
iptables -A INPUT -j LOG
iptables -A INPUT -j DROP

c.2. Add the bash script to the system.

Setup post-up option, append following line to /etc/network/interfaces

post-up /etc/squid/iptablesquid.sh

 

2. Configuration

a. Copy /etc/squid/squid.conf to /etc/squid/squid(backup).conf

b. Set visible_hostname in /etc/squid/squid.conf

visible_hostname server

c. Port of squid in /etc/squid/squid.conf. From this port, Squid will listen data, from iptables.

c.1 Normal.

For a server that LAN client must enter proxy server to access Internet.

http_port 3128 # 

c.2 Transparent

For a server that LAN’s client don’t need to enter proxy server. This type needs a configuration: 2 NICs.

http_port 3128 transparent # 

3. Test the Squid

a. Add an acl PornSites in /etc/squid/squid.conf

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 purge method PURGE
acl CONNECT method CONNECT
acl PornSites url_regex Porn

b. Add a rule in /etc/squid/squid.conf: prevent PornSites

 
http_access deny PornSites
http_access allow all
http_access deny all

c. Start testing

Server:

/etc/init.d/squid restart
/etc/squid/iptablesquid.sh

Client:

Way 1:

pathping -n google.com

Way 2:

If success you will see "ERROR, The request URL could not be retrieved"

4. Tricks and Error Troubleshooting( update continuously from comments)

a. Start squid and it is down.

Solution: – Check out in /etc/init.d. If it have 2 bash:squid and squid3, then it means you’ve installed 2 versions of squid on a same machine. You should remove squid 3:

apt-get remove --purge squid3

b. …

 

5. References:
http://www.cyberciti.biz/tips/linux-setup-transparent-proxy-squid-howto.html
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: