Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to VM running Django

Using VirtualBox, I have a NAT enabled VM running Centos 7. The host OS is Windows 7. I can't seem to access the Django web server running inside the VM. What am I missing?

I have two port forwarding rules set for the Virtual Machine:

Port Forwarding Rules

I start the Django web server on the guest OS with:

python manage.py runserver 0.0.0.0:8000

And I try to visit the webpage on the host OS at:

http://localhost:8000

Google Chrome gives me the error code ERR_CONNECTION_RESET.

The result of curl on the host OS:

[user@win7 ~ ]$ curl http://localhost:8000
curl: (56) Recv failure: Connection reset by peer

Here is the result of a netstat performed on the guest OS:

[user@vm ~ ]$ netstat -na | grep 8000
tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN

Here is the result of a netstat performed on the host OS (with Cygwin):

[user@win7 ~ ]$ netstat -na | grep 8000
  TCP    0.0.0.0:8000           0.0.0.0:0              LISTENING

It is also worth mentioning that the SSH rule works. I can SSH into the machine with no problems.

like image 927
Austin Moore Avatar asked Feb 02 '26 13:02

Austin Moore


1 Answers

This is not a solution, but a work-around for my problem. Maybe this will help anyone encountering a problem similar to mine, and just wants to be able to connect to their VM's webserver.

Since SSH was working, I figured I could access the webpage via a SSH Tunnel. The syntax for doing so via command line is:

ssh -L <local-port>:<remote-host>:<remote-port>

So in my situation, if I wanted to open a tunnel via command line I would do:

ssh -L 8000:127.0.0.1:8000

This would allow me to browse to http://localhost:8000 and access the website.

You can also do this via PuTTY, but I won't explain that here, so just Google for a guide.

like image 157
Austin Moore Avatar answered Feb 04 '26 05:02

Austin Moore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!