Fixing clear unnessesary iptables rules from table NAT.

This commit is contained in:
2021-12-12 20:58:08 +00:00
parent ff3ae4b6a8
commit 404cc9362e

View File

@@ -54,12 +54,12 @@ if [[ "$NSENTER" == "true" ]] ; then
iptables="nsenter -t $(docker inspect --format {{.State.Pid}} $NAME) -n -- $IPTABLES -t nat";
if [[ "$PREROUTING" == "true" ]] ; then
LINES=$($iptables --line-number -n | grep $COMMENT | awk '{print $1}'| tac)
LINES=$($iptables --line-number -n | grep $COMMENT | grep PREROUTING |awk '{print $1}'| tac)
# DELETE UNECESSARY LINES FROM PREVIOUS RULES
if [ -n "$LINES" ] ; then
for i in $LINES; do
$iptables -D PREROUTING $i
$iptables -D $i
sleep 0.1
done
fi
@@ -67,12 +67,12 @@ if [[ "$NSENTER" == "true" ]] ; then
$iptables -I PREROUTING -d $SOURCE_IP -p $PROTOCOL --dport $SOURCE_PORT -m comment --comment "$COMMENT" -j DNAT --to $TARGET_IP:$TARGET_PORT
elif [[ "$POSTROUTING" == "true" ]] ; then
LINES=$($iptables --line-number -n | grep $COMMENT | awk '{print $1}'| tac)
LINES=$($iptables --line-number -n | grep $COMMENT | grep POSTROUTING | awk '{print $1}'| tac)
# DELETE UNECESSARY LINES FROM PREVIOUS RULES
if [ -n "$LINES" ] ; then
for i in $LINES; do
$iptables -D POSTROUTING $i
$iptables -D $i
sleep 0.1
done
fi