Preparing firewall to create /24 subnet NAT settings.

This commit is contained in:
2022-02-27 20:12:37 +00:00
parent 6411e97a7f
commit 869994823a

View File

@@ -31,11 +31,22 @@ EXTRA_OPTIONS="$2 $3 $4"
if [[ -z "$TYPE" ]]; then if [[ -z "$TYPE" ]]; then
TYPE="tcp" TYPE="tcp"
fi; fi;
if [[ -z "$SOURCE_IP" ]]; then if [[ -z "$SOURCE_IP" ]]; then
SOURCE_IP="0.0.0.0/0" SOURCE_IP="0.0.0.0/0";
elif [[ "$(echo $SOURCE_IP | cut -d . -f4)" == "0" ]] ; then
SOURCE_IP="$SOURCE_IP/24";
debug "source ip is $SOURCE_IP"
fi; fi;
if [[ -z "$TARGET_IP" ]]; then if [[ -z "$TARGET_IP" ]]; then
TARGET_IP="0.0.0.0/0" TARGET_IP="0.0.0.0/0";
elif [[ "$(echo $TARGET_IP | cut -d . -f4)" == "0" ]] ; then
TARGET_IP="$TARGET_IP/24";
debug "target ip is $TARGET_IP"
fi; fi;
############################## ##############################
@@ -49,7 +60,7 @@ IPTABLES=/sbin/iptables-legacy
############################### ###############################
prerouting() { prerouting() {
LINES=$($IPTABLES --line-number -n | grep $COMMENT | grep DNAT |awk '{print $1}'| tac) LINES=$($IPTABLES -L --line-number -n | grep $COMMENT | grep DNAT |awk '{print $1}'| tac)
debug "Previous prerouting lines: "$LINES debug "Previous prerouting lines: "$LINES
# DELETE UNECESSARY LINES FROM PREVIOUS RULES # DELETE UNECESSARY LINES FROM PREVIOUS RULES
if [ -n "$LINES" ] ; then if [ -n "$LINES" ] ; then
@@ -65,7 +76,7 @@ prerouting() {
} }
postrouting() { postrouting() {
LINES=$($IPTABLES --line-number -n | grep $COMMENT | grep MASQUERADE | awk '{print $1}'| tac) LINES=$($IPTABLES -L --line-number -n | grep $COMMENT | grep MASQUERADE | awk '{print $1}'| tac)
debug "Previous postrouting lines: "$LINES debug "Previous postrouting lines: "$LINES
# DELETE UNECESSARY LINES FROM PREVIOUS RULES # DELETE UNECESSARY LINES FROM PREVIOUS RULES