#!/bin/bash
# used some from
advanced script to have multiple ports: use an equal
number of guest and host ports
Guest_name=xxxxxxx
Guest_ipaddr=xxx.xxx.xxx.xx
Host_ipaddr=xxx.xxx.xxx.xx
Host_port=( '80' '443'
)
Guest_port=( '80' '443'
)
length=$((
${#Host_port[@]} - 1 ))
if [ "${1}" =
"${Guest_name}" ]; then
if [ "${2}" =
"stopped" -o "${2}" = "reconnect" ]; then
for i in `seq 0
$length`; do
iptables
-t nat -D PREROUTING -d
${Host_ipaddr} -p tcp --dport
${Host_port[$i]} -j DNAT --to
${Guest_ipaddr}:${Guest_port[$i]}
iptables
-D FORWARD -d ${Guest_ipaddr}/32 -p tcp -m state --state
NEW -m tcp --dport ${Guest_port[$i]} -j ACCEPT
done
fi
if [ "${2}" =
"start" -o "${2}" = "reconnect" ]; then
for i in `seq 0
$length`; do
iptables
-t nat -A PREROUTING -d
${Host_ipaddr} -p tcp --dport
${Host_port[$i]} -j DNAT --to
${Guest_ipaddr}:${Guest_port[$i]}
iptables
-I FORWARD 4 -d ${Guest_ipaddr}/32 -p tcp -m state --state
NEW -m tcp --dport ${Guest_port[$i]} -j ACCEPT
done
fi
fi
Lastly, I should note that I am using Ubuntu 14.04, both
for the host and guest.
I'm also curious as to why this is considered a hack
method. It states in the wiki that "This method is a hack",
but it doesn't express why.