准备工作

1.以管理员身份打开 PowerShell ,然后在 PowerShell中输入以下命令 Get-VM 查看当前系统有哪些虚拟机:

PS C:\Windows\system32> Get-VM

Name State CPUUsage(%) MemoryAssigned(M) Uptime Status Version
---- ----- ----------- ----------------- ------ ------ -------
Debian12-001 Running 0 4096 00:50:09.9080000 正常运行 11.0
PVE-8.1-001 Off 0 0 00:00:00 正常运行 11.0
PVE-8.1-002 Off 0 0 00:00:00 正常运行 11.0
ubuntu2204-001 Off 0 0 00:00:00 正常运行 11.0

2.关闭要设置嵌套虚拟化的虚拟机,比如我这里要为 Debian12-001 这台虚拟机开启嵌套虚拟化(必要步骤,否则后面操作会失败):

# 关闭指定虚拟机命令:
PS C:\Windows\system32> Stop-VM Debian12-001


# 启动指定虚拟机命令:
# PS C:\Windows\system32> Start-VM Debian12-001

# 再次查看虚拟机状态
PS C:\Windows\system32> get-vm Debian12-001

Name State CPUUsage(%) MemoryAssigned(M) Uptime Status Version
---- ----- ----------- ----------------- ------ ------ -------
Debian12-001 Off 0 0 00:00:00 正常运行 11.0

开启虚拟机嵌套虚拟化及网络混杂功能

开启虚拟机嵌套虚拟化

1.接着运行 PS C:\Windows\system32> Set-VMProcessor -ExposeVirtualizationExtensions $true -VMName Debian12-001:

PS C:\Windows\system32> Set-VMProcessor -ExposeVirtualizationExtensions $true -VMName Debian12-001

开启后,可以执行命令 Get-VMProcessor -VMName Debian12-001 | fl 查看:

PS C:\Windows\system32> Get-VMProcessor -VMName Debian12-001 | fl


ResourcePoolName : Primordial
Count : 4
CompatibilityForMigrationEnabled : False
CompatibilityForMigrationMode : MinimumFeatureSet
CompatibilityForOlderOperatingSystemsEnabled : False
HwThreadCountPerCore : 0
ExposeVirtualizationExtensions : True
EnablePerfmonPmu : False
EnablePerfmonArchPmu : False
EnablePerfmonLbr : False
EnablePerfmonPebs : False
EnablePerfmonIpt : False
EnableLegacyApicMode : False
ApicMode : Default
AllowACountMCount : True
CpuBrandString :
PerfCpuFreqCapMhz : 0
L3CacheWays : 0
Maximum : 100
Reserve : 0
RelativeWeight : 100
MaximumCountPerNumaNode : 8
MaximumCountPerNumaSocket : 1
EnableHostResourceProtection : False
OperationalStatus : {}
StatusDescription : {}
Name : 处理器
Id : Microsoft:C450DFAB-55D8-436C-B713-6E0C4B2A9CEC\b637f346-6a0e-4dec-af52-bd70cb80a21d\0
VMId : c450dfab-55d8-436c-b713-6e0c4b2a9cec
VMName : Debian12-001
VMSnapshotId : 00000000-0000-0000-0000-000000000000
VMSnapshotName :
CimSession : CimSession: .
ComputerName : VEAZHI
IsDeleted : False
VMCheckpointId : 00000000-0000-0000-0000-000000000000
VMCheckpointName :

开启虚拟机网络混杂功能

1.先执行命令 get-vm -Name Debian12-001 | Get-VMNetworkAdapter 获取虚拟机的 MAC 地址:

PS C:\Windows\system32> get-vm -Name Debian12-001 | Get-VMNetworkAdapter

Name IsManagementOs VMName SwitchName MacAddress Status IPAddresses
---- -------------- ------ ---------- ---------- ------ -----------
网络适配器 False Debian12-001 Lan 00155D037303 {}

2.再次执行命令 PS C:\Windows\system32> Get-VM -Name Debian12-001 | Get-VMNetworkAdapter | Where-Object { $_.MacAddress -eq "00155D037303" } | Set-VMNetworkAdapter -MacAddressSpoofing On 启用该虚拟机的网络混杂功能:

PS C:\Windows\system32> Get-VM -Name Debian12-001 | Get-VMNetworkAdapter | Where-Object { $_.MacAddress -eq "00155D037303" } | Set-VMNetworkAdapter -MacAddressSpoofing On

3.最后,启动虚拟机:

PS C:\Windows\system32> Start-VM Debian12-001

至此,虚拟机的嵌套虚拟化和网络混杂功能都已成功开启!