无法让虚拟机中运行的网站显示在浏览器中,网络混乱

无法让虚拟机中运行的网站显示在浏览器中,网络混乱

我想这是一个关于 Ubuntu 网络的问题,但需要一些背景知识。

我是 Linux 新手。我有一个接管的 Trellis Wordpress 网站,因此设置了一台双启动笔记本电脑,其中装有 Ubuntu 18.04(设置/环境所需的版本)。我按照前一位开发人员的说明设置了环境,克隆了项目,然后进入 trellis 文件夹并执行 vagrant up。

这一切都有效,我得到了这个:

  ==> default: Machine 'default' has a post vagrant up message. This is a message
  ==> default: from the creator of the Vagrantfile, and not from Vagrant itself:
  ==> default: 
  ==> default: Your Trellis Vagrant box is ready to use!
  ==> default: * Composer and WP-CLI commands need to be run on the virtual machine
  ==> default:   for any post-provision modifications.
  ==> default: * You can SSH into the machine with vagrant ssh.
  ==> default: * Then navigate to your WordPress sites at /srv/www
  ==> default:   or to your Trellis files at /home/vagrant/trellis.
  ubuntu@ubuntu-laptop:~/uweek-cms/trellis$

然后我应该(根据说明)能够使用本地浏览器导航到该网站:http://uweekdev.abaso.co.uk/

但这并不管用,Chrome(和 Firefox)报告称:

  This site can’t be reached
  uweekdev.abaso.co.uk refused to connect.

因此 Trellis 在 hosts 文件中插入了一行:cat /etc/hosts 内容为:

  ## vagrant-hostmanager-start id: 16ff5846-31d4-4402-aa91-479139d39183
  192.168.50.5  uweekdev.abaso.co.uk
  ## vagrant-hostmanager-end

之前的开发人员在安装 Ubuntu 本身时谈到了网络适配器,但是是在虚拟安装的背景下,但由于文档是为 ubuntu 作为操作系统和在 Windows 上使用 VirtualBox 编写的,所以我不确定我是否错过了一步!

以下是主机上的 ifconfig 的输出:

## vagrant-hostmanager-start id: 16ff5846-31d4-4402-aa91-479139d39183
192.168.50.5    uweekdev.abaso.co.uk

## vagrant-hostmanager-end
  ubuntu@ubuntu-laptop:~/uweek-cms/trellis$ ifconfig
  enp1s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 54:e1:ad:8e:30:09  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 4190  bytes 612036 (612.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 4190  bytes 612036 (612.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  vboxnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.50.1  netmask 255.255.255.0  broadcast 192.168.50.255
        inet6 fe80::800:27ff:fe00:0  prefixlen 64  scopeid 0x20<link>
        ether 0a:00:27:00:00:00  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 78  bytes 9312 (9.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  wlp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.12  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::ebb5:652:1251:6b01  prefixlen 64  scopeid 0x20<link>
        ether 44:03:2c:4b:d6:88  txqueuelen 1000  (Ethernet)
        RX packets 3300  bytes 2803503 (2.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2431  bytes 462691 (462.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  ubuntu@ubuntu-laptop:~/uweek-cms/trellis$ ifconfig -s -a
  Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
  enp1s0    1500        0      0      0 0             0      0      0      0 BMU
  lo       65536     4204      0      0 0          4204      0      0      0 LRU
  vboxnet0  1500        0      0      0 0            90      0      0      0 BMRU
  wlp2s0    1500     3526      0      0 0          2712      0      0      0 BMRU

这是我通过 vagrant ssh 进入客户端虚拟机时的情况:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:fed2:10a5  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:d2:10:a5  txqueuelen 1000  (Ethernet)
        RX packets 2844  bytes 315692 (315.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2184  bytes 341128 (341.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.50.5  netmask 255.255.255.0  broadcast 192.168.50.255
        inet6 fe80::a00:27ff:fe34:19a5  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:34:19:a5  txqueuelen 1000  (Ethernet)
        RX packets 96  bytes 7852 (7.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 113  bytes 8864 (8.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 22  bytes 1824 (1.8 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 22  bytes 1824 (1.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

现在我承认我迷路了。我不懂任何有关网络方面的事情,而且我不确定如何让虚拟机中运行的网站加载到我的浏览器中!

有什么想法可以解决/尝试/检查什么问题吗?

非常感谢您帮助一位热心的新手。

答案1

您将需要编辑您的/etc/hosts文件,因为 IP 地址与您的虚拟机报告的 IP 地址不匹配。

/etc/hosts变革:

192.168.50.5  uweekdev.abaso.co.uk

到:

192.168.50.1  uweekdev.abaso.co.uk

保存文件,如果需要,清除浏览器缓存以强制其再次查找域名。这应该可以解决您的问题

答案2

好吧,在听取了 @matigo 的善意建议后,我想我对 Vagrant、VirtualBox 和 Ubuntu 网络的工作原理有了更多的了解!

解决方案:我用 vagrant destroy 销毁了虚拟机,执行了 apt-get upgrade,重新启动,然后再次运行 vagrant up 来重新创建所有内容。奇怪的是,设置看起来有点不同,但这次浏览器 URL 最终起作用了。

注意:我之前尝试过销毁并重新创建,但没有任何效果。vbox 设置中的 NAT 和主机专用适配器均拒绝“混杂”,最终主机条目为最初设置的 50.5。

相关内容