Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't Ping Ubuntu VM from WSL2 Ubuntu

I am trying to ping my Ubuntu VM from my WSL2 Ubuntu. And same ping issue happening for vice versa. Both ubuntu version are 20.04.1. But I can ping Ubuntu VM from my Local Windows.

From Windows To Ubuntu VM

WUVM

From WSL2 Ubuntu To Ubuntu VM

WSLUVM

like image 721
Saiful Islam Avatar asked Jan 14 '21 09:01

Saiful Islam


2 Answers

We need to set Forwarding to be enabled across the two v-Switches. Using this command (with admin rights) based on my v-Switch names works.

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

Below is my network connection

enter image description here

like image 101
Md Mahmudul Hasan Avatar answered Oct 18 '22 13:10

Md Mahmudul Hasan


That's a great command line ! Minor improvment that would product less logs, invoke Enabled only if state is Disabled.

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'
like image 20
Idan Avatar answered Oct 18 '22 13:10

Idan