access private VM from other computer over wifi

后端 未结 4 1355
孤街浪徒
孤街浪徒 2021-02-04 06:26

I have a private network VM for developing on my mac. I\'d like for my android device to be able to communicate with the VM on my mac. Currently I can visit the IP defined in my

相关标签:
4条回答
  • 2021-02-04 06:44

    This can be just a small problem with port forwarding / setting a dmz. Since it's on the same machine; you can interact since it's physically on the same adapter. However if you are trying to access outside of that, you should try tinkering with the ports.

    0 讨论(0)
  • 2021-02-04 06:47

    You are using a Private Network IP which is only accessible by the Host machine (NOT visible to other machines even they are in the same WLAN).

    In your case, the best choice is to use Public Network (bridged) so that your Android device can access it.

    add config.vm.network "public_network" in your Vagrant file in the config block.

    BTW: the default NAT mode is fine but you'll have to set proper port forwarding rules for each service you want to access (e.g. SSH, HTTP, HTTPS etc...).

    0 讨论(0)
  • 2021-02-04 06:48

    You can easily access your Vagrant from any machine on your network, by simply ensuring that the port forwarding rules aren't bound to your localhost (127.0.0.1).

    If you're using VirtualBox as your provider, you can change this on the fly, so you can have it be private by default (which is of course more secure), and then you can go change it in VirtualBox while your VM is running to expose the port to other machines on your network (and possibly the internet, so be careful!)

    To expose the port:

    • Start Virtual Box
    • Select your VM in the left hand side bar
    • Click Settings | Network | Advanced | Port Forwarding
    • Find the port you want to expose in the port list
    • Set it's Host IP to an empty string, and click OK.

    The port is now available to other machines on your network, and possibly the internet, so don't do this unless you're positive you're ok with opening up the port!

    Of course to revert it, just do the same process and set the Host IP to 127.0.0.1 again.

    0 讨论(0)
  • 2021-02-04 06:54

    A little expansion on the accepted answer: after adding the public network option in your vagrant file and reloading it, ssh into it the old way and then run ifconfig to get the IP you can use to access the vm in your local network from any other device.

    Docs: https://www.vagrantup.com/docs/networking/public_network.html

    0 讨论(0)
提交回复
热议问题