Can't access localhost via IP address
Solution 1
If you can access a server running on your own machine via 127.0.0.1
(or localhost
) but not via the computer's ip address, this means that the server software is configured to listen on the localhost interface only. This is a configuration item and to avoid exposing a potentially unsecure server many server programs come preconfigured to listen on localhost only. That way you can safely test locally before exposing the server.
Note that 0.0.0.0
means "listen on all interfaces present on this computer" which is convenient, but may cause security issues if the machine has multiple interfaces.
Solution 2
If you are using Python 3.8, this is a known bug. The solution is to manually specify the IP address with the -bind
argument or use Python 3.9.
python -m http.server 8000 --bind 127.0.0.1
(or 0.0.0.0
, <insert-your-ip-here>
)

user1502723
Updated on June 04, 2021Comments
-
user1502723 over 1 year
I'm viewing a locally hosted website (using
grunt serve
, if that matters). I can view it viahttp://localhost:9000/
orhttp://127.0.0.1:9000/
, but not viahttp://10.0.0.16:9000/
.10.0.0.16 is my local IP address (from
ifconfig
or System Preferences), but I cannot access my locally hosted content athttp://10.0.0.16:9000/
from either the device that is hosting it or from other devices on the network.I haven't had trouble using my local IP address to access locally hosted sites when my computer is on other networks, only on my home network. Do you have any idea what needs to change?
-
user1502723 over 6 yearsThanks for the extra tip about
0.0.0.0
. -
Choletski over 4 years@fvu the same problem I suppose (stackoverflow.com/questions/51026532/…)
-
user104309 over 3 yearsFor me, it was the opposite. Service was accessible by IP and Hostname but not by localhost or 127.0.0.1 !
netstat - tulpn
in Ubuntu. The same PID/Service running on port 123 should be bound on all<IP>:123
,127.0.0.1:123
,0.0.0.0:123
... for you to access via localhost or IP. -
Xantosh Lamsal over 2 yearsHow do we make sever to listen to all the ip address and ports? I am developing API using laravel and now I need to access localhost through ip from android within same network.
-
fvu over 2 years@XantoshLamsal I don't understand your question: "all ports" is to my knowledge not readily available - and actually never needed, and "accessing localhost through ip from android within same network" is to say the least a cryptic statement: localhost is the name given to the machine you're working on, not a specific machine on the network.
-
topsoftwarepro over 1 yearHow can I make my public ip available to everyone?