尝试在 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 设置为多少。

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

感谢所有阅读我帖子的人

答案2

wlp0s20f3: flags = 4099 <UP, BROADCAST, MULTICAST> 

我已经成功使用以下命令针对 mtu 1500 解决方案并且它运行完美。


sudo add-apt-repository ppa:canonical-hwe-team/backport-iwlwifi
cd backport-iwlwifi/

sudo add-apt-repository ppa:canonical

sudo add-apt-repository ppa:canonical-hwe-team

sudo apt-get update sudo apt-get install backport-iwlwifi-dkms

sudo apt-get install backport-iwlwifi-dkms
  

  

sudo apt-get remove backport-iwlwifi-dkms
cat /etc/apt/sources.list

   

 

iwconfig

dmesg | grep iwl

git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/firmware/linux-firmware

   

 cd linux-firmware/

  

  

make

sudo modprobe iwlwifi
  

  

sudo modprobe iwl4965

sudo rmmod iwlmvm iwlwifi

sudo make install
   

sudo make
cat /etc/apt/sources.list

sudo apt-get dist-upgrade
   

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5
   

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
sudo apt-get update 

lsb-release -id && uname -a
  

sudo nano /etc/apt/sources.list
sudo apt install git build-essential

git clone https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/backport-iwlwifi.git
cd backport-iwlwifi/
  

make defconfig-iwlwifi-public  

 

sed -i 's/CPTCFG_IWLMVM_VENDOR_CMDS=y/# CPTCFG_IWLMVM_VENDOR_CMDS is not set/' .config
 

make -j4
  

sudo make install
   

sudo modprobe iwlwifi
   

reboot
 

lspci | grep -i wireless

lsusb 
  

sudo apt-get update 
sudo apt-get upgrade 
  

sudo apt-get install wireless-tools 
   

sudo apt-get install  inxi wicd 
ls
 

ifconfig
   

lsusb
   

macchanger wlan0 --show
   

sudo apt-get install macchanger 
   

macchanger wlan0 --show
 

       iwlist eth1 scan
        sudo apt-get --reinstall git dkms build-essential linu-headers -$(uname -r)
    git clone

     https://kernel.googlesource.com/pub/scm/linux/kernel/git/firmware/linux-firmware

    
    cd linux-firmware/



   

     ls
  

      make
sudo modprobe iwl4965
   

     sudo make install   

 

    sed -i 's/CPTCFG_IWLMVM_VENDOR_CMDS=y/# CPTCFG_IWLMVM_VENDOR_CMDS is not set/' .config
make defconfig-iwlwifi-public

sudo make install
   

sudo modprobe iwlwifi
sudo apt-get install network-manager

sudo apt-get install network-manager-gnome

sudo apt-get install wireless-tools
   

ifconfig
   

sudo apt-get install wicd
sudo dmesg | grep iwl

sudo dmesg 

sudo apt install git build-essential
  

git clone https://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/backport-iwlwifi.git
cd backport-iwlwifi/
  

ls
   

make defconfig-iwlwifi-public
   

sudo apt-get install make
   

make defconfig-iwlwifi-public
   

sudo apt-get install linux-headers-$(uname -r)
   

make defconfig-iwlwifi-public

  

sed -i 's/CPTCFG_IWLMVM_VENDOR_CMDS=y/# CPTCFG_IWLMVM_VENDOR_CMDS is not set/' .config
  

make -j4
   

sudo make install
   

cd
   

sudo make install
  

sudo modprobe iwlwifi
   

reboot
  

ifconfig

**2 ethernet outputs are observed after this command.**

 - lokman@pardus:~$ `ifconfig` > enp16s0:
   flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 > inet
   10.214.0.46 netmask 255.255.0.0 broadcast 10.214.255.255 > inet6 fe80::dac4:97ff:fef6:c3e9 prefixlen 64 scopeid 0x20<link> > ether
   d8:c4:97:f6:c3:e9 txqueuelen 1000 (Ethernet) > RX packets 23225 bytes
   32615000 (31.1 MiB) > RX errors 0 dropped 0 overruns 0 frame 0 > TX
   packets 10007 bytes 680944 (664.9 KiB) > 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 1 (Local Loopback) > RX packets 168 bytes 13356 (13.0 KiB)
   > RX errors 0 dropped 0 overruns 0 frame 0 > TX packets 168 bytes 13356 (13.0 KiB) > TX errors 0 dropped 0 overruns 0 carrier 0
   collisions 0 > > wlp0s20f3: flags=4099<UP,BROADCAST,MULTICAST> mtu
   1500 > ether ea:de:cd:29:d5:00 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

在此处输入图片描述

相关内容