Simple port forwarding

In case someone else is looking for a way that actually works. Though @HorsePunchKid is right in his suggestion, I've found this walkthrough that fills in the missing steps:

http://www.debuntu.org/how-to-redirecting-network-traffic-to-a-new-ip-using-iptables/

In essence:

Enable IP Forwarding:

sysctl net.ipv4.ip_forward=1

Add your forwarding rule (use n.n.n.n:port):

iptables -t nat -A PREROUTING -p tcp -d 10.0.0.132 --dport 29418 -j DNAT --to-destination 10.0.0.133:29418

Ask IPtables to Masquerade:

iptables -t nat -A POSTROUTING -j MASQUERADE

And that's it! It worked for me in any case :)


If anyone searching for a temporary method, try the below solution.

    ssh -L 192.168.0.10:8080:10.0.0.10:80 [email protected]

The above command redirects all connections to the port 8080 on your base machine to 80 port of your virtual machine. You can test the working by accessing the web page http://192.168.0.10:8080, and it'll show you the web page on guest machine.

This applies to all ports :)


If you have iptables installed on 10.0.0.132, I think this will be pretty straightforward:

iptables -t nat -A PREROUTING -j DNAT -d 10.0.0.132 -p tcp --dport 29418 --to 10.0.0.133

This says to send traffic coming in to 10.0.0.132 on port 29418 over to 10.0.0.133 instead, on the same port, prior to any other routing that 10.0.0.132 might try to do. If you run this command and have trouble with it, replace the -A flag with -D to remove it.

If you're looking to have this rule run automatically when 10.0.0.132 starts up, consider adding the above command as a "post-up" rule in /etc/network/interfaces.