socket io server running on port 90 - AWS ec2 - security group port is open - yet can't connect - node.js

I have a running nodejs based socket.io server on AWS ec2, this server is running on port 90, and i can run the local tests on this server at the same port.
netstat -a shows me the port 90 as open as well for connections
tcp 0 0 localhost:3001 *:* LISTEN
tcp 0 0 *:90 *:* LISTEN
I can vouch for the fact that I have the port 90 open on my security group settings, yet I can not connect at the port 90 to my server.
I am not doing anything as foolish as making my clients connect over the localhost.
I have tried telnet to my server at the port 90 but it doesn't work
I have port 22 and 80 open as well and I can very well telnet to them.

Related

Why my website hosted on aws refuses to connect?

I have a node app which runs on localhost perfectly, I hosted it on AWS ec2 instance on port 80 and it worked fine too, after 7 days of inactivity when I searched public IP address of my ec2 instance(on any browser), it says <public_ipv4> refused to connect.
Here are a few things I did for troubleshooting which I read from AWS forums but not getting any luck:
deleted the node_modules/ directory and reinstalled using npm
install command
Have correctly allowed HTTP traffic on port 80 inside inbound rules of security groups for that instance(i have only one instance running)
Ran netstat -nplt | grep 80 , which gave me output :
tcp6 0 0 :::80 :::* LISTEN
I have added a script in package.json file, through which app.js file will run
In my app.js file i am listening to port 80:
app.listen(80, async function(){
console.log("server has started");
})
What else am I missing?
Screenshot of inbound rules :
it seems you have allowed only IP v6 address on Inbound traffic of Security Groups..
Not added allow permission for IPv4 address..
Add below rule
HTTP tcp 0.0.0.0/0 80
if you have added both rule ( IPV4 and IPV6) then
sudo netstat -tnlp | grep :80
should show below both lines..
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
tcp6 0 0 :::80 :::* LISTEN
but in your case it showing only tcp6
See if the steps below helps.
Did you stop your ec2 instance start and it again if you did it would have changed your public ip if that is case use the new public ip.
Check your security groups attached to the ec2 instance if it allows in bound traffic on port 80.
If the first step does not work connect to your ec2 instance and run a curl command to see if your app is running.
In my app.js file i have used port 80 :
app.listen(80, async function(){
console.log("server has started");
})
but when i changed port number to 3000 in app.listen , it worked , i dont't know how did this happen though.
There was no issue with security groups.

Raspberry Pi Node Server not connecting on other machines

I am running ubuntu 18.4 on a raspberry pi 3b+. I am using node to host an angular web app. I have set a static ip on the RPi but cannot access the webapp from my windows machine at http:ipadress. I get 'refused to connect'.
server code:
const PORT = process.env.PORT || 8080;
http.listen(PORT, "0.0.0.0", () => {
console.log(`Server is running on port ${PORT}.`);
});
netstat:
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 2142/node
tcp 0 0 127.0.0.1:8081 0.0.0.0:* LISTEN 2102/ng serve --por
tcp 0 0 127.0.0.1:41804 127.0.0.1:27017 ESTABLISHED 2142/node
tcp 0 0 127.0.0.1:27017 127.0.0.1:41804 ESTABLISHED 1347/mongod
How can I access my node/angular app from another machine!!!
thank you.
I haven't taken a look at your code above specifically - I tried to run it but as it is not a minimum working example it failed with ReferenceError: http is not defined. But I'm assuming you know that?
Assuming therefore that the fuller version of your code compiles and the problem is that port 8080 on the Raspberry Pi is closed; then to open it do the following in the Pi terminal:
sudo apt install ufw
sudo ufw allow ssh
sudo ufw enable
sudo ufw allow 8080
You can skip line two if you aren't using ssh to access it; this just stops you being thrown off if you are.
The port should now be accessible on your local network (though probably not the internet, depending on how your router is set up).
I found this Run your Node.js application on a headless Raspberry Pi tutorial useful.

Connection Refused on Amazon Web Services

Can't access node.js API on port 3000 on AWS EC2 instance, but netstat shows port :3000 listening and my AWS security group has TCP rules for this port. What else could the problem be?
I've tried changing port, setting security group rules and adding port to iptables and it didn't work. I'm using node 10.6.0.
When I use netstat -tulpn | grep LISTEN it contains the following line:
tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN 8270/node
When i try to access myip:3000/socket (my node endpoint) it shows: ERR_CONNECTION_REFUSED

Azure Ubuntu VM application only able to connect on port 80

I have an Ubuntu16.04 VM on Azure, and am trying to run a node server on it. When I bind the port to 80, I am able to access it from my browser (http://a.b.c.d:80). However, if I try to instead bind the server to a different port, such as 3300 or 8080, the browser times out when trying to connect to it. (http://a.b.c.d:3300)
I have ensured that:
There exists an inbound security rule for port 3300 in the NSG
The windows firewall of the machine of the browser allows port 3300 (I have even tried temporarily turning it completely off but to no avail)
I am not using an azure load balancer
I am starting node with root privileges
Node is bound to (port, "0.0.0.0")
I am listening on the correct port (I think?)
netstat -ant | grep 3300 gives
tcp6 0 0 :::3300 :::* LISTEN
I have spent a few hours now researching on the internet how to get it to work and tried everything I could find, but to no avail. If anyone has any input i'd be happy to try it out.
Jason was correct, it was a ufw issue. If anyone comes across this question in the future, I solved it with the command
sudo ufw allow proto tcp from any to any port 3300

Meteor app running on 127.0.0.1 instead of 0.0.0.0

I have my meteor app running on my production server. I have a reverse proxy setup on a different server.
A curl from my reverse proxy server to my app server gives me a Connection Refused.
My app is running on port 8080 and my firewall allows access to the port. I suspect the reason for the connection refused is that my app is running on 127.0.0.1 instead of 0.0.0.0
On running sudo netstat -tapn I get a
tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 14391/node
How do I get the app to run on 0.0.0.0. If this is not the reason, what else could cause a connection refused?
127.0.0.1 is the loopback IP it's usually the same as localhost (as defined in your hosts file). you should never be able to connect to that IP from the outside. 0.0.0.0 binds to all IPs on the server, which is accessible from the outside.

Resources