无法从 WSL2 Ubuntu Ping Ubuntu 虚拟机

Can't Ping Ubuntu VM from WSL2 Ubuntu

我正在尝试从我的 WSL2 Ubuntu ping 我的 Ubuntu 虚拟机。同样的 ping 问题发生在反之亦然。 ubuntu 版本均为 20.04.1。但是我可以从本地 Windows.

ping Ubuntu 虚拟机

从 Windows 到 Ubuntu VM

从 WSL2 Ubuntu 到 Ubuntu VM

我们需要将转发设置为在两个 v-Switch 之间启用。根据我的 v-Switch 名称使用此命令(具有管理员权限)有效。

Get-NetIPInterface | where {$_.InterfaceAlias -eq 'vEthernet (WSL)' -or $_.InterfaceAlias -eq 'vEthernet (Default Switch)'} | Set-NetIPInterface -Forwarding Enabled

下面是我的网络连接

这是一个很棒的命令行! 产生较少日志的小改进,仅当状态为禁用时才调用启用。

Get-NetIPInterface | select ifIndex,InterfaceAlias,AddressFamily,ConnectionState,Forwarding| where {$_.InterfaceAlias -eq 'vEthernet (WSL)' -or $_.InterfaceAlias -eq 'vEthernet (Default Switch)'} | where {$_.Forwarding -eq 'Disabled'} | Set-NetIPInterface -Forwarding 'Enabled'