这篇博文的背景是,需要在 Hyper-V 中安装 PVE,涉及到嵌套虚拟化的问题。

如果有空,改天总结一下在 Hyper-V 中安装 PVE 的流程。

参考资料

尤其注意 MAC Address Sproofing: 由于 Hyper-V 默认有 MAC 地址的验证,所以嵌套虚拟化出的 VM(PVE 中的虚拟机),无法正常连接网络。所以需要启用 MAC Address Sproofing。

全过程命令

  1. 新建虚拟交换机:

    New-VMSwitch -SwitchName "SwitchName" -SwitchType Internal
  2. 配置 NAT 网关:

    Get-NetAdapter
    New-NetIPAddress -IPAddress <NAT Gateway IP> -PrefixLength <NAT Subnet Prefix Length> -InterfaceIndex <ifIndex>
  3. 配置 NAT 网络:

    New-NetNat -Name <NATOutsideName> -InternalIPInterfaceAddressPrefix <NAT subnet prefix>
  4. 创建虚拟机,略(注意选择刚刚创建好的 Switch)。
  5. 为嵌套虚拟化出的 VM 启用 MAC Sproofing。

    Get-VMNetworkAdapter -VMName <VMName> | Set-VMNetworkAdapter -MacAddressSpoofing On