Connect to localhost from another computer

localhost

I'm trying to access a database that is hosted in a Mac localhost from my Android device which are both connected to the same network.

The localhost project is running at www.localhost:8000/

I've entered the IP: 192.168.1.1 (of my laptop connection) to my phone browser and I was able to see the root folder of my project.

However, when I attempted to run it at 192.168.1.1:8000/, I was not able to access anything and the web browser returned "Webpage not available".

So the issue now is that I can access the root folder using my Android device but I cannot access the "localhost server" of my laptop.

Best Answer

I would imagine this is because your server is set to listen on the loopback interface only. You can confirm this by looking at the output of netstat -an. As an example of output

Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:53            0.0.0.0:*               LISTEN     

This means that this server (bind nameserver in this case) is only LISTENing for connections on port 53 on the address 127.0.0.1.

You can get around this by either configuring the server to listen on the 192.168.1.1 address or to do something like ssh tunneling to get around this. It's a bit of an old article (2007) but the contents is still relevent: http://magazine.redhat.com/2007/11/06/ssh-port-forwarding/ (mirror).

I personally use Putty to do port forwarding of this ilk on my windows hosts.

Related Question