如何让Hyper-V检测到我的Ubuntu虚拟机的IP地址

17

今天我刚刚从Ubuntu.com下载了一个新的ISO镜像,把它安装到了一台新机器上。网络连接很好,但是IP地址没有被Hyper-V管理器检测到。我正在尝试为Vagrant创建一个基础虚拟机盒子,因此我需要网络连接实际上报告IP地址。

pingifconfiglsmod的控制台输出:

root@trusty-tahr:~# ping -c 4 stackoverflow.com
PING stackoverflow.com (198.252.206.16) 56(84) bytes of data.
64 bytes from stackoverflow.com (198.252.206.16): icmp_seq=1 ttl=54 time=49.3 ms
64 bytes from stackoverflow.com (198.252.206.16): icmp_seq=2 ttl=54 time=50.2 ms
64 bytes from stackoverflow.com (198.252.206.16): icmp_seq=3 ttl=54 time=48.7 ms
64 bytes from stackoverflow.com (198.252.206.16): icmp_seq=4 ttl=54 time=49.8 ms

--- stackoverflow.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 48.726/49.536/50.216/0.623 ms
root@trusty-tahr:~# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:15:5d:01:98:41
          inet addr:192.168.1.186  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::215:5dff:fe01:9841/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:530 errors:0 dropped:0 overruns:0 frame:0
          TX packets:252 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:83564 (83.5 KB)  TX bytes:33034 (33.0 KB)

root@trusty-tahr:~# lsmod
Module                  Size  Used by
joydev                 20480  0
hid_generic            16384  0
iosf_mbi               16384  0
crct10dif_pclmul       16384  0
crc32_pclmul           16384  0
ghash_clmulni_intel    16384  0
aesni_intel           172032  0
aes_x86_64             20480  1 aesni_intel
lrw                    16384  1 aesni_intel
gf128mul               16384  1 lrw
glue_helper            16384  1 aesni_intel
ablk_helper            16384  1 aesni_intel
cryptd                 20480  3 ghash_clmulni_intel,aesni_intel,ablk_helper
serio_raw              16384  0
hid_hyperv             16384  0
hid                   110592  2 hid_hyperv,hid_generic
hyperv_keyboard        16384  0
hv_balloon             24576  0
8250_fintek            16384  0
hyperv_fb              20480  1
i2c_piix4              24576  0
mac_hid                16384  0
lp                     20480  0
parport                45056  1 lp
hv_netvsc              36864  0
hv_utils               20480  0
hv_storvsc             20480  2
psmouse               114688  0
floppy                 77824  0
hv_vmbus               61440  8 hv_balloon,hyperv_keyboard,hv_netvsc,hid_hyperv,hv_utils,hyperv_fb,hv_storvsc
pata_acpi              16384  0
root@trusty-tahr:~#

Hyper-V管理器中的网络选项卡:

Hyper-V网络选项卡

这是在Windows 10专业版上。


根据此链接 https://social.technet.microsoft.com/Forums/en-US/8ea16b25-6ede-49f7-a70e-7aa79f02f9cb/hyperv-ubuntu-1504-server-vm-not-reporting-an-ip-address-but-has-network-access?forum=linuxintegrationservices,似乎与linux-cloud-tools-virtual中的kvp守护程序有关。 - John P Bloch
4个回答

34

好的,我解决了这个问题。

简短版:

sudo apt-get install "linux-cloud-tools-$(uname -r)"

通常情况下,您需要安装linux-cloud-tools-virtual才能安装KVP守护程序。不幸的是,Ubuntu 14.04.3附带的内核版本为3.19.0-25-generic,而linux-cloud-tools-virtual安装的是适用于3.13.0-65-generic的云工具。因此,您需要安装适用于您内核发布版本的云工具。要自动执行此操作,请使用上面介绍的uname -r获取版本信息。

希望这可以帮助到某个地方的某个人。


这在16.04版本中对我来说完美运行,但在17.10版本中却不起作用。 - Taegost
这在我的Windows 10企业版主机上的Ubuntu 18.04.1 LTS客户机中有效。不带“引号”。sudo apt-get install linux-cloud-tools-$(uname -r) - nickedeye
它对我有用,Deepin Linux。终于我可以通过ssh登录到我的虚拟机,而不需要连接并ifconfig检查IP地址。谢谢! - valleygtc
如果您安装了与您的确切内核版本相对应的软件包,那么当内核更新时,它是否会过时,或者apt是否会使它们保持最新状态? - mwfearnley

7

看起来对于18.10版本,需要再次使用sudo apt install linux-cloud-tools-virtual


1
此软件包名称截至20.04仍然有效。 - Scott P.
在重新启动后,这对我在22.04中起作用了。 - mwfearnley

2
对于我的Ubuntu 20.04,我遵循了这篇针对Ubuntu 18.04的指南。从问题中的lsmod输出可以看出,他不需要第一步,但我想发布一个更完整的指南。
首先使用nano编辑modules文件以添加其他模块:
    sudo nano /etc/initramfs-tools/modules

并添加以下几行:

    hv_vmbus
    hv_storvsc
    hv_blkvsc
    hv_netvsc

现在安装虚拟工具,更新initramfs模块并重新启动:
    sudo apt-get install linux-virtual linux-cloud-tools-virtual linux-tools-virtual
    sudo update-initramfs -u
    sudo reboot

1
在20.04中,我只需要执行apt install命令并重新启动即可。 - mwfearnley

2
在Ubuntu 22.04服务器上,(类似于@mwfearnley在https://dev59.com/MVwY5IYBdhLWcg3wFkej#67481445的评论中所述),我只需要:
sudo apt install -y \
  linux-virtual \
  linux-cloud-tools-virtual \
  linux-tools-virtual

sudo reboot now

这在Ubuntu Studio 22.04 LTS对我来说行不通。我已经尝试了所有可能的方法,但无法在Hyper-V管理器中显示虚拟机的IP地址,也无法通过PowerShell中的Get-VMNetworkAdapter命令获取。我现在真是急得要抓狂了。 - Trevor Sullivan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接