22

I'm sure this is very noobish, so forgive me. I'm trying to run a node.js server on port 8080 of my ubuntu 10.04.

Here's the result of iptables -L on the server:

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

And here's the result of nmap -p 8080 (edited the ip address because everything is or should be wide open)

nmap 173.203.xxx.xxx -p 8080 -A

Starting Nmap 5.00 ( http://nmap.org ) at 2011-05-19 22:52 PDT
Interesting ports on xxx (173.203.xxx.xxx):
PORT     STATE  SERVICE    VERSION
8080/tcp closed http-proxy

Why on earth is 8080 seen as closed? Adding this did not help:

iptables -A OUTPUT -p tcp  --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp  --dport 8080 -j ACCEPT

I'm really confused.

I'll add this, in case it helps, but I don't know

 netstat -pan | grep 80
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN          16785/node      
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      16471/apache2

I can access my regular website running off of port 80 on apache, but the node.js server is inaccessible from outside. Accessing it from the server itself works fine.

So my question is: how would I go about debugging this? Could there be something else than iptables blocking some ports? How do I find out what it is?

Any help much appreciated!

Mikael Gramont
  • 323
  • 1
  • 2
  • 4
  • To those who came here via Google: If you've hosted service on Google cloud and facing this issue, first **make sure you've added the port in the exception rules of [cloud firewall](https://console.cloud.google.com/networking/firewalls) as well as in the operating systems firewall** – Atul Aug 10 '16 at 11:02

3 Answers3

36

Thanks for adding the last netstat output, it really helped. You can't access node.js from outside because it is listening on localhost IP i.e 127.0.0.1. You need to configure node.js to listen on 0.0.0.0 so it will be able to accept connections on all the IPs of your machine.

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
}).listen(8080, "0.0.0.0");
console.log('Server running at http://0.0.0.0:8080/');
5

According to your netstat output, port 8080 is open only for 127.0.0.1 which is localhost, hence accessing from the server works (which is localhost), but not from anywhere else.

The right output should look like

0.0.0.0:8080
freethinker
  • 336
  • 1
  • 8
0

I had the same Issue.

I did the following

  1. In Google Cloud Console you need enable ports which you are using for Nodejs
  2. use following link to enable same ports on Ubuntu Server https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-14-04

  3. And after this last one what I was missing is Networking -> Firewall Rules -> default-allow-internal ->all IP address 0.0.0.0/0

see this image

Done

chicks
  • 3,639
  • 10
  • 26
  • 36
Tejas
  • 101
  • 1