#!/bin/sh

# chkconfig: 2345 13 89
# description: NAT
. /etc/init.d/functions

case "$1" in
	start)
		$0 stop
		echo -n "Starting NAT: "
			iptables -I PREROUTING -t nat -s 192.168.2.0/24 -p tcp --dport 80 -j DNAT --to 192.168.1.14:3128 \
			&& iptables -I PREROUTING -t nat -s 192.168.1.0/24 -p tcp --dport 80 -j DNAT --to 192.168.1.14:3128 \
			&& echo 1 > /proc/sys/net/ipv4/ip_forward \
			&& iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o eth0 -j MASQUERADE \
			&& success
		echo
		;;
	stop)
		echo -n "Stopping NAT: "
			echo 0 > /proc/sys/net/ipv4/ip_forward \
                        && iptables -t filter -F \
                        && iptables -t filter -X \
                        && iptables -t nat -F \
                        && iptables -t nat -X \
                        && success
		echo
		;;
	status)
		echo -n "Status NAT: "
                        echo && iptables -L -t nat
		echo
		;;
	restart)
		$0 stop
		$0 start
		;;
	*)
		echo "Usage: nat {start|stop|status|restart}"
		exit 1
		;;
esac

exit $RETVAL