Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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 using an Ubuntu 12.10 server as a router/NAT for an internal network to the internet. I have also configured the server to forward port 80 to a server sitting on my internal network. This all works fine.

What I would like to do now is setup additional port forwarders to addition web servers using port 80 on my network. I have several other static internet addresses I can use externally and just need to setup forwarding to the local servers.

I know I could just create additional Ubuntu servers, configuring each of them with different internet addresses (as well as local addresses on a 2nd NIC) and setting up port forwarding.

Is this possible to do with a single Ubuntu server?

I tried adding more virtual NICs to my single Ubuntu server but ran into routing problems since all these additional NICs were on the same internet subnet.

Is setting up individual ubuntu servers for each port forward I wish to do the only way to accomplish this?

share|improve this question

What you are asking to do is not possible (that I know of) with NAT. There is really no way for iptables to know where to send what traffic and you can port forward only one instance of post 80.

Imo am more elegant solution is to use nginx as a reverse proxy.


It works well as nginx is fast, light weight, and you can forward to your various servers based on url ;)

Nginx serves out the static content very fast and apache serves out the dynamic content (usually php) very fast (see the second link).

share|improve this answer

if you've got specific external ips for specific internal http servers you can use iptables for NATing to the right one, like this.

Lets supose you've got a inner http servers with ips, and and everytime the external ip calls port 80 you want it to go to the server so you use the DNAT rule like this

iptables -t nat -A PREROUTING -i eth0 -s -p tcp --dport 80 -j DNAT --to

and the rules keep the same for other. Now if you have no specifications like this, as bodhi.zazen said before, there is no way to do it with iptables only.

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.