47

I'm viewing a locally hosted website (using grunt serve, if that matters). I can view it via http://localhost:9000/ or http://127.0.0.1:9000/, but not via http://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 at http://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
  • 558
  • 1
  • 4
  • 6
  • @fvu If you make this an answer, I'll mark it correct. I changed my `Gruntfile.js` hostname to `0.0.0.0` and all is fine now. – user1502723 Jul 03 '16 at 23:20
  • 2
    If Skype is running, I get same problem you described. – Uroš Podkrižnik Feb 27 '18 at 10:04
  • For me, the problem was that I hadn't specified in Windows that my particular LAN connection was "private" instead of "public". Now when I use a Mac on my LAN to ping the local IP of my PC, it works. – Ryan Sep 14 '20 at 20:13

2 Answers2

63

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.

fvu
  • 32,488
  • 6
  • 61
  • 79
  • 1
    Thanks for the extra tip about `0.0.0.0`. – user1502723 Jul 03 '16 at 23:51
  • @fvu the same problem I suppose (https://stackoverflow.com/questions/51026532/json-server-cannot-access-via-local-ip) – Choletski Jun 25 '18 at 15:04
  • For 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 `:123` , `127.0.0.1:123` , `0.0.0.0:123` ... for you to access via localhost or IP. – user104309 May 08 '19 at 07:03
  • How 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. – Xantosh Lamsal May 15 '20 at 08:45
  • 1
    @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. – fvu May 15 '20 at 18:52
  • How can I make my public ip available to everyone? – topsoftwarepro Jun 08 '21 at 02:08
3

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>)

tejasvi88
  • 635
  • 7
  • 15