On my Ubuntu 14.04 I have a service running on a local IP (192.168.33.99) and port 80. In my network, my Ubuntu computer has IP 192.168.2.3. Now I want to redirect all traffic on 192.168.2.3:8080 to 192.168.33.99:80 (note that this is a local IP on the Ubuntu machine). How can I do that?
What you're looking for is called NAT.
First we want to enable portforwarding:
Now we should add a rule that forwards all incoming traffic on 8080:
iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to-destination 192.168.33.99:80
Then all that is left, is iptables to masquerade
iptables -t nat -A POSTROUTING -j MASQUERADE