#!/bin/bash
chainplustables="INPUT,filter,0 OUTPUT,filter,1 FORWARD,filter,2 PREROUTING,nat,0 OUTPUT,nat,1 POSTROUTING,nat,1 PREROUTING,mangle,0 INPUT,mangle,0 FORWARD,mangle,2 OUTPUT,mangle,1 POSTROUTING,mangle,1"
ipdopatraum=192.168.50.30
# I == inject; D == Remove
job=I
for cpt in ${chainplustables}; do
corrente="$(echo ${cpt} | cut -f1 -d",")"
tabela="$(echo ${cpt} | cut -f2 -d",")"
# 0 == in ; 1 == out ; 2 == in/out
caminhos="$(echo ${cpt} | cut -f3 -d",")"
case ${caminhos} in
'0') sdip="-s" ;;
'1') sdip="-d" ;;
*) sdip="-s -d"
esac
if [ "${tabela}" == "nat" -a "${corrente}" == "POSTROUTING" ]; then
RULE="MASQUERADE"
else
RULE="ACCEPT"
fi
for sourceordest in ${sdip}; do
iptables -${job} ${corrente} -t ${tabela} ${sourceordest} ${ipdopatraum} -j ${RULE}
done
done