1

My WSL2 instance is currently connecting via Ethernet adapter vEthernet (WSL) to the Internet. Can I enable it to use the Ethernet adapter vEthernet (Default Switch or another) instead?

Currently, there is an option to create a New Virtual Switch (external) in Hyper-V Manager, and create the .wslconfig file in the user home directory on Windows.

[wsl2]
vmSwitch=New Virtual Switch
networkingMode=bridged
ipv6=true

Unfortunately, this is broken in Windows 10.

0

1 Answer 1

1

I assume that your demand is motivated by the need to connect the two interfaces.

This PowerShell command should cause the switches to forward messages between themselves:

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

For more information see the article
Allowing Windows Subsystem for Linux to communicate with Hyper-V VMs


Note that replacing the "vEthernet (WSL)" switch itself is not possible. A bug report on that subject is found in the post [WSL2] - vEthernet (WSL) switch reset/lost configuration after system reboot #6406 where the poster has manually modified the switch, only to find that these modifications disappeared after reboot.

The official answer by Microsoft was :

that is really the intent here. This issue is expressing a work-around that doesn't work.

This is only logical, since the WSL environment itself is a light-weight virtual machine, so is in effect reinitialized every time that it is restarted. To permanently effect these changes would require modifying this virtual machine, for which there is no known method. In addition, such modifications would disappear every time that WSL would be updated by Windows Update.

6
  • 1
    I was hoping to have the WSL use a different interface altogether. The Hyper-V Manager can tell a virtual machine to connect to the switch, and leave the WSL vEthernet adapter alone, apparently. On the other hand, WSL seems to be stuck with the default WSL vEthernet adapter for all the Internet traffic. My vEthernet adapter is creating problems for the system, because a Java business software is using that adapter.
    – GianniTee
    Commented Jan 25, 2023 at 8:39
  • That unfortunately is not possible. See the addition to my answer.
    – harrymc
    Commented Jan 25, 2023 at 8:51
  • You could add a new file C:\Users\user\.wslconfig with the following contents. [wsl2] vmSwitch=New Virtual Switch networkingMode=bridged ipv6=true It is mentioned here: stackoverflow.com/questions/69691928/… However, although it works on my home computer, it produces an error on the workstation. "The virtual machine or container JSON document is invalid. Error code: Wsl/Service/CreateInstance/CreateVm/ConfigureNetworking/0x8037010d"
    – GianniTee
    Commented Jan 25, 2023 at 12:41
  • @GianniTee Do you perhaps run Win11 on your home computer and Win10 on the workstation? The bridged network mode for WSL2 is apparently only supported on the former.
    – MikrySoft
    Commented Feb 15, 2023 at 7:00
  • Why would Microsoft make vEthernet (WSL) switch not replaceable, and reinitialized every reboot? I don't see any benefit to that. What benefit is there even to have a special switch for WSL rather than the "default switch"? Commented Mar 30 at 22:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .