Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect Hyper-V VM from WSL (Ubuntu)

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?

like image 270
TeguhTujuh Avatar asked May 18 '20 11:05

TeguhTujuh


People also ask

Does Hyper-V work with WSL2?

While WSL 2 uses Microsoft's Hyper-V as a hypervisor under the hood to run the utility VM, it does not require you to enable Windows' Hyper-V role or feature; WSL works perfectly fine without it.

Can Hyper-V coexist WSL?

Does WSL 2 use Hyper-V? Will it be available on Windows 10 Home and Windows 11 Home? WSL 2 is available on all Desktop SKUs where WSL is available, including Windows 10 Home and Windows 11 Home. The newest version of WSL uses Hyper-V architecture to enable its virtualization.

Does VMware work with WSL2?

WSL 2 will work with VMware 15.5. 5+ and VirtualBox 6+. Learn more in our FAQs.

Can WSL interact with Windows?

WSL can run Windows tools directly from the WSL command line using [tool-name].exe . For example, notepad.exe . Applications run this way have the following properties: Retain the working directory as the WSL command prompt (for the most part -- exceptions are explained below).

Why WSL2 can't connect to Hyper-V?

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).

How do I get Ubuntu Core on Hyper V?

Getting Started with Ubuntu Core on Hyper-V using WSL Ubuntu Core is a tiny, transactional version of Ubuntu Linux from Canonical. Use WSL to convert a KVM image of Ubuntu Core and boot in Hyper-V on Windows.

Is vs code compatible with Hyper-V?

VS Code Compatibility - WSL 2 / Hyper-V VM - VS Code has an embedded WSL 2 connection type and you can type code . in a terminal to automatically open the current folder. Hyper-V VM projects can connect to VS Code via an SSH connection. Linux Compatibility - WSL 2 / Hyper-V VM - Hyper-V VM is the clear winner here.

Is Hyper-V on Windows 10 good enough to run a VM?

I use Hyper-V on Windows 10 to run an Ubuntu 20.04 VM, which I only need in order to run some models for work. Everything has worked fine over several months of regular use. Today on the VM I had to kill a model process that had been set up wrong and was running too long and filling the virtual hard drive.


Video Answer


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.

like image 105
HobPet Avatar answered Oct 17 '22 22:10

HobPet