debian 9 stretch vagrant vm box host无法访问

时间:2017-07-21 13:09:19

标签: linux vagrant debian private-network

先决条件:

- Debian 9 Stretch
  -> virgin and not on a VM
- VirtualBox 5.1.24 r117012 (Qt5.7.1)
  -> VirtualBox Extension Pack 5.1.24 117012
  -> Virtual Box Guest Additions
- Vagrant 1.9.7

Vagrantfile

Vagrant.configure("2") do |config|

    # It's a Ubuntu box
    config.vm.box = "Foo/Bar"
    config.vm.box_download_insecure = true

    config.vm.network "private_network", ip: "192.168.3.23"
    config.vm.hostname = "www.hostname.domain"
    config.hostsupdater.aliases = ["hostname.domain", "pma.www.hostname.domain"]

    config.vm.provision "file", source: "env/vgrt/id_rsa", destination: "/home/vagrant/.ssh/id_rsa"
    config.vm.provision "file", source: "env/vgrt/ssh_config", destination: "/home/vagrant/.ssh/config"
    config.vm.provision "shell", path: "env/vgrt/bootstrap.sh"

end

vagrant upvagrant ssh执行得很好

的/ etc /主机

127.0.0.1   localhost
127.0.1.1   mypchostname

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

172.28.128.1 hostname.domain
192.168.3.23  www.hostname.domain  # VAGRANT: 48b09d14c4dfba94981a628a986b69e0 (default) / d0fbe81e-2bd6-49f5-a285-3e2c4d4e7cef
192.168.3.23  hostname.domain  # VAGRANT: 48b09d14c4dfba94981a628a986b69e0 (default) / d0fbe81e-2bd6-49f5-a285-3e2c4d4e7cef
192.168.3.23  pma.hostname.domain  # VAGRANT: 48b09d14c4dfba94981a628a986b69e0 (default) / d0fbe81e-2bd6-49f5-a285-3e2c4d4e7cef

在流浪汉(客人)

ifconfig

enp0s3    Link encap:Ethernet  HWaddr 08:00:27:2c:61:d0  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe2c:61d0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1841 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1567 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:171675 (171.6 KB)  TX bytes:164725 (164.7 KB)

enp0s8    Link encap:Ethernet  HWaddr 08:00:27:7d:ea:54  
          inet addr:192.168.3.23  Bcast:192.168.3.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe7d:ea54/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:1296 (1.2 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ping 192.168.3.23 =>细

在debian shell(主机)中

ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s31f6: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether d4:81:d7:cd:4a:5b brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.98/24 brd 192.168.0.255 scope global enp0s31f6
       valid_lft forever preferred_lft forever
    inet6 fe80::d681:d7ff:fecd:4a5b/64 scope link 
       valid_lft forever preferred_lft forever
3: wlp1s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 28:16:ad:e5:90:75 brd ff:ff:ff:ff:ff:ff
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
    inet 192.168.3.1/24 scope global vboxnet0
       valid_lft forever preferred_lft forever

ping 192.168.3.23 =&gt;主持人无法访问

我不知道如何让Vagrant VM Box托管我的Debian。愿有人遇到类似的问题。

2 个答案:

答案 0 :(得分:2)

您可能遇到VirtualBox 5.1.24 https://www.virtualbox.org/ticket/16911的以下问题。

另见Vagrant问题https://github.com/mitchellh/vagrant/issues/8802

答案 1 :(得分:0)

VirtualBox 5.1.24 r117012(Qt5.7.1)

提示位于ip addr

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
    inet 192.168.3.1/24 scope global vboxnet0
       valid_lft forever preferred_lft forever

VirtualBox界面已创建但未启动。我必须输入

ifconfig vboxnet0 up

更好的解决方案是在由框创建时自动启动VirtualBox界面的守护程序。

<强>更新

VirtualBox 5.1.22 r115126(Qt5.7.1)

关于@szeestraten链接的virtualbox.org上的票证:

我安装了https://www.virtualbox.org/ticket/16911#comment:12中提到的VirtualBox 5.1.22。带上流浪盒后,界面会自动出现。

使用此解决方案可以部分解决问题。部分地,我被迫安装较旧版本的VirtualBox。所以我在这里保留两种解决方案。

<强>更新

VirtualBox 5.1.26 r117224(Qt5.7.1)

新更新已于昨天(8月2日和17日)发布,他们解决了这个问题。它按预期工作,不需要降级到较旧版本的VirtualBox。