# Parse the IP address for my public IP and put it into a variable. # Since we use the external IP, the script needs to run when you get a new IP. ADDR=`ifconfig eth0|grep 'inet addr'| awk '{print $2}'| awk -F ":" '{print $2}'`
# Incoming requests to port 5902 on the external IP redirect to port 5900 on 192.168.1.44 iptables -A PREROUTING -t nat -p tcp -d $ADDR --dport 5902 -j DNAT --to 192.168.1.44:5900 iptables -A OUTPUT -t nat -p tcp -d $ADDR --dport 5902 -j DNAT --to 192.168.1.44:5900
Translation
# Since we use the external IP, the script needs to run when you get a new IP.
ADDR=`ifconfig eth0|grep 'inet addr'| awk '{print $2}'| awk -F ":" '{print $2}'`
# Incoming requests to port 5902 on the external IP redirect to port 5900 on 192.168.1.44
iptables -A PREROUTING -t nat -p tcp -d $ADDR --dport 5902 -j DNAT --to 192.168.1.44:5900
iptables -A OUTPUT -t nat -p tcp -d $ADDR --dport 5902 -j DNAT --to 192.168.1.44:5900