Squid – transparent proxy
Squid Installation and Configuration
yum install squid -y
Edit squid configuration file
Before you edit default configuration file it is highly recommended to keep backup.
cp /etc/squid/squid.conf /etc/squid/squid.conf.bk-07-05-2016
Open configuration file and add below mentioned parameters
vi /etc/squid/squid.conf
Add transparent proxy setting and add and allow our_network
vi /etc/squid/squid.conf
Allow LAN Network acl our_network src 192.168.2.0/24 # Allow Network ACL Allow/Deny Section# http_access allow our_network # Transparent Proxy Parameters http_port 3128 intercept visible_hostname pxy.broexperts.com
Save & Exit
Now start squid service and make sure it is added on startup.
systemctl start squid systemctl enable squid
If you wish to use iptables instead of firewalld deamon use below link to enable iptables in CentOS7 and then Add below showing iptables rules to setup squid as transparent proxy.
Note:-Refer this guide to enable iptables in CentOS 7 How to Enable Iptables Firewall in CentOS 7 / RHEL 7
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.2.100:3128 iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 3128 iptables --t nat -A POSTROUTING --out-interface eth1 -j MASQUERADE
now you can save your iptable rules by following command:
service iptables save
That’s It, Now squid should work smoothly in transparent proxy mode.