简体   繁体   中英

Access django server on virtual Machine

I know there is a lot of similar question but I haven't be able to make it work.

I have a VM (VirtualBox) running CentOS 7

I set up 2 adapters, a NAT and a host-only adapter. This way I have internet output on the VM and I can enter via ssh using a ip (192.168.56.102) from the host

Now, I'm trying to reach a django server running on the guest from the host

I've tried running at 0.0.0.0:8000 and 192.168.56.102:8000 but I always got

$ curl 192.168.56.2:8000
curl: (7) Failed connect to 192.168.56.2:8000; No route to host

I've read some solutions using a bridge instead of NAT, but I need to keep the output to internet and the access via ssh

Finally I opened the port 8000 on the guest firewall and its working now.

For CentOS 7, i followed those steps centos 7 - open firewall port

firewall-cmd --zone=public --add-port=8000/tcp --permanent

firewall-cmd --reload

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM