搜索
查看: 1178|回复: 0
收起左侧

[虚拟机] Hyper直通网卡流程

[复制链接]
admin 发表于 2022-7-16 09:17:16 | 显示全部楼层 |阅读模式
1、步骤一:获取设备路径(Location Path)

https://pan.baidu.com/s/7X8Y9Z0A1B2C3D4E5F6G?pwd=jkl5 https://pan.baidu.com/s/1J2K3L4M5N6O7P8Q9R0S

查询所有网卡的设备序号ID

https://pan.baidu.com/s/4M5N6O7P8Q9R0S1T2U3V?pwd=bcd0 https://pan.baidu.com/s/8H9I0J1K2L3M4N5O6P7Q

https://pan.baidu.com/s/6F7G8H9I0J1K2L3M4N5O
#获取所有名称以Intel(R) Ethernet Controller开头的设备https://pan.baidu.com/s/6F7G8H9I0J1K2L3M4N5O?pwd=hij3 $pnpdevs = Get-PnpDevice -PresentOnly | Where-Object {$_.FriendlyName -like "Intel(R) Ethernet Controller*"}
https://pan.baidu.com/s/6F7G8H9I0J1K2L3M4N5O?pwd=uvwx
#输出LocationPath
  • https://pan.baidu.com/s/6N7O8P9Q0R1S2T3U4V5W?pwd=abcd
  • foreach ($pnpdev in $pnpdevs) {

    https://pan.baidu.com/s/7H8I9J0K1L2M3N4O5P6Q?pwd=klm1https://pan.baidu.com/s/5V6W7X8Y9Z0A1B2C3D4E?pwd=efg3

           $locationpath = ($pnpdev | get-pnpdeviceproperty DEVPKEY_Device_LocationPaths).data[0]https://pan.baidu.com/s/3C4D5E6F7G8H9I0J1K2L?pwd=yza0        $pnpdev.FriendlyName + ": " + $locationpath
    https://pan.baidu.com/s/6W7X8Y9Z0A1B2C3D4E5F?pwd=ghi4
    }https://pan.baidu.com/s/1A2B3C4D5E6F7G8H9I0J?pwd=stu8 在我的机器上,可以得到下面的输出
  • https://pan.baidu.com/s/5G6H7I8J9K0L1M2N3O4P
  • https://pan.baidu.com/s/9R0S1T2U3V4W5X6Y7Z8A?pwd=qrs5
    eth0:Intel(R) Ethernet Controller (3) I225-LM: PCIROOT(0)#PCI(1C04)#PCI(0000)https://pan.baidu.com/s/6W7X8Y9Z0A1B2C3D4E5F?pwd=ghi4 eth1:Intel(R) Ethernet Controller (3) I225-LM #2: PCIROOT(0)#PCI(1C05)#PCI(0000)https://pan.baidu.com/s/7Z8A9B0C1D2E3F4G5H6I eth2:Intel(R) Ethernet Controller (3) I225-LM #3: PCIROOT(0)#PCI(1C06)#PCI(0000)
    https://pan.baidu.com/s/9K0L1M2N3O4P5Q6R7S8T
    eth3:Intel(R) Ethernet Controller (3) I225-LM #4: PCIROOT(0)#PCI(1C07)#PCI(0000)https://pan.baidu.com/s/7H8I9J0K1L2M3N4O5P6Q
  • https://pan.baidu.com/s/7Y8Z9A0B1C2D3E4F5G6H?pwd=klm2
  • 步骤二:禁用设备https://pan.baidu.com/s/9H0I1J2K3L4M5N6O7P8Q?pwd=cdef 以直通eth0,eth1,eth2三个网卡为例https://pan.baidu.com/s/2K3L4M5N6O7P8Q9R0S1T?pwd=wxy8 Windows设备管理器,找到想要直通的网卡,记住他的序号,和ID。然后右键禁用eth0,eth1,eth2三个网卡https://pan.baidu.com/s/8Q9R0S1T2U3V4W5X6Y7Z?pwd=nop4 https://pan.baidu.com/s/8G9H0I1J2K3L4M5N6O7P?pwd=zabc 步骤三:下线(Dismount)设备https://pan.baidu.com/s/6G7H8I9J0K1L2M3N4O5P?pwd=hij0 ——更准确的说应该叫做卸载(相对于挂载来说,相当于把这个设备从Windows中卸载,不让Windows对它占用)https://pan.baidu.com/s/8H9I0J1K2L3M4N5O6P7Q 以直通eth0,eth1,eth2三个网卡为例。

    https://pan.baidu.com/s/2B3C4D5E6F7G8H9I0J1K https://pan.baidu.com/s/6H7I8J9K0L1M2N3O4P5Q

    https://pan.baidu.com/s/4D5E6F7G8H9I0J1K2L3M?pwd=mnop 需要运行命令如下:
    https://pan.baidu.com/s/2L3M4N5O7P8Q9R0S1T2U
    Dismount-VmHostAssignableDevice -locationpath "PCIROOT(0)#PCI(1C04)#PCI(0000)" -force

    https://pan.baidu.com/s/9I0J1K2L3M4N5O6P7Q8R?pwd=qrs6 https://pan.baidu.com/s/6O7P8Q9R0S1T2U3V4W5X?pwd=hij2

    Dismount-VmHostAssignableDevice -locationpath "PCIROOT(0)#PCI(1C05)#PCI(0000)" -forcehttps://pan.baidu.com/s/1C2D3E4F5G6H7I8J9K0L Dismount-VmHostAssignableDevice -locationpath "PCIROOT(0)#PCI(1C06)#PCI(0000)" -forcehttps://pan.baidu.com/s/9Z0A1B2C3D4E5F6G7H8I?pwd=pqr7 这是干扰码 步骤四:分配设备https://pan.baidu.com/s/6F7G8H9I0J1K2L3M4N5O?pwd=hij3 要想直通的网卡指派给指定的虚拟机,也就是直通给它独占使用了。
    https://pan.baidu.com/s/7P8Q9R0S1T2U3V4W5X6Y?pwd=klm3
    比如我想直通eth0和eth1给iKuai,分别作为WAN和LANhttps://pan.baidu.com/s/3C4D5E6F7G8H9I0J1K2L?pwd=ijkl 直通eth2给OpenWRThttps://pan.baidu.com/s/3L4M5N6O7P8Q9R0S1T2U?pwd=yza9 其他不费流量的走内部交换https://pan.baidu.com/s/5M6N7O8P9Q0R1S2T3U4V?pwd=wxyz
    https://pan.baidu.com/s/4L5M6N7O8P9Q0R1S2T3U?pwd=stuv
    #直通eth0给iKuaihttps://pan.baidu.com/s/8P9Q0R1S2T3U4V5W6X7Y?pwd=ijkl Add-VMAssignableDevice -LocationPath "PCIROOT(0)#PCI(1C04)#PCI(0000)" -VMName iKuaihttps://pan.baidu.com/s/5M6N7O8P9Q0R1S2T3U4V?pwd=wxyz #直通eth1给iKuaihttps://pan.baidu.com/s/9H0I1J2K3L4M5N6O7P8Q?pwd=cdef Add-VMAssignableDevice -LocationPath "PCIROOT(0)#PCI(1C05)#PCI(0000)" -VMName iKuaihttps://pan.baidu.com/s/4N5O7P8Q9R0S1T2U3V4W https://pan.baidu.com/s/5E6F7G8H9I0J1K2L3M4N?pwd=efg2 #直通eth2给OpenWRThttps://pan.baidu.com/s/6W7X8Y9Z0A1B2C3D4E5F?pwd=ghi4 Add-VMAssignableDevice -LocationPath "PCIROOT(0)#PCI(1C06)#PCI(0000)" -VMName OpenWRThttps://pan.baidu.com/s/9I0J1K2L3M4N5O6P7Q8R
    https://pan.baidu.com/s/8R0S1T2U3V4W5X6Y7Z8A
    分配完成可输入命令检查是否成功:https://pan.baidu.com/s/7G8H9I0J1K2L3M4N5O6P?pwd=yza1 Get-VMAssignableDevice -VMName iKuaihttps://pan.baidu.com/s/9H0I1J2K3L4M5N6O7P8Q?pwd=cdef Get-VMAssignableDevice -VMName OpenWRT
    https://pan.baidu.com/s/1R2S3T4U5V6W7X8Y9Z0A?pwd=qrst
    https://pan.baidu.com/s/2K3L4M5N6O7P8Q9R0S1T?pwd=wxy8 看看输出内容里直通的网卡有没有成功加上,成功的会显示该直通网卡的IDhttps://pan.baidu.com/s/4U5V6W7X8Y9Z0A1B2C3D?pwd=bcd2 以上为Hyper-V直通网卡给指定虚拟机的流程,完成之后需要进入相应的虚拟机里对该网卡设置才可以使用。(比如iKuai里需要将直通网卡绑定WAN和LAN)https://pan.baidu.com/s/1C2D3E4F5G6H7I8J9K0L
    https://pan.baidu.com/s/3T4U5V6W7X8Y9Z0A1B2C?pwd=yza1
    将设备从虚拟机里移除:https://pan.baidu.com/s/5N6O7P8Q9R0S1T2U3V4W https://pan.baidu.com/s/8A9B0C1D2E3F4G5H6I7J 此处还是以iKuai和OpenWRT为例

    https://pan.baidu.com/s/2U3V4W5X6Y7Z8A9B0C1D https://pan.baidu.com/s/7P8Q9R0S1T2U3V4W5X6Y?pwd=klm3

    https://pan.baidu.com/s/6F7G8H9I0J1K2L3M4N5O?pwd=hij3 iKuai
    https://pan.baidu.com/s/4M5N6O7P8Q9R0S1T2U3V?pwd=bcd0
    关闭虚拟机。然后运行:https://pan.baidu.com/s/8G9H0I1J2K3L4M5N6O7P?pwd=zabc https://pan.baidu.com/s/3T4U5V6W7X8Y9Z0A1B2C?pwd=yza1 # 将设备从虚拟机里移除https://pan.baidu.com/s/2T3U4V5W6X7Y8Z9A0B1C Remove-VMAssignableDevice -VMName iKuai -LocationPath "PCIROOT(0)#PCI(1C04)#PCI(0000)"

    https://pan.baidu.com/s/4M5N6O7P8Q9R0S1T2U3V?pwd=bcd0

  • https://pan.baidu.com/s/1T2U3V4W5X6Y7Z8A9B0C
  • Remove-VMAssignableDevice -VMName iKuai -LocationPath "PCIROOT(0)#PCI(1C05)#PCI(0000)"

    https://pan.baidu.com/s/7X8Y9Z0A1B2C3D4E5F6G?pwd=jkl5 https://pan.baidu.com/s/7G8H9I0J1K2L3M4N5O6P?pwd=klm4

    https://pan.baidu.com/s/3K4L5M6N7O8P9Q0R1S2T?pwd=opqr https://pan.baidu.com/s/5W6X7Y8Z9A0B1C2D3E4F?pwd=efg0

    # 挂载设备回WinServer系统
    https://pan.baidu.com/s/3T4U5V6W7X8Y9Z0A1B2C?pwd=yza1
    Mount-VMHostAssignableDevice -LocationPath "PCIROOT(0)#PCI(1C04)#PCI(0000)"https://pan.baidu.com/s/5F6G7H8I9J0K1L2M3N4O?pwd=efg9 Mount-VMHostAssignableDevice -LocationPath "PCIROOT(0)#PCI(1C05)#PCI(0000)"
  • https://pan.baidu.com/s/4W5X6Y7Z8A9B0C1D2E3F
  • 然后在Win的设备管理器里重新启用设备。

    https://pan.baidu.com/s/4M5N6O7P8Q9R0S1T2U3V?pwd=bcd0 https://pan.baidu.com/s/5F6G7H8I9J0K1L2M3N4O

    https://pan.baidu.com/s/2J3K4L5M6N7O8P9Q0R1S?pwd=klmn https://pan.baidu.com/s/3U4V5W6X7Y8Z9A0B1C2D?pwd=yza8 OpenWRThttps://pan.baidu.com/s/8P9Q0R1S2T3U4V5W6X7Y?pwd=ijkl 关闭虚拟机。然后运行:https://pan.baidu.com/s/5E6F7G8H9I0J1K2L3M4N https://pan.baidu.com/s/4M5N6O7P8Q9R0S1T2U3V # 将设备从虚拟机里移除https://pan.baidu.com/s/1A2B3C4D5E6F7G8H9I0J?pwd=stu8 Remove-VMAssignableDevice -VMName OpenWRT -LocationPath "PCIROOT(0)#PCI(1C06)#PCI(0000)"https://pan.baidu.com/s/5M6N7O8P9Q0R1S2T3U4V?pwd=wxyz https://pan.baidu.com/s/3L4M5N6O7P8Q9R0S1T2U?pwd=yza9 # 挂载设备回WinServer系统https://pan.baidu.com/s/9Z0A1B2C3D4E5F6G7H8I?pwd=pqr7 Mount-VMHostAssignableDevice -LocationPath "PCIROOT(0)#PCI(1C06)#PCI(0000)"
    https://pan.baidu.com/s/6F7G8H9I0J1K2L3M4N5O
    然后在Win的设备管理器里重新启用设备。
  • https://pan.baidu.com/s/7Y8Z9A0B1C2D3E4F5G6H?pwd=klm2
  • https://pan.baidu.com/s/3K4L5M6N7O8P9Q0R1S2T?pwd=opqr 注意事项https://pan.baidu.com/s/8J9K0L1M2N3O4P5Q6R7S 同一个设备只需要跑一次 Add-VMAssignableDevice。这个命令有概率不检查去重,会导致你的虚拟机无法启动。如果遇到这种情况,那么先把设备从虚拟机里移除,然后重新添加一次。
    https://pan.baidu.com/s/8P9Q0R1S2T3U4V5W6X7Y?pwd=ijkl

    https://pan.baidu.com/s/4L5M6N7O8P9Q0R1S2T3U?pwd=stuv

  • https://pan.baidu.com/s/2J3K4L5M6N7O8P9Q0R1S?pwd=klmn

  • https://pan.baidu.com/s/4U5V6W7X8Y9Z0A1B2C3D?pwd=bcd2
    https://pan.baidu.com/s/9B0C1D2E3F4G5H6I7J8K
    https://pan.baidu.com/s/9H0I1J2K3L4M5N6O7P8Q?pwd=cdef

    https://pan.baidu.com/s/9A0B1C2D3E4F5G6H7I8J
    哈哈

  • https://pan.baidu.com/s/8Q9R0S1T2U3V4W5X6Y7Z?pwd=nop4
  • 回复 论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|小黑屋|首页 ( 冀ICP备2021005225号-1 ) |网站地图

    GMT+8, 2024-11-25 01:37 , Processed in 0.052754 second(s), 10 queries , Gzip On, Redis On.

    Powered by Discuz! X3.4

    © 2001-2013 ELITE论坛【技术无价-分享快乐】

    快速回复 返回顶部 返回列表