#!/bin/bash
# used some from advanced script to have multiple ports: use an equal number of guest and host ports
# Update the following variables to fit your setup
Guest_ipaddr="192.168.122.101"
Host_ipaddr="192.168.15.10"
Host_port=(  '101' '4242' )
Guest_port=( '22' '4242' )
length=$(( ${#Host_port[@]} - 1 ))

for i in `seq 0 $length`; do
	echo iptables -t nat -A PREROUTING -d ${Host_ipaddr} -p tcp --dport ${Host_port[$i]} -j DNAT --to ${Guest_ipaddr}:${Guest_port[$i]}
	iptables -t nat -A PREROUTING -d ${Host_ipaddr} -p tcp --dport ${Host_port[$i]} -j DNAT --to ${Guest_ipaddr}:${Guest_port[$i]}
	echo iptables -I FORWARD -d ${Guest_ipaddr}/32 -p tcp -m state --state NEW -m tcp --dport ${Guest_port[$i]} -j ACCEPT
	iptables -I FORWARD -d ${Guest_ipaddr}/32 -p tcp -m state --state NEW -m tcp --dport ${Guest_port[$i]} -j ACCEPT
done
