#!/bin/bash # transparent_proxying This shell script takes care of starting and stopping # transparent proxying # # chkconfig: - 91 24 # description: transparent proxying: this will force all web traffic to be \ # redirected to the squid proxy server. It will only work if squid \ # is running # pidfile: /var/run/squid.pid # Source function library. . /etc/init.d/functions start() { echo -n "Starting transparent proxying: " if [ -f /var/run/squid.pid ] then # Turn on IP forwarding echo 1 > /proc/sys/net/ipv4/ip_forward # Turn on transparent proxy redirect /sbin/iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3128 echo_success else echo -n "Squid is not running! " echo_failure fi echo return 0 } stop() { echo -n "Stopping transparent proxying: " echo 0 > /proc/sys/net/ipv4/ip_forward # Turn off transparent proxy redirect /sbin/iptables -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 3128 echo_success echo return 0 } status() { if [ "`/sbin/iptables -L -n -t nat | grep '80 redir ports 3128'`" ] then echo "Transparent proxying is active" return 0 else echo "Transparent proxying is inactive" return 0 fi } restart() { stop start } case "$1" in start) start ;; status) status ;; stop) stop ;; restart|reload) restart ;; *) echo "*** Usage: {start|stop|restart}" exit 1 esac exit $?