WSL2 から Hyper-V にアクセスする
変更前の確認
PS C:\Users\User> Get-NetIPInterface | ` >> Select-Object ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding | ` >> Sort-Object -Property IfIndex | ` >> Format-Table ifIndex InterfaceAlias AddressFamily ConnectionState Forwarding ------- -------------- ------------- --------------- ---------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 省略 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 17 vEthernet (Default Switch) IPv6 Connected Disabled 17 vEthernet (Default Switch) IPv4 Connected Disabled ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 省略 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 108 vEthernet (WSL) IPv6 Connected Disabled 108 vEthernet (WSL) IPv4 Connected Disabled
設定の変更
PowerShell を管理者権限で起動して設定の変更を行う必要がありました。
PS C:\Users\User> Get-NetIPInterface | ` >> Where-Object {$_.InterfaceAlias -eq 'vEthernet (WSL)' -or $_.InterfaceAlias -eq 'vEthernet (Default Switch)'} | ` >> Set-NetIPInterface -Forwarding Enabled
変更後の確認
PS C:\Users\User> Get-NetIPInterface | ` >> Select-Object ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding | ` >> Sort-Object -Property IfIndex | ` >> Format-Table ifIndex InterfaceAlias AddressFamily ConnectionState Forwarding ------- -------------- ------------- --------------- ---------- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 省略 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 17 vEthernet (Default Switch) IPv6 Connected Enabled 17 vEthernet (Default Switch) IPv4 Connected Enabled ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 省略 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 108 vEthernet (WSL) IPv6 Connected Enabled 108 vEthernet (WSL) IPv4 Connected Enabled