Skip to content

Commit

Permalink
Update gateway_UDP.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz authored Jan 15, 2024
1 parent 41c54bb commit 47c779a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions scripts/gateway/gateway_UDP.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

# get local ip from meta data server
LOCALIP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4)
LOCALNET=$( echo ${LOCALIP} | cut -f 1-3 -d".")
LOCALNET=$( echo ${LOCALIP} | cut -f 1-2 -d".")

#ip forwarding rules
for ((base=0; base <=8; base++))
{
for ((n=1; n <=254; n++))
{
MOSH_BASE=$((30000+$n*10))
MOSH_BASE=$((30000+$n + base *256))


MOSH_PORT=$(($MOSH_BASE))
echo ${MOSH_PORT}
iptables -t nat -A PREROUTING -i ens3 -p udp -m udp --dport ${MOSH_PORT} -j DNAT --to-destination ${LOCALNET}.${base}.${n}:${MOSH_PORT}
iptables -t nat -A POSTROUTING -d ${LOCALNET}.${base}.${n}/32 -p udp -m udp --dport ${MOSH_PORT} -j SNAT --to-source ${LOCALIP}

for ((m=0; m<=9; m++))
{
MOSH_PORT=$(($MOSH_BASE+$m))
#$echo ${MOSH_PORT}
iptables -t nat -A PREROUTING -i ens3 -p udp -m udp --dport ${MOSH_PORT} -j DNAT --to-destination ${LOCALNET}.${n}:${MOSH_PORT}
iptables -t nat -A POSTROUTING -d ${LOCALNET}.${n}/32 -p udp -m udp --dport ${MOSH_PORT} -j SNAT --to-source ${LOCALIP}
}

}
}

0 comments on commit 47c779a

Please sign in to comment.