Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 have a server with multiple IP addresses associated with it. I'm trying to run a node.js web server (which I do not want to run as root), using only one of those ip addresses (it would be very bad if the traffic from all the ip addresses were forwarded).

Through searching superuser, it looked like this could be possible with iptables:

How to setting up iptables for traffic fowarding on port 80 from specific sources

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 --source 212.333.111.222 -j REDIRECT --to-port 9020

However, I do not understand why eth0 is needed.

According to:

this could be done with:

iptables -t nat -A PREROUTING -p tcp --dport 2525 -j REDIRECT --to-ports 25

What is the correct way of forwarding traffic from a single ip on port 80, lets say to another port on the same server, lets say

thanks for your help!

share|improve this question
up vote 2 down vote accepted

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8765

Instead of using IP address use interface name, I mean instead of eth0 you can use the interface you want.

This rule says iptables:

  1. Do it on PreRouting
  2. Do nat
  3. On interface eth0
  4. Protocol is TCP
  5. Destination port to match is 80
  6. Redirect it to port 8765
share|improve this answer
After doing this, I am still not able to access my web server on port 80 - accessing it from port 8765 still works, so I know my node.js server is still up and listening, but the requests and responses don't seem to be forwarded from 8765 to port 80.Is there anything I'm missing? – zam Jul 1 '12 at 20:24
Can you send me tcpdump output? – Hamed JML Jul 2 '12 at 7:13
Unfortunately there are way too many other sites running, making the tcpdump hard to decipher - I didn't see anything specific to this ip, though. I tried checking iptables with -L - but couldn't find my rule we just added. Could something stop new rules? – zam Jul 2 '12 at 23:46
To see if your rule added you should use this command: iptables -L -t nat – Hamed JML Jul 3 '12 at 4:58
Thanks for your help, Hamed - I've ended up going a different route using nginx, however I will make note of this for the future. – zam Jul 3 '12 at 23:42

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.