Set WSL2 subnet

Alin Ungurean 1 Reputation point
2022-12-10T14:49:35.76+00:00

How to set WSL2 subnet to a specific address space?

Running WSL2 on Windows 11, without Hyper-V, changes the subnet associated with vEthernet (WSL) adapter on every reboot of the host computer.

The subnet is a /20 block randomly selected from the address space of 172.12.0.0/12. This conflicts sometimes with other subnets in my LAN creating "no route to host" conflict when trying to connect from WSL guest to one of those other subnets.

I need to be able to set more specific /20 block for WSL2 so that the conflict never occurs any longer. The only workaround I found was to reboot the host computer, so that WSL network is randomly re-assigned from a different block that does not conflict with my other subnets.

I was not able to find any way to modify the settings of vEthernet (WSL) adapter. While this adapter is enumerated by ipconfig, it does not show up in Control Panel / Settings. Is there a way to set the vEthernet (WSL) subnet to a specific block range?

Such feature would be similar to VMware Virtual Network Editor that permits the configuration of virtual subnets.

Thanks

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
7,377 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. C Plumlee 15 Reputation points
    2023-04-11T19:29:40.45+00:00

    The Windows -side WSL2 Hyper-V network adapter does not come up anywhere you can configure it, even if you install the Hyper-V Manager. You can change the netmask and address of the virtual adapter in regedit here: image

    I had some network devices I needed to reach from WSL in a nearby subnet and was able to get there simply by reducing the size of the the WSL adapter's subnet from 4096 addresses (why would anyone need that?) to 256: User's image

    3 people found this answer helpful.

  2. Dave Patrick 425.9K Reputation points MVP
    2022-12-10T15:19:51.163+00:00

    The product group for WSL actively monitors questions over at
    https://github.com/microsoft/WSL#readme
    https://stackoverflow.com/questions/tagged/windows-subsystem-for-linux?tab=Newest

    --please don't forget to upvote and Accept as answer if the reply is helpful--


  3. pdurante 0 Reputation points
    2024-01-10T14:01:45.8666667+00:00

    God bless you for posting this. Once I rebooted after making this change I was able to access VPN resources on my corporate network. I use a python script to set my DNS servers once connected to the VPN.

    0 comments No comments