iptables port forwarding works only for localhost

Posted by Venki on Server Fault See other posts from Server Fault or by Venki
Published on 2013-10-27T22:23:25Z Indexed on 2013/10/28 3:56 UTC
Read the original article Hit count: 475

Filed under:

Below is my iptables config. I used this for my accessing a node js website running in port 9000 through port 80. This works fine only if access the website through local host / loop back. When I try to use the ip of eth0, which is assigned by my router through dcp. this does not work, when I use ip like 192.168.0.103 to access the website. I am not able to figure what is wrong here, Already burnt a day in this, still not able to figure out :(

Edit: ( more information) Earlier, I was using this configuration to develop the website, i had configured the domain name to point to 127.0.0.1 in the /etc/hosts file. It was working fine, but now I am trying to deploy the website in a vps with static ip, This configuration does not work with both static IP.

# redirect port 80 to port 9000
*nat
:PREROUTING ACCEPT [57:3896]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [4229:289686]
:POSTROUTING ACCEPT [4239:290286]
-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 9000
-A OUTPUT -d 127.0.0.1/32 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 9000
COMMIT

#  Allow HTTP and HTTPS connections from anywhere (the normal ports for websites and SSL).
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT
-A INPUT -p tcp --dport 9000 -j ACCEPT

-A INPUT -j REJECT

© Server Fault or respective owner

Related posts about iptables