如何让 Hyper V 检测我的 Ubuntu VM 的 IP 地址

How can I get Hyper V to detect my Ubuntu VM's IP Address

我今天刚刚安装了从Ubuntu.com下载的新ISO,刚安装到一台新机器上。网络工作正常,但 Hyper-V 管理器未获取 IP 地址。我正在尝试为 vagrant 制作一个基本盒子,所以我需要联网才能实际报告 IP 地址。

pingifconfiglsmod 的控制台输出:

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

--- whosebug.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 管理器中的网络选项卡:

这是 Windows 10 Professional

好的,我想通了。

tl;dr版本:

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 获取您的 relase 版本,如上所述。

希望对沿线某个地方的人有所帮助。

似乎 18.10 又需要 sudo apt install linux-cloud-tools-virtual

为了我的Ubuntu 20.04,我关注了this guide for Ubuntu 18.04。我可以从问题的 lsmod 输出中看出,他不需要第一步,但我想要 post 更完整的指南。

首先编辑 modules 文件(使用 nano)以添加其他模块:

    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