如何在公网访问Vagrant Box [英] How to access Vagrant Box in public network
问题描述
我在 vagrant 中创建了一个盒子.在 Vagrantfile 中,我将网络指定为
I had created on e box inside vagrant. In the Vagrantfile, I had given the network as
Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network :private_network, ip: "192.168.33.10"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
config.vm.network :public_network
我无法访问 VLAN 外的 VagrantBox.我需要访问公共网络中的 Vagrant Box.如何配置vagrantfile,需要公网访问?
I can't access the VagrantBox outside the VLAN. I need to access the Vagrant Box in public network. How to configure vagrantfile in such a way that I need to access in public network?
推荐答案
取消注释 Vagrantfile
config.vm.network :public_network
文件如下图
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "box_name"
config.vm.network :public_network
end
保存,使用vagrant reload
重启虚拟机.
Save it, restart the VM by using vagrant reload
.
对于 VirtualBox,它将使用桥接模式进行网络连接.这意味着虚拟机将从 DHCP 服务器获取 VLAN 的 IP 地址.
For VirtualBox, it'll use Bridged mode for networking. Which means the VM will acquire an IP address from the DHCP server for the VLAN.
你也可以设置VLAN IP:config.vm.network :public_network, ip: "192.168.0.160"
You can also set the VLAN IP with: config.vm.network :public_network, ip: "192.168.0.160"
参考 => 公共网络
这篇关于如何在公网访问Vagrant Box的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!