21

I am trying to open port 3000 on Ubuntu 12.04, cause I have a web server listening there. I'm a bit out of my confort zone here, and spent many hours trying to solve the problem without success.

Port seems to be open in the firewall :

$> sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
...
3000/tcp                   ALLOW       Anywhere
3000/tcp                   ALLOW       Anywhere (v6)

The server is listening alright on that port :

$> netstat -an | grep "LISTEN "
...
tcp        0      0 127.0.0.1:3000          0.0.0.0:*               LISTEN     
...

And I can even wget alright the index page :

$> wget localhost:3000
Connecting to localhost (localhost)|127.0.0.1|:3000... connected.
HTTP request sent, awaiting response... 200 OK

And the received file contains what I expect ("hello world" :).

However, when trying from another computer, or if I wget mydomain.com:3000 I get "connection refused", and nmap tells me that the port is not open :

$> nmap -A -T4 mydomain.com
Host is up (0.00032s latency).
...
Not shown: 999 closed ports
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 5.9p1 Debian 5ubuntu1 (protocol 2.0)
...
Service Info: OS: Linux

Any idea what I should try next ???

EDIT

Here's what traceroute gives :

$> traceroute mydomain.com
traceroute to mydomain.com (176.31.x.x), 30 hops max, 60 byte packets
 1  mydomain.com (176.31.x.x)  0.034 ms  0.013 ms  0.010 ms
  • Disable ufw, try again. If that doesn't work, there is another firewall/device between the remote computer and your server. – ish Jul 20 '12 at 18:53
  • I tried already .. didn't solve it :( – sebpiq Jul 20 '12 at 19:07
  • "there is another firewall/device between the remote computer and your server." : this is very unlikely. I tried the second wget from the server so that it makes a round trip through the network. – sebpiq Jul 20 '12 at 19:15
  • huh? You can't type wget serverseb.com from serverseb and get it to make a round trip without some fancy iptables routing magic. Please pastebin the output of traceroute mydomain.com from the remote computer. You can ** out the last two octets of the last (server) IP for privacy. – ish Jul 20 '12 at 19:19
  • edited with a traceroute – sebpiq Jul 20 '12 at 20:22
24

If your server is listening on the localhost interface only, you won't be able to access it from a remote computer. This appears to be your primary problem, as only 127.0.0.1:3000 is listed in your netstat output.

You will also need to ensure that "mydomain.com" resolves to the correct IP address for your machine, such that connecting to it will result in communication with the external interface of that machine.

  • I can ssh to the machine using its name, so I guess the name resolution is not the problem here. How can I make so that server would listen from anywhere ? – sebpiq Jul 20 '12 at 20:13
  • 1
    @sebpiq This resolution is program-specific. You need to bind the program's listener to the right interface by name{eth0, or something like that), IP address(192.168.1.99, or something like that), or the MAC address. This depends on the program. – Reinstate Monica - ζ-- Jul 20 '12 at 20:24
  • uugh ... sounds insane :S I'll try to google about that. My server is node.js, so I'll check if there's info about what interface I need to connect to. – sebpiq Jul 20 '12 at 20:34
  • Yeepee !!! @ObsessiveFOSS and dobey thank you SO MUCH ! My node.js server was actually only listening on localhost. I didn't know it was doing like that, and none of the tutorial mentioned that. – sebpiq Jul 20 '12 at 20:40
  • @sebpiq No problem. :-) – Reinstate Monica - ζ-- Jul 20 '12 at 20:41
13

I had this problem recently with a nodejs HTTPS server, and the solution to it was not to use "localhost", "127.0.0.1" or even the domain name. It was to use "0.0.0.0"

I believe this acts as a wildcard, now allowing for public resolution via the domain name and it also works with "localhost"

Edit: Here's a link to a serverfault page on the 0.0.0.0 topic: https://serverfault.com/questions/78048/whats-the-difference-between-ip-address-0-0-0-0-and-127-0-0-1

  • Use "0.0.0.0" where exactly? – Adaephon Jan 28 '15 at 9:34
  • @Adaephon Well in my case, I created a Node-based web server. I had to change: }).listen(3000, '127.0.0.1'); to }).listen(3000, '0.0.0.0'); in my code. – Sami Fouad Jan 29 '15 at 15:43
  • @Adaephon So I'm not sure how much help that was, but wherever you're defining the IP/Hostname, try 0.0.0.0 instead. – Sami Fouad Jan 29 '15 at 15:53
  • can you please visit my post? stackoverflow.com/questions/37922804/… – Kar19 Jun 20 '16 at 15:11
  • 1
    0.0.0.0 (or rather the binary representation 0) is considered as listening to everyone from the point of view of the socket interface. You can give another IP and it will only listen to the interface where you have that IP. For example, if you give 127.0.0.1 you can only receive connections from the 127.*.*.* IPs (localhost really), or from other computers with seriously botched routing tables which would access yours for 127.0.0.1 (to test this last case!) – Paul Stelian Apr 28 '18 at 16:34
3

Is there any chance that you are using AWS or any other cloud services? In that case port should be opened on inctance (OS) configuration level or after. In particular in AWS you should be looking for "Security Groups" where you should open access to port 3000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.