Nodejs server not visible on lan - node.js

I have installed a fresh CentOS 7 on my server and now I would like to run a nodejs server, but there is some problem I can't figure out. What I have is a simple nodejs server:
hello.js
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/');
I have tried with .listen(8080); also .listen(80); no success with those as well.
The strange thing is that, I can access the server locally with curl localhost:8080 it works as expected. But when I try from another machine on the same network it doesn't work.
E.g.
The server ip is 192.168.2.136 when I try in my browser 192.168.2.136:8080 I get 192.168.2.136 refused to connect.
Just to clarify that I have setup my modem with DMZ to my server ip.
Here is also netstat -ntl output
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
If someone can help with this would be great! thanks in advance!

Related

NodeJS + Fedora 32 refused to connect

Simplest server (same result with '0.0.0.0' and removing this property)
const http = require('http');
function handleRequest(a,b) {
console.log('!');
}
var server = http.createServer(handleRequest);
server.listen(4000, '0.0.0.0', function(){
console.log("Server is listening");
});
Netstat:
sudo netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 669/sshd: /usr/sbin
tcp 0 0 0.0.0.0:4000 0.0.0.0:* LISTEN 5631/node
tcp6 0 0 :::22 :::* LISTEN 669/sshd: /usr/sbin
Result by accessing http://(server's IP):4000
This site can’t be reached
(server's IP) refused to connect.
Ok, so I had to open port in firewall like this:
firewall-cmd --zone=public --add-port=4000/tcp

Why can't I talk to a service on tcp/3000 on my CentOS VPS

I'm trying to run a second web service on my VPS at port 3000.
On the VPS I run:
# php -S myhost.com:3000
and then in a browser, navigate to http://myhost.com:3000 but the browser times out and the service logs/outputs nothing.
If I run the service on port 80 (i.e., php -S myhost.com:80 and navigate to http://myhost.com), it works.
So firewall. Except that:
[root#spinal ~]# firewall-cmd --list-ports
3887/tcp 3000/tcp
(the 3887 is another service, which is working correctly.) And I rebooted the VPS after setting up port 3000 in the firewall. I reckon the service is listening correctly because:
[root#spinal ~]# netstat -tupl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:imap 0.0.0.0:* LISTEN 1907/dovecot
tcp 0 0 0.0.0.0:ciphire-data 0.0.0.0:* LISTEN 1876/sshd
tcp 0 0 0.0.0.0:http 0.0.0.0:* LISTEN 1903/nginx: master
tcp 0 0 0.0.0.0:urd 0.0.0.0:* LISTEN 2004/master
tcp 0 0 myhost.com:hbci 0.0.0.0:* LISTEN 2206/php
tcp 0 0 localhost.loca:postgres 0.0.0.0:* LISTEN 1908/postgres
tcp 0 0 0.0.0.0:smtp 0.0.0.0:* LISTEN 2004/master
tcp 0 0 0.0.0.0:https 0.0.0.0:* LISTEN 1903/nginx: master
tcp 0 0 0.0.0.0:imaps 0.0.0.0:* LISTEN 1907/dovecot
tcp 0 0 localhost.lo:cslistener 0.0.0.0:* LISTEN 1878/php-fpm: maste
tcp6 0 0 [::]:imap [::]:* LISTEN 1907/dovecot
tcp6 0 0 [::]:ciphire-data [::]:* LISTEN 1876/sshd
tcp6 0 0 [::]:urd [::]:* LISTEN 2004/master
tcp6 0 0 [::]:smtp [::]:* LISTEN 2004/master
tcp6 0 0 [::]:imaps [::]:* LISTEN 1907/dovecot
I can however connect locally. This works, when run on the VPS:
$ curl http://myhost.com:3000
so that again points at the firewall. But disabling the firewall doesn't help:
# systemctl stop firewalld
so it could be a DNS problem: my browser and the VPS differ on what myhost.com resolves-to. Except that, as mentioned above, switching to port 80 solves the problem. So it's something to do with coming-in on port 3000, from outside. But not firewalld.
The question at Can't reach nodejs on port 3000 from external on CentOS 7 is close to mine, but isn't conclusively answered.
I feel pretty stupid. It was a firewall; not on the VPS, but on my local network. When I tried it on a machine that doesn't go through my local network, it worked. I hope my public confession helps someone else.

can't get http from tomcat on guest vm (nat connection)

I have running centos on guest machine (using virtualbox, connection over nat).
And there's tomcat running on this machine on port 8080.
<Connector port="8080" protocol="HTTP/1.1" address="0.0.0.0"
connectionTimeout="20000"
redirectPort="8443" />
There's port forwarding from host to guest
host 2222, guest 22 (ssh)
host 40001, guest 8080
I try to get page from http://localhost:8080
If I connect from host via ssh and do curl localhost:8080 I get an html page.
But if try to get http://localhost:40001 via browser, it becomes infinitely loading.
netstat -an | find "40001" on host machine shows
C:\Users\user>netstat -an | find "40001"
TCP 0.0.0.0:40001 0.0.0.0:0 LISTENING
TCP 127.0.0.1:30279 127.0.0.1:40001 FIN_WAIT_2
TCP 127.0.0.1:40001 127.0.0.1:30279 CLOSE_WAIT
If I try to telnet on host machine (telnet localhost 40001) the connection is ok.
If I try to get a netstat on guest, I get this
[aegis#localhost ~]$ netstat -an | grep LISTEN | grep tcp
tcp 0 0 127.0.0.1:8005 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8009 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
I can't figure out why telnet from host is working, but I can't get a page via browser. Could you help me, where I've made a mistake in configuration?
At first, I was discaraged because of working "telnet localhost 40001 from host machine".
But there's difference between 22 and 8080 ports.
22 port is opened by default.
8080 port is not.
If you'll have such a problem, you should allow the firewall connection over 8080 port.
E.g., you can execute this statement:
iptables -I INPUT 1 -i eth0 -p tcp --dport 8080 -j ACCEPT

Express http only working with localhost but not with external ip http connection

Tried to avoid the listen IP only on the '127.0.0.1', so the listen port 8000 is also bind with the '0.0.0.0'. But external http clients still not able to get the http connection setup. Also tried tcpdump, the client SYN can reach to the node server, but not any response from the node.js http server... this caused the issue. Really appreciate your assistance!
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 1650/node
tcp 0 0 127.0.0.1:56064 127.0.0.1:27017 ESTABLISHED 1650/node
tcp 0 0 127.0.0.1:56062 127.0.0.1:27017 ESTABLISHED 1650/node
tcp 0 0 127.0.0.1:56065 127.0.0.1:27017 ESTABLISHED 1650/node
tcp 0 0 127.0.0.1:56063 127.0.0.1:27017 ESTABLISHED 1650/node
tcp 0 0 127.0.0.1:56061 127.0.0.1:27017 ESTABLISHED 1650/node

Linux Centos 6 Some how filtered port 80 + broke Apache 2

I have magically been able to break port 80 / Apache server when following a guide to install PHPMyAdmin (http://www.krizna.com/centos/installing-apache2-mysql-server-php-centos-6-lamp/#apache)
Prior to me to starting the guide, Apache 2 was working for me (was able to view pages and see the default blue one)
I followed the guide down to Step 4 under "PHP installation" and went to check the page and I was getting the following error (note: I skipped Mysql installation since I have it already installed and "Testing your page" in the Apache section since I had it working prior).
ERROR
The requested URL could not be retrieved
The following error was encountered while trying to retrieve the URL: http://`192.168.141.22`/
Read Error
The system returned: (104) Connection reset by peer
An error condition occurred while reading data from the network. Please retry your request.
Your cache administrator is webmaster.
Generated Wed, 03 Jul 2013 19:04:56 GMT by tx22rrpep4da (hpm/3.0.55)
I tried to uninstall (yum erase) httpd and php and re-install and no success.
I did an nmap and it shows 80/tcp filtered http.
I even disabled/stopped IP tables incase that was the issue, no luck. I have other things like TS3 running on other ports fine.
Restarted the dedicated server.
netstat -tulpn
te PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 25896/httpd
tcp 0 0 0.0.0.0:30033 0.0.0.0:* LISTEN 2967/./ts3server_li
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 2736/named
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2798/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2873/master
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 2736/named
tcp 0 0 0.0.0.0:10011 0.0.0.0:* LISTEN 2967/./ts3server_li
tcp 0 0 ::1:53 :::* LISTEN 2736/named
tcp 0 0 :::22 :::* LISTEN 2798/sshd
tcp 0 0 ::1:953 :::* LISTEN 2736/named
udp 0 0 0.0.0.0:9987 0.0.0.0:* 2967/./ts3server_li
udp 0 0 127.0.0.1:53 0.0.0.0:* 2736/named
udp 0 0 ::1:53 :::* 2736/named
I had a few other people test the IP in case it was just my connection but they all got the same as well (IP: 192.168.141.22 )
Really hoping I can get this fixed with out doing something over the top like wiping and re-installing centos 6.
The netstat command is showing that Apache is in-deed listening on the following IP & port:
0 0.0.0.0:80
If you want reach Apache in 192... ip, then you need to edit one of the .conf files that has the "Listen" directive(normally in /etc/httpd/conf.d/ports.conf or the main .conf file) and either put in the ip or remove all ips so Apache can listen on all interfaces available in the machine.

Resources