diff options
author | Vasudeva Kamath <vasudeva.kamath@in.abb.com> | 2016-07-14 17:52:31 +0530 |
---|---|---|
committer | Vasudeva Kamath <vasudeva.kamath@in.abb.com> | 2016-07-14 17:52:31 +0530 |
commit | b8f42ab1f6dc17bbb352bcc3a12020d47429df00 (patch) | |
tree | 392d8100c94eb39c3b9835695fd0ddf62a003b1d | |
parent | 857819c13c7608ca9556deaaf55636c52219a493 (diff) |
Handle source nating when interface has more IP
Some time interface can have 2 ip address handle this case, though I
feel only first IP will be considered by iptables.
-rwxr-xr-x | port_forward | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/port_forward b/port_forward index 4a3c9d1..4842b3c 100755 --- a/port_forward +++ b/port_forward @@ -35,8 +35,10 @@ setup_portforwarding () { iptables -A FORWARD -p "$protocol" -d ${DESTINATION%%\:*} --dport $PORT -j ACCEPT # Returning packet should have gateway IP - iptables -t nat -A POSTROUTING -s ${DESTINATION%%\:*} -o \ - $IN_INTERFACE -j SNAT --to ${IN_IP%%\/*} + for ip in ${IN_IP} ; do + iptables -t nat -A POSTROUTING -s ${DESTINATION%%\:*} -o \ + $IN_INTERFACE -j SNAT --to ${ip%%\/*} + done } @@ -82,7 +84,7 @@ DESTINATION="$4" # Get the incoming interface IP. This is used for SNAT. IN_IP=$(ip addr show $IN_INTERFACE|\ - perl -nE '/inet\s(.*)\sbrd/ and print $1') + perl -nE '/inet\s(.*)\sscope/ and say $1' | tr '\n' ' ') if [ -n "$CLEAR_RULES" ]; then |