Cannot access local server with IP address while localhost and 127.0.0.1 can
Solution 1
Check that your server is listening:
sudo lsof -n | grep TCP | grep LISTEN
You can also check the route using nc. Start nc on the server listening on an unused port and then connect from another machine -- this will verify iptables and routes are correct.
My guess is that you're listening on the localhost only.
Solution 2
I fixed this issue with following ways:
I run the command
sudo ufw status
And I found that the port 80 (in my case) was not in the list.
Then I run the command
sudo ufw allow 80
This fixed the issue.
Related videos on Youtube
Hearen
A junior java engineer trying pretty hard to become a senior.
Updated on September 18, 2022Comments
-
Hearen over 1 year
I am trying to let other computers to access my local server but I tried myself locally that I cannot access it locally even myself.
Several things you should know:
My target
Visit my server via http://172.26.141.106:5201/
What I can do now
I can access my server via these two ways:
IP configuration
Result of
ifconfig | grep inet
inet addr:172.17.0.1 Bcast:0.0.0.0 Mask:255.255.0.0 inet addr:172.26.141.106 Bcast:172.26.141.255 Mask:255.255.255.0 inet6 addr: fe80::f767:cd56:9641:d3a9/64 Scope:Link inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host
Hosts
Output of
cat /etc/hosts
:127.0.0.1 localhost.localdomain localhost 127.0.0.1 hearen.pc 127.0.0.1 hearen-OptiPlex-7050 127.0.0.1 staging 127.0.0.1 arthas 172.26.141.106 localhost hearen.pc
Firewall
$ sudo ufw disable Firewall stopped and disabled on system startup $ sudo ufw status Status: inactive
Is there some way that I missed out? All I want is to let others access my server via http://172.26.141.106:5201/
Any help will be appreciated :)
Updated 2019-01-10
With the help of @Ed King, I check the ports via
sudo lsof -i -P -n | grep LISTEN | grep 5201
and only127.0.0.1
was listenned on.Problem solved after I configured my Angular server to listen on
0.0.0.0
.-
Admin over 3 yearsIn the /etc/hosts file above localhost points to 2 different IP addresses, is this allowed? Will it work?
-
-
Hearen over 5 yearsThank you, you are leading the right direction. It is and now I configure it to listen on
0.0.0.0
. Problem solved. Thanks for the help. I will mark your answer after minutes when I am allowed. -
Mohit Mittal almost 3 yearsThanks for making me think in the correct direction. If you landed here due to google firebase echosystem, please refer to - stackoverflow.com/questions/58260877/…
-
Ed King almost 3 yearsThis will work if ufw was his problem -- in his question he disabled ufw and still could not connect.