Updating port forwarding code

master
bbruns 2010-12-18 19:19:26 +00:00
parent 2a055c638e
commit 4b7a383be0
1 changed files with 23 additions and 7 deletions

View File

@ -486,13 +486,29 @@ fi
if [ "$PORTFW" ] && [ "$NAT" ]; then if [ "$PORTFW" ] && [ "$NAT" ]; then
display_c YELLOW "Adding port forward for:" display_c YELLOW "Adding port forward for:"
for i in `grep -v "\#" $PORTFW`; do for i in `grep -v "\#" $PORTFW`; do
PORTADD=( ${i//:/ } ) IFS_OLD=${IFS};IFS=\:
$IPTABLES -A PREROUTING -t nat -i ${PORTADD[0]} -p ${PORTADD[4]} -s ${PORTADD[1]} \ PORTFWADD=($i)
--dport ${PORTADD[3]} -d ${PORTADD[2]} -j DNAT --to \ IFS=${IFS_OLD}
${PORTADD[5]}:${PORTADD[6]} DSTIF=${PORTFWADD[0]}
$IPTABLES -A INPUT -p ${PORTADD[4]} ${M_STATE} ${C_STATE} NEW -s ${PORTADD[1]} \ SRCIP=${PORTFWADD[1]}
--dport ${PORTADD[3]} -d ${PORTADD[2]} -i ${PORTADD[0]} -j ACCEPT DSTIP=${PORTFWADD[2]}
display_c DEFAULT "\t${GREEN}${PORTADD[0]}:${BLUE}${PORTADD[1]}:${PURPLE}${PORTADD[2]}:${PORTADD[3]}:${PORTADD[4]}${AQUA}->${BLUE}${PORTADD[5]}:${PORTADD[6]} " DSTPORT=${PORTFWADD[3]}
DSTPROTO=${PORTFWADD[4]}
DSTINTIP=${PORTFWADD[5]}
DSTINTPORT=${PORTFWADD[6]}
if [ "$DSTIF" ]; then
DSTIF="-i ${DSTIF}"
fi
if [ "$SRCIP" ]; then
SRCIP="-s ${SRCIP}"
fi
//PORTADD=( ${i//:/ } )
$IPTABLES -A PREROUTING -t nat ${DSTIF} -p ${DSTPROTO} ${SRCIP} \
--dport ${DSTPORT} -d ${DSTIP} -j DNAT --to \
${DSTINTIP}:${DSTINTPORT}
$IPTABLES -A INPUT -p ${DSTPROTO} ${M_STATE} ${C_STATE} NEW ${DSTIF} ${SRCIP} \
--dport ${DSTPORT} -d ${DSTIP} -j ACCEPT
display_c DEFAULT "\t${GREEN}${PORTFWADD[0]}:${BLUE}${PORTFWADD[1]}:${PURPLE}${PORTFWADD[2]}:${PORTFWADD[3]}:${PORTFWADD[4]}${AQUA}->${BLUE}${PORTFWADD[5]}:${PORTFWADD[6]} "
done done
reset_color reset_color
fi fi