Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can I connect to http://127.0.0.1:8000/ but not to http://192.168.1.6/

I'm running OS X Mountain Lion on a machine with local IP address 192.168.1.6 (as reported by both the Network utility and ifconfig) and am running a local (Django) development web server on port 8000 that I would like to connect to from a virtual machine running a guest OS on the same machine.

On the host OS (ie, OS X running on the metal of the machine w/ address 192.168.1.6) I can connect to my test web server through the browser by navigating to 127.0.0.1:8000; or localhost:8000; but not when using the machine's local IP address. Here's what makes this extra confusing:

  • The router is not filtering the ports; and, just to be sure, I've set it to explicitly forward ports 8000 and 22 to 192.168.1.6; And speaking of port 22,
  • When I start the SSH service, I can connect (from the command line) via ssh 192.168.1.6
  • It's not a browser issue, because I also can't telnet to 192.168.1.6 port 8000 (connection refused) while I can telnet to 127.0.0.1 port 8000, and I can also telnet to 192.168.1.6 port 22
  • The firewall is set to off (as reported in System Preferences) but to be extra safe, I've also set an ipfw rule to allow everything through

Here are the ipfw rules:

00100 allow tcp from any to any dst-port 8000
65535 allow ip from any to any

Here is additional confirmation that the port is, indeed, being listened to by my test server:

netstat -an | grep 8000
tcp4       0      0  127.0.0.1.8000         *.*                    LISTEN 

so what's going on here? Somehow port 22 is being treated differently than port 8000, but every place I can think to look for those differences I can't find any. Why can't I get into this machine's port 8000 using its local ip address?

like image 282
shanusmagnus Avatar asked Oct 03 '13 19:10

shanusmagnus


2 Answers

When you start Django development server you need to give the address explicitly:

python manage.py runserver 192.168.1.6:8000

Or if you want the server to run on all interfaces you can use:

python manage.py runserver 0.0.0.0:8000

In other case Django development server defaults to running on the local interface only.

like image 85
Ludwik Trammer Avatar answered Nov 15 '22 22:11

Ludwik Trammer


The problem for me was I accidentally quit the server whenever trying to copy the server address. So instead of using ctrl+C just write down the address into your browser.

like image 32
Constantin Shimonenko Avatar answered Nov 15 '22 22:11

Constantin Shimonenko