case "$1" in
start)
$0 enablerouting
$0 enablenat
$0 enablefirewall
;;
stop)
$0 disablefirewall
$0 disablenat
$0 disablerouting
/usr/local/sbin/iptables -F
/usr/local/sbin/iptables -t nat -F
/usr/local/sbin/iptables -t mangle -F
/usr/local/sbin/iptables -X
/usr/local/sbin/iptables -t nat -X
/usr/local/sbin/iptables -t mangle -X
;;
enablerouting)
echo "Enabling Routing"
echo "1" > /proc/sys/net/ipv4/ip_forward
;;
disablerouting)
echo "Disabling Routing"
echo "0" > /proc/sys/net/ipv4/ip_forward
;;
enablefirewall)
echo "Enabling Firewall"
/usr/local/sbin/iptables -N firewall
/usr/local/sbin/iptables -A firewall -m state --state INVALID -j DROP
/usr/local/sbin/iptables -A firewall -m state --state ESTABLISHED,RELATED -j ACCEPT
/usr/local/sbin/iptables -A firewall -m state --state NEW -i ! ppp0 -j ACCEPT
/usr/local/sbin/iptables -A firewall -j DROP
/usr/local/sbin/iptables -A INPUT -j firewall
/usr/local/sbin/iptables -A FORWARD -j firewall
;;
disablefirewall)
echo "Disabling Firewall"
/usr/local/sbin/iptables -D INPUT -j firewall
/usr/local/sbin/iptables -D FORWARD -j firewall
/usr/local/sbin/iptables -F firewall
/usr/local/sbin/iptables -X firewall
;;
enablenat)
echo "Enabling NAT"
/usr/local/sbin/iptables -A POSTROUTING -t nat -o ppp0 -j MASQUERADE
;;
disablenat)
echo "Disabling NAT"
/usr/local/sbin/iptables -D POSTROUTING -t nat -o ppp0 -j MASQUERADE
;;
restart)
$0 stop && $0 start || return=$rc_failed
;;
*)
echo "Usage: $0
{start|stop||restart|enablerouting|disablerouting|enablefirewall|disablefirewall|enablenat|disablenat}"
exit 1
;;
esac