无法从主机连接到Vagrant专用网络 [英] Unable to connect to Vagrant private network from host

查看:104
本文介绍了无法从主机连接到Vagrant专用网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无用的虚拟盒子并且正在运行.到目前为止,我一直无法连接到Web服务器.这是启动程序:

I have a vagrant virtual box up and running. So far I have been unable to connect to the web server. here is the start up:

[jesse@Athens VVV-1.1]$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 => 2222 (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: 
    default: Guest Additions Version: 4.2.0
    default: VirtualBox Version: 4.3
==> default: Setting hostname...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => /home/jesse/vagrant/vvvStable/VVV-1.1
    default: /srv/www => /home/jesse/vagrant/vvvStable/VVV-1.1/www
    default: /srv/config => /home/jesse/vagrant/vvvStable/VVV-1.1/config
    default: /srv/database => /home/jesse/vagrant/vvvStable/VVV-1.1/database
    default: /var/lib/mysql => /home/jesse/vagrant/vvvStable/VVV-1.1/database/data
==> default: VM already provisioned. Run `vagrant provision` or use `--provision` to force it
==> default: Checking for host entries

在我的主机控制台上,ip addr显示产量:

on my host console, ip addr show yields:

4: vboxnet0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000                                       
    link/ether 0a:00:27:00:00:00 brd ff:ff:ff:ff:ff:ff                                                                         
5: vboxnet1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000                                      
    link/ether 0a:00:27:00:00:01 brd ff:ff:ff:ff:ff:ff

在来宾上它产生:

vagrant@vvv:~$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:12:96:98 brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global eth0
    inet6 fe80::a00:27ff:fe12:9698/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:2c:d4:3e brd ff:ff:ff:ff:ff:ff
    inet 192.168.50.4/24 brd 192.168.50.255 scope global eth1

现在,我要做的就是以任何可行的方式访问虚拟机上的Web服务器.我尝试了各种各样的事情,只是在黑暗中拍摄.我很乐意提供任何具体信息.任何帮助或建议,将不胜感激

For now, all I want to do is access the web server on the virtual machine, whatever way works. I have tried a variety of things, just shooting in the dark. I would be happy to provide any specific info. Any help or suggestions would be greatly appreciated

推荐答案

基于提供的输出,该框具有2个网络接口,其中1个是默认NAT,另一个是专用-请问您说.

Based on the output provided, the box has 2 network interfaces, 1 is the default NAT and the other private - ask you said.

无法通过私有接口访问VM内托管的网站的原因:可能是主机eth0wlan0 IP地址与私有接口不在同一网络中-> 192.168.50.4/24并且没有路线.

The reason why you are not able to access the web site hosted within the VM thru the private interface: it could be that host eth0 or wlan0 IP address is not in the same network as the private interface -> 192.168.50.4/24 and there is no route.

要访问由来宾内的Web服务器托管的站点,您可以使用以下选项:

To access the the site hosted by the web server within the guest, you have the following options:

转发Web端口,例如80托管8080(您不能使用80,因为它是* NIX上的特权端口).添加以下

Forward the web port, e.g. 80 to host's 8080 (you can't use 80 because it is a privileged port on *NIX). Add the following

Vagrant.configure("2") do |config|
  config.vm.network "forwarded_port", guest: 80, host: 8080,
    auto_correct: true
end

注意:如果主机上的端口已在使用中,则auto_correct将解决端口冲突.

NOTE: auto_correct will resolve port conflicts if the port on host is already in use.

执行vagrant reload,您将可以通过http://localhost:8080/

添加公共网络接口

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

在启动并运行虚拟机后获取其IP,端口转发不适用于桥接网络.因此,您将使用http://IP_ADDR访问该站点,如果它在VM中绑定到80,否则请指定端口.

Get the IP of VM after it is up and running, port forwarding does NOT apply to bridged networking. So you'll be accessing the site by using http://IP_ADDR, if within the VM it binds to 80, otherwise specify the port.

这篇关于无法从主机连接到Vagrant专用网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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