通过wifi从其他计算机访问私有VM [英] access private VM from other computer over wifi

查看:36
本文介绍了通过wifi从其他计算机访问私有VM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个专用网络 VM 用于在我的 mac 上进行开发.我希望我的 android 设备能够与我的 mac 上的 VM 进行通信.目前我可以在我的 mac 上访问我的 Vagrantfile 中定义的 IP,10.10.10.10 并可以很好地访问它,但我无法通过我的手机在同一个 wifi 上访问它.

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 Vagrantfile, 10.10.10.10, on my mac and access it just fine but I can't access it via my phone on the same wifi.

我需要做什么才能使其在我的本地网络中可用并通过 wifi 对我的手机可见?

What do I need to do to make it available across my local network and visible to my phone over wifi?

这是我的 Vagrantfile

Here's my Vagrantfile

Vagrant.configure("2") do |config|
  config.vm.box = "precise64"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"

  config.vm.network :private_network, ip: "10.10.10.10"
    config.ssh.forward_agent = true

  config.vm.provider :virtualbox do |v|
    v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    v.customize ["modifyvm", :id, "--memory", 1024]
    v.customize ["modifyvm", :id, "--name", "PHPBoxWith54"]
  end

  nfs_setting = RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/
  config.vm.synced_folder "./", "/var/www", id: "vagrant-root" , :nfs => nfs_setting
  config.vm.provision :shell, :inline =>
    "if [[ ! -f /apt-get-run ]]; then sudo apt-get update && sudo touch /apt-get-run; fi"


  config.vm.provision :shell, :inline => 'echo -e "mysql_root_password=root
controluser_password=awesome" > /etc/phpmyadmin.facts;'

  config.vm.provision :puppet do |puppet|
    puppet.manifests_path = "manifests"
    puppet.module_path = "modules"
    puppet.options = ['--verbose']
  end
end

推荐答案

您使用的专用网络 IP 只能由主机访问(即使它们在同一 WLAN 中,其他计算机也不可见).

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).

就您而言,最好的选择是使用公共网络(桥接),以便您的 Android 设备可以访问它.

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

在配置块的 Vagrant 文件中添加 config.vm.network "public_network".

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

顺便说一句:默认的 NAT 模式很好,但您必须为要访问的每个服务(例如 SSH、HTTP、HTTPS 等)设置适当的端口转发规则.

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...).

这篇关于通过wifi从其他计算机访问私有VM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆