Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am in a bit of trouble as I am trying to setup a reverse proxy with and a second server. My idea was to get the firewall to forward https to the reverse proxy and port 29418 (gerrit ssh) to the second server. Now my cooperate IT guy says: CAN NOT! Either both ports go to server 1 or both ports go to server 2.

Ok, as a work around I tried to setup a port forwarding on the reverse proxy of port 29418 -> server2:29418


  • Server1 IP: and on Ubuntu 12.04.2 LTS
  • Server2 IP: and on Ubuntu 12.04.2 LTS

Now both https and port 29418 go from the firewall to, IT says that's the only way. :(

So please tell me how to forward from -> or

When I am working on the I can connect to both and so the ports are open.

-- Update --

My iptables -t nat -L looks like this:

root@dev:/root# iptables -t nat -L
target     prot opt source               destination
DNAT       tcp  --  anywhere          tcp dpt:29418 to:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

target     prot opt source               destination
root@dev:/root# cat /proc/sys/net/ipv4/ip_forward
share|improve this question
up vote 8 down vote accepted

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:

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 --dport 29418 -j DNAT --to-destination

Ask IPtables to Masquerade:

iptables -t nat -A POSTROUTING -j MASQUERADE

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

share|improve this answer
This is the best answer I found on this subject. – Victor Piousbox Sep 19 '14 at 8:34

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

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

This says to send traffic coming in to on port 29418 over to instead, on the same port, prior to any other routing that 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 starts up, consider adding the above command as a "post-up" rule in /etc/network/interfaces.

share|improve this answer
That's exactly what I did but it didn't work. I have uncommented the net.ipv4.ip_forward = 1 in /etc/sysctl.conf but I still get errors connecting to the – uncletall Jul 15 '13 at 2:39

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

    ssh -L root@

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, and it'll show you the web page on guest machine.

This applies to all ports :)

share|improve this answer

In the end I had to install pfSense as a router inside my ESXi server to route the traffic to the different VM's as I could not get it to work in Ubuntu.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.