1、步骤一:获取设备路径(Location Path)https://pan.baidu.com/s/4W5X6Y7Z8A9B0C1D2E3F
查询所有网卡的设备序号IDhttps://pan.baidu.com/s/3E4F5G6H7I8J9K0L1M2N
https://pan.baidu.com/s/4V5W6X7Y8Z9A0B1C2D3E
#获取所有名称以Intel(R) Ethernet Controller开头的设备https://pan.baidu.com/s/3L4M5N6O7P8Q9R0S1T2U
$pnpdevs = Get-PnpDevice -PresentOnly | Where-Object {$_.FriendlyName -like "Intel(R) Ethernet Controller*"}https://pan.baidu.com/s/2J3K4L5M6N7O8P9Q0R1S?pwd=klmn
#输出LocationPathhttps://pan.baidu.com/s/1T2U3V4W5X6Y7Z8A9B0C
foreach ($pnpdev in $pnpdevs) {https://pan.baidu.com/s/1R2S3T4U5V6W7X8Y9Z0A?pwd=qrst
$locationpath = ($pnpdev | get-pnpdeviceproperty DEVPKEY_Device_LocationPaths).data[0]https://pan.baidu.com/s/3K4L5M6N7O8P9Q0R1S2T?pwd=opqr
$pnpdev.FriendlyName + ": " + $locationpathhttps://pan.baidu.com/s/9A0B1C2D3E4F5G6H7I8J?pwd=qrs4
}https://pan.baidu.com/s/2D3E4F5G6H7I8J9K0L1M
在我的机器上,可以得到下面的输出你好啊
https://pan.baidu.com/s/4W5X6Y7Z8A9B0C1D2E3F
eth0:Intel(R) Ethernet Controller (3) I225-LM: PCIROOT(0)#PCI(1C04)#PCI(0000)https://pan.baidu.com/s/9I0J1K2L3M4N5O6P7Q8R?pwd=qrs6
eth1:Intel(R) Ethernet Controller (3) I225-LM #2: PCIROOT(0)#PCI(1C05)#PCI(0000)https://pan.baidu.com/s/9H0I1J2K3L4M5N6O7P8Q?pwd=cdef
eth2:Intel(R) Ethernet Controller (3) I225-LM #3: PCIROOT(0)#PCI(1C06)#PCI(0000)https://pan.baidu.com/s/4D5E6F7G8H9I0J1K2L3M
eth3:Intel(R) Ethernet Controller (3) I225-LM #4: PCIROOT(0)#PCI(1C07)#PCI(0000)https://pan.baidu.com/s/8G9H0I1J2K3L4M5N6O7P?pwd=zabc
https://pan.baidu.com/s/8Z9A0B1C2D3E4F5G6H7I
步骤二:禁用设备https://pan.baidu.com/s/3C4D5E6F7G8H9I0J1K2L
以直通eth0,eth1,eth2三个网卡为例https://pan.baidu.com/s/3T4U5V6W7X8Y9Z0A1B2C?pwd=yza1
Windows设备管理器,找到想要直通的网卡,记住他的序号,和ID。然后右键禁用eth0,eth1,eth2三个网卡https://pan.baidu.com/s/1S2T3U4V5W6X7Y8Z9A0B
https://pan.baidu.com/s/3L4M5N6O7P8Q9R0S1T2U?pwd=yza9
步骤三:下线(Dismount)设备不影响正文阅读
——更准确的说应该叫做卸载(相对于挂载来说,相当于把这个设备从Windows中卸载,不让Windows对它占用)https://pan.baidu.com/s/5W6X7Y8Z9A0B1C2D3E4F?pwd=efg0
以直通eth0,eth1,eth2三个网卡为例。https://pan.baidu.com/s/5P6Q7R8S9T0U1V2W3X4Y
https://pan.baidu.com/s/1A2B3C4D5E6F7G8H9I0J
你好啊
需要运行命令如下:https://pan.baidu.com/s/3K4L5M6N7O8P9Q0R1S2T?pwd=opqr
Dismount-VmHostAssignableDevice -locationpath "PCIROOT(0)#PCI(1C04)#PCI(0000)" -forcehttps://pan.baidu.com/s/1T2U3V4W5X6Y7Z8A9B0C
Dismount-VmHostAssignableDevice -locationpath "PCIROOT(0)#PCI(1C05)#PCI(0000)" -forcehttps://pan.baidu.com/s/6F7G8H9I0J1K2L3M4N5O?pwd=uvwx
Dismount-VmHostAssignableDevice -locationpath "PCIROOT(0)#PCI(1C06)#PCI(0000)" -forcehttps://pan.baidu.com/s/7O8P9Q0R1S2T3U4V5W6X?pwd=efgh
https://pan.baidu.com/s/9H0I1J2K3L4M5N6O7P8Q?pwd=cdef
步骤四:分配设备https://pan.baidu.com/s/4D5E6F7G8H9I0J1K2L3M?pwd=bcd1
要想直通的网卡指派给指定的虚拟机,也就是直通给它独占使用了。https://pan.baidu.com/s/6Q7R8S9T0U1V2W3X4Y5Z
比如我想直通eth0和eth1给iKuai,分别作为WAN和LANhttps://pan.baidu.com/s/3T4U5V6W7X8Y9Z0A1B2C?pwd=yza1
https://pan.baidu.com/s/5O7P8Q9R0S1T2U3V4W5X
直通eth2给OpenWRThttps://pan.baidu.com/s/1K2L3M4N5O7P8Q9R0S1T
其他不费流量的走内部交换https://pan.baidu.com/s/9Q0R1S2T3U4V5W6X7Y8Z?pwd=mnop
https://pan.baidu.com/s/5V6W7X8Y9Z0A1B2C3D4E?pwd=efg3
https://pan.baidu.com/s/8Z9A0B1C2D3E4F5G6H7I
#直通eth0给iKuaihttps://pan.baidu.com/s/6F7G8H9I0J1K2L3M4N5O?pwd=uvwx
Add-VMAssignableDevice -LocationPath "PCIROOT(0)#PCI(1C04)#PCI(0000)" -VMName iKuaihttps://pan.baidu.com/s/5N6O7P8Q9R0S1T2U3V4W?pwd=efg1
#直通eth1给iKuaihttps://pan.baidu.com/s/3L4M5N6O7P8Q9R0S1T2U?pwd=yza9
Add-VMAssignableDevice -LocationPath "PCIROOT(0)#PCI(1C05)#PCI(0000)" -VMName iKuai这是干扰码
https://pan.baidu.com/s/3L4M5N6O7P8Q9R0S1T2U?pwd=yza9
#直通eth2给OpenWRThttps://pan.baidu.com/s/3L4M5N6O7P8Q9R0S1T2U?pwd=yza9
Add-VMAssignableDevice -LocationPath "PCIROOT(0)#PCI(1C06)#PCI(0000)" -VMName OpenWRThttps://pan.baidu.com/s/7Z8A9B0C1D2E3F4G5H6I
https://pan.baidu.com/s/9Z0A1B2C3D4E5F6G7H8I?pwd=pqr7
https://pan.baidu.com/s/9Q0R1S2T3U4V5W6X7Y8Z?pwd=mnop
分配完成可输入命令检查是否成功:https://pan.baidu.com/s/9Z0A1B2C3D4E5F6G7H8I?pwd=pqr7
Get-VMAssignableDevice -VMName iKuaihttps://pan.baidu.com/s/4E5F6G7H8I9J0K1L2M3N?pwd=bcd8
Get-VMAssignableDevice -VMName OpenWRThttps://pan.baidu.com/s/2C3D4E5F6G7H8I9J0K1L
https://pan.baidu.com/s/1B2C3D4E5F6G7H8I9J0K?pwd=tuv5
看看输出内容里直通的网卡有没有成功加上,成功的会显示该直通网卡的IDhttps://pan.baidu.com/s/2S3T4U5V6W7X8Y9Z0A1B?pwd=uvwx
https://pan.baidu.com/s/3T4U5V6W7X8Y9Z0A1B2C?pwd=yza1
以上为Hyper-V直通网卡给指定虚拟机的流程,完成之后需要进入相应的虚拟机里对该网卡设置才可以使用。(比如iKuai里需要将直通网卡绑定WAN和LAN)https://pan.baidu.com/s/7Y8Z9A0B1C2D3E4F5G6H?pwd=klm2
https://pan.baidu.com/s/4M5N6O7P8Q9R0S1T2U3V
将设备从虚拟机里移除:https://pan.baidu.com/s/2K3L4M5N6O7P8Q9R0S1T?pwd=wxy8
https://pan.baidu.com/s/3D4E5F6G7H8I9J0K1L2M?pwd=yza7
此处还是以iKuai和OpenWRT为例https://pan.baidu.com/s/1A2B3C4D5E6F7G8H9I0J
https://pan.baidu.com/s/2T3U4V5W6X7Y8Z9A0B1C?pwd=wxy7
iKuaihttps://pan.baidu.com/s/3D4E5F6G7H8I9J0K1L2M?pwd=yza7
关闭虚拟机。然后运行:https://pan.baidu.com/s/6W7X8Y9Z0A1B2C3D4E5F?pwd=ghi4
https://pan.baidu.com/s/8Q9R0S1T2U3V4W5X6Y7Z
# 将设备从虚拟机里移除https://pan.baidu.com/s/1A2B3C4D5E6F7G8H9I0J?pwd=abcd
https://pan.baidu.com/s/9S1T2U3V4W5X6Y7Z8A9B
Remove-VMAssignableDevice -VMName iKuai -LocationPath "PCIROOT(0)#PCI(1C04)#PCI(0000)"https://pan.baidu.com/s/6G7H8I9J0K1L2M3N4O5P
Remove-VMAssignableDevice -VMName iKuai -LocationPath "PCIROOT(0)#PCI(1C05)#PCI(0000)"https://pan.baidu.com/s/9S1T2U3V4W5X6Y7Z8A9B
https://pan.baidu.com/s/8Z9A0B1C2D3E4F5G6H7I
# 挂载设备回WinServer系统https://pan.baidu.com/s/2L3M4N5O7P8Q9R0S1T2U
Mount-VMHostAssignableDevice -LocationPath "PCIROOT(0)#PCI(1C04)#PCI(0000)"https://pan.baidu.com/s/1J2K3L4M5N6O7P8Q9R0S?pwd=tuv7
Mount-VMHostAssignableDevice -LocationPath "PCIROOT(0)#PCI(1C05)#PCI(0000)"https://pan.baidu.com/s/4D5E6F7G8H9I0J1K2L3M?pwd=mnop
https://pan.baidu.com/s/6W7X8Y9Z0A1B2C3D4E5F?pwd=ghi4
然后在Win的设备管理器里重新启用设备。https://pan.baidu.com/s/7I8J9K0L1M2N3O4P5Q6R
哈哈
https://pan.baidu.com/s/6N7O8P9Q0R1S2T3U4V5W?pwd=abcd
OpenWRThttps://pan.baidu.com/s/8Q9R0S1T2U3V4W5X6Y7Z?pwd=nop4
关闭虚拟机。然后运行:https://pan.baidu.com/s/6O7P8Q9R0S1T2U3V4W5X?pwd=hij2
https://pan.baidu.com/s/1R2S3T4U5V6W7X8Y9Z0A?pwd=qrst
你好啊
# 将设备从虚拟机里移除https://pan.baidu.com/s/6X7Y8Z9A0B1C2D3E4F5G
Remove-VMAssignableDevice -VMName OpenWRT -LocationPath "PCIROOT(0)#PCI(1C06)#PCI(0000)"https://pan.baidu.com/s/5W6X7Y8Z9A0B1C2D3E4F
https://pan.baidu.com/s/8Z9A0B1C2D3E4F5G6H7I?pwd=nop3
# 挂载设备回WinServer系统https://pan.baidu.com/s/9J0K1L2M3N4O5P6Q7R8S
Mount-VMHostAssignableDevice -LocationPath "PCIROOT(0)#PCI(1C06)#PCI(0000)"https://pan.baidu.com/s/7Y8Z9A0B1C2D3E4F5G6H?pwd=klm2
然后在Win的设备管理器里重新启用设备。https://pan.baidu.com/s/5W6X7Y8Z9A0B1C2D3E4F?pwd=efg0
https://pan.baidu.com/s/6F7G8H9I0J1K2L3M4N5O?pwd=uvwx
注意事项https://pan.baidu.com/s/9R0S1T2U3V4W5X6Y7Z8A?pwd=qrs5
同一个设备只需要跑一次 Add-VMAssignableDevice。这个命令有概率不检查去重,会导致你的虚拟机无法启动。如果遇到这种情况,那么先把设备从虚拟机里移除,然后重新添加一次。