#!/bin/sh # version 1.0.1 # see , route, flush # Source function library. IPTABLES="/sbin/iptables" if [ ! -f ${IPTABLES} ]; then echo " Install iptables first !" exit 1 fi . /etc/rc.d/init.d/functions INTERNAL_INTERFACE=eth1 EXTERNAL_INTERFACE=eth0 IPINTERNAL=`/sbin/ifconfig ${INTERNAL_INTERFACE} | grep "inet ad" | sed -e "s/\\ Bcast.*$//; s/.*://" | sed -e "s/ //"` IPEXTERNAL=`/sbin/ifconfig ${EXTERNAL_INTERFACE} | grep "inet ad" | sed -e "s/\\ Bcast.*$//; s/.*://" | sed -e "s/ //"` IPBASE_INTERNAL="`echo ${IPINTERNAL} | awk -F. '{print $1"."$2"."$3}'`" IPBASE_EXTERNAL="`echo ${IPEXTERNAL} | awk -F. '{print $1"."$2"."$3}'`" case $1 in see) gprintf " - Filter rules" ${IPTABLES} -L -t filter -v -n echo gprintf " - NAT rules" ${IPTABLES} -L -t nat -v -n #gprintf "Mangle regles" #iptables -L -t mangle -v -n # echo gprintf " -end-" ;; share) $0 flush action "Postrouting ${IPBASE_INTERNAL} " ${IPTABLES} -t nat -A POSTROUTING -o ${INTERNAL_INTERFACE} -j MASQUERADE action "Postrouting ${IPBASE_EXTERNAL}" ${IPTABLES} -t nat -A POSTROUTING -o ${EXTERNAL_INTERFACE} -j MASQUERADE ;; flush) action "flushing Rules INPUT" ${IPTABLES} -F INPUT action "flushing Rules OUTPUT" ${IPTABLES} -F OUTPUT action "flushing Rules FORWARD" ${IPTABLES} -F FORWARD action "flushing Rules POSTROUTING" ${IPTABLES} -t nat --flush POSTROUTING action "flushing Rules PREROUTING" ${IPTABLES} -t nat --flush PREROUTING ;; *) gprintf "usage rapidfirewall : {see|share|flush}\n" ;; esac