简体   繁体   中英

Node.js EADDRNOTAVAIL can't access via external IP

app = require('http').createServer()
app.listen(5000, '75.113.126.31')

Error: listen EADDRNOTAVAIL

People say this error means I'm trying to listen on an IP address that I don't own. But that is my external IP address according to google.

Also, if I omit my IP, it only works when I visit localhost:5000 and 127.0.0.1:5000 , visiting 75.113.126.31:5000 doesn't work, even though people say node should listen there too when I don't give a 2nd argument to listen. I also tried listening on IP 0.0.0.0 with no luck accessing it through external IP.

What are the possible causes? I disabled Windows firewall but that didn't help.

Your external IP and your computer's network address often have almost nothing in common. In fact it would be very unusual if they did match.

Normally you bind to 0.0.0.0 if you want your service to be available remotely.

It's also worth noting that if you have some kind of router or firewall you'll need to configure port mapping to get port 5000 to route to your local IP correctly.

ipconfig should show you your actual IP address.

You should also be aware that some routers don't handle mapping internal traffic back to a local IP. Many do, so it's not always a problem, but if it doesn't work that might be the case.

The error message you are getting is correct. I'm going to assume you are on a computer behind a router. That ip address Google is reporting is the ip address assigned to your router not your computer, ie your computer doesn't own it. You can prove this by running the command ipconfig in a cmd prompt, finding out your eth/wifi ip address, and using that in your app.listen (it'll probably start with 192 or 10), it should work. If you want to make your app public an easier way might be to just forward the port 5000 from your router the computer running the node app. Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM