尝试在 Ubuntu 和 virtualbox 之间设置网络

尝试在 Ubuntu 和 virtualbox 之间设置网络

我在我的计算机上运行着一个 ubuntu,在 Virtualbox 中还有一个 ubuntu,我试图让它们连接在一起,这样它们就可以互相访问,而且都可以访问互联网。

这是ifconfig主机的

eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 130.15.1.72  netmask 255.255.255.0  broadcast 130.15.1.255
    inet6 fe80::3f37:1632:b494:f83d  prefixlen 64  scopeid 0x20<link>
    ether 84:2b:2b:a2:f0:d2  txqueuelen 1000  (Ethernet)
    RX packets 7275030  bytes 2419246030 (2.4 GB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 705630  bytes 93740106 (93.7 MB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    device interrupt 21  memory 0xf7fe0000-f8000000  

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 132569  bytes 44162247 (44.1 MB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 132569  bytes 44162247 (44.1 MB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0 

这是/etc/network/interfaces主持人的

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

auto eno1
iface eno1 inet static
address 130.15.1.72
netmask 255.255.255.0
network 130.15.1.0
broadcast 130.15.1.255
gateway 130.15.1.1

在 Virtualbox 网络设置中,我设置了仅主机网络,其vboxnet0设置如下:

IP4 Address: 192.168.56.0
IP4 Network Mask: 255.255.255.0  

并且 DHCP 已禁用

现在我在虚拟机设置中:

Adapter 1: Host only network - vboxnet0
Adapter 2: NAT

ls /sys/class/net这是我在客户机上运行时的输出

enp0s3 enp0s8 低

这是ifconfig客户机的

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.101  netmask 255.255.255.0  broadcast 192.168.56.255
        inet6 fe80::a00:27ff:fefd:775c  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:fd:77:5c  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 87  bytes 9096 (9.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.3.15  netmask 255.255.255.0  broadcast 10.0.3.255
        inet6 fe80::a00:27ff:fef3:976  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:f3:09:76  txqueuelen 1000  (Ethernet)
        RX packets 14384  bytes 13692205 (13.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6941  bytes 749919 (749.9 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 348  bytes 25732 (25.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 348  bytes 25732 (25.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

这就是/etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

# The host-only network interface
auto enp0s3
iface enp0s3 inet static
address 192.168.56.101
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255

# NAT interface
auto enp0s8
iface enp0s8 inet dhcp

我正在尝试 ping 以确保连接已建立。客户机似乎能够成功 ping 主机 (130.15.1.72)。但是,主机只能 ping 192.168.56.0(这只是 vboxnet0 的广播地址),而 ping 192.168.56.101 则挂起,没有任何输出。此外,当我尝试从主机 SSH 时,我只得到

正在尝试 192.168.56.101...

当我尝试从客户机使用 SSH 时,出现连接被拒绝错误。

请帮助我,让我知道我做错了什么。我确信这是 IP 地址的问题,因为设置起来让我很困惑。

谢谢

答案1

经过几天的不断研究和反复试验,我终于解决了这个问题,我简直不敢相信它是如此简单......

我的问题通过简单地将 virtualbox 更新到最新版本就解决了!我只需运行

sudo apt-get update && sudo apt-get upgrade

在运行此命令之前,应关闭 VirtualBox,否则显然无法更新。在此之后,我只需重新启动主机即可!我的电脑ifconfig自动修复以显示新界面(vboxnet0),这是我以前从未见过的:

eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 130.15.1.72  netmask 255.255.255.0  broadcast 130.15.1.255
        inet6 fe80::862b:2bff:fea2:f0d2  prefixlen 64  scopeid 0x20<link>
        ether 84:2b:2b:a2:f0:d2  txqueuelen 1000  (Ethernet)
        RX packets 45609  bytes 25862185 (25.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16778  bytes 2427180 (2.4 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 21  memory 0xf7fe0000-f8000000  

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 1222  bytes 239666 (239.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1222  bytes 239666 (239.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vboxnet0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.56.1  netmask 255.255.255.0  broadcast 192.168.56.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 608  bytes 60421 (60.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:43:82:ee  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

现在我只需启动客户机,果然,我终于能够来回 ping 通 :) 不过,我犯了一个错误,我认为应该使用 (130.15.1.72) 来 ping 主机。这是错误的;客户机应该使用在 virtualbox 网络设置中设置 vboxnet0 的地址与主机通信。因此,我将 vboxnet0 设置如下:

IP4 Address: 192.168.56.1
IP4 Network Mask: 255.255.255.0

所有其他设置都与我之前的帖子没有分支。现在我可以通过以下方式从客户机 ping 主机:

ping 192.168.56.1 

我可以通过运行以下命令来 ping 访客

ping 192.168.56.101

或者无论他们的静态 IP 设置为多少。

希望这能帮助到那些遇到这个问题的人,这真的很令人沮丧!

感谢所有阅读我帖子的人

相关内容