Server Fault is a question and answer site for system and network administrators. 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'm basically wondering what is best practice when running multiple web-services that all need to be on port 80 without using something like nginx as a proxy. The following solution is actually working but I'm wondering if I'm actually doing this correctly.

Currently I am doing something like this in my iptables:

-A RH-Firewall-1-INPUT -m state --state NEW -d -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -d -m tcp -p tcp --dport 8081 -j ACCEPT

-A RH-Firewall-1-INPUT -m state --state NEW -d -m tcp -p tcp --dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -d -m tcp -p tcp --dport 8082 -j ACCEPT

-A PREROUTING -d -p tcp --dport 80 -j DNAT --to
-A PREROUTING -d -p tcp --dport 80 -j DNAT --to

I would point my DNS to for and would resolve to but both operate on 80 externally.

I greatly appreciate any input/suggestions, I'm currently running CentOS 5.5.

share|improve this question
up vote 3 down vote accepted

Why wouldn't you just make both webservers (or whatever they are) bind to port 80 on the different IP addresses? (Ab)using iptables in this manner just confuses people (I know, I've worked in an environment that did this; it was painful, annoying, unproductive, and unnecessary).

share|improve this answer
I feel pretty stupid, thank you for the obvious solution. I knew something was weird which is why i posted the question, hopefully someone else benefits from it. My default webserver was eating up all the requests on any IP using 80, but after fixing that it allowed me to do exactly what you suggested ;) – Chad Scira Jul 4 '11 at 6:01

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.