Friday, October 2, 2009

Transparent Proxy with Squid & Iptables on Fedora 9

Chkconfig NetworkManager off & Disable selinux
/etc/sysctl.conf -> Ipforward = 1 and Install Squid, Dhcp, Bind, Openssh.
/etc/hosts
127.0.0.1 localhost.localdomain localhost amk
192.168.10.10 amk.localdomain.com amk
/etc/dhcpd.conf
ddns-update-style none;
allow bootp;
authoritative;
subnet 192.168.10.0 netmask 255.255.255.0
{
range 192.168.10.20 192.168.10.30;
option subnet-mask 255.255.255.0;
option domain-name "localdomain.com";
option routers 192.168.10.10;
option domain-name-servers 192.168.10.10;
default-lease-time 3600;
max-lease-time 7200;
}
/etc/named.conf
options {
directory "/etc";
pid-file "/var/run/named/named.pid";
forwarders {
203.81.71.68;
203.81.71.73; };
};
zone "localdomain.com"
{
type master;
file "/var/named/localdomain.com.hosts";
};
zone "10.168.192.in-addr.arpa"
{
type master;
file "/var/named/192.168.10.rev";
};
/var/named/localdomain.com.hosts
$ttl 38400
localdomain.com. IN SOA amk.localdomain.com. amk.localdomain.com (
1246337929
10800
3600
604800
38400 )
localdomain.com. IN NS amk.localdomain.com.
amk.localdomain.com. IN A 192.168.10.10
/var/named/192.168.10.rev
$ttl 38400
10.168.192.in-addr.arpa. IN SOA amk.localdomain.com. amk.localdomain.com. (
1246338296
10800
3600
604800
38400 )
10.168.192.in-addr.arpa. IN NS amk.localdomain.com.
10.10.168.192.in-addr.arpa. IN PTR amk.localdomain.com.
/etc/squid/squid.conf
# WELCOME TO SQUID 3.0.STABLE2
# ----------------------------
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl to_localhost dst 127.0.0.0/8
acl localnet src 192.168.10.0/24
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
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localnet
http_access allow localhost
http_access deny all
icp_access allow localnet
icp_access deny all
htcp_access allow localnet
htcp_access deny all
http_port 192.168.10.10:8080 vhost vport=80 defaultsite=virtual protocol=http
hierarchy_stoplist cgi-bin ?
cache_mem 8 MB
minimum_object_size 0 KB
maximum_object_size 4096 KB
access_log /var/log/squid/access.log squid
cache_log /var/log/squid/cache.log
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern (cgi-bin|\?) 0 0% 0
refresh_pattern . 0 20% 4320
cache_mgr admin@gmail.com
visible_hostname amk.localdomain.com
icp_port 3130
always_direct allow all
cachemgr_passwd 123456
coredump_dir /var/spool/squid
IPTABLES
#Clear Default IPTABLES Rules
iptables -F
#Allow Local Network to Accept to Firewall ( Eth1= Local / Eth0=External )
iptables -A INPUT -j ACCEPT -p all -s 192.168.10.0/24 -i eth1
iptables -A OUTPUT -j ACCEPT -p all -s 192.168.10.0/24 -o eth0
#Redirect port 80 request to Proxy Port
iptables -t nat -A PREROUTING -i eth1 -p tcp ! -d 192.168.10.0/24 --dport 80 -j REDIRECT
--to-port 8080
#Enable NAT for Local Network
iptables -A POSTROUTING -t nat -o eth0 -s 192.168.10.0/24 -d 0/0 -j MASQUERAD

No comments:

Quote of the Day