如何从另一个虚拟机来宾访问流浪来宾?

问题描述:

场景是我的开发环境在我的笔记本电脑(主机)上的 Vagrant 机器上,我想在 vitualbox vm 中进行浏览器测试,所以我需要从另一个 vm 中看到一个.

The scenario is that my dev environment is on a Vagrant box on my laptop (host) and I would like to do browser testing in a vitualbox vm, so I need to see one vm from another.

vagrant box 的端口是:8080,转发到主机的端口是:8080.这样我就可以从localhost:8080的主机看到服务器

The vagrant box's port is :8080 which is forwarded to the host on the same port :8080. So I can see the server from the host at localhost:8080

浏览器测试虚拟机应该使用哪个地址?

Which address should I be using for the browser testing vm?

测试虚拟机的默认网关?流浪虚拟机的ip?主机的虚拟网络ip?

The testing vm's default gateway? The vagrant vm's ip? The host's virtual network ip?

我应该在浏览器测试虚拟机上使用 NAT 还是仅主机适配器?

And should I be using a NAT or host only adapter on the browser testing vm?

这产生了很多组合,我相信我已经尝试过所有这些组合.在这里我还需要了解什么?

That makes for a lot of combinations, all of which I believe I have tried. What else do I need to understand here?

在您的用例中,您应该使用桥接网络(Vagrant 中的公共网络).如果 VM 驻留在同一主机上,您甚至可以使用内部(Vagrant 中的私有网络).

In your use case, you should be using Bridged networking (Public Network in Vagrant). If the VMs reside on the same host, you can even use internal (Private Network in Vagrant).

如果使用公共网络,虚拟机的第二个 NIC 将能够从您网络中的 DHCP 服务器(例如您的家庭路由器)获取 IP 地址.

If using Public Network, the VM's 2nd NIC will be able to obtain an IP address from the DHCP server in your network (e.g. your home router).

只需在您的 Vagrantfile 中添加以下代码块并执行 vagrant reload

Simply add the following code block in your Vagrantfile and do a vagrant reload

Vagrant.configure("2") do |config|
  config.vm.network "public_network"
end

您应该能够通过使用vagrant sshifconfig/ip addr show 来获取IP 地址.

You should be able to get the IP address by using vagrant ssh and ifconfig / ip addr show.