Connect Hyper-V VM from WSL (Ubuntu)

Viewed 6440

I have created a VM on Hyper-V with 2 Network Adapters.

  1. NAT switch for static ip
  2. External Switch (for access internet)

From my command line I was able to connect to the VM with the Nat Switch IP but from WSL Bash I was not able to connect with IP NatSwitch, but able to connect with ExternalSwitch IP.

Why?

1 Answers

Unfortunately this is the expected behavior. (As of 29/01/2021)

WSL2 uses Hyper-V Virtual Switch, vEthernet (WSL) virtual network adapter, that is providing internal type Hyper-V network that is only accessible from the VM and the Host. The Hyper-V machine has a different virtual network adapter e.g. vEthernet (Default Switch). If that is set to internal that is a different NAT-ed network (subnet) not connected to the WSL one. It is like the Host having 3 NICs and one cable (Cable 1) going to WSL on a subnet that only exists on that adapter/cable and another cable (Cable2) going to Hyper-V guest with a very different subnet on that NIC.

enter image description here

On the other scenario the Hyper-V guest shares the subnet with the Host machine ("Same subnet as the 3rd cable/NIC.") so it is routed back to the VM. See red labels.

enter image description here

There is a workaround in this GitHub issue using port forwarding to Guest VM from WSL.

Related