Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow us to specify hyper-v virtual switch network adapter for wsl2 #5835

Closed
drdamour opened this issue Aug 31, 2020 · 12 comments
Closed

allow us to specify hyper-v virtual switch network adapter for wsl2 #5835

drdamour opened this issue Aug 31, 2020 · 12 comments

Comments

@drdamour
Copy link

drdamour commented Aug 31, 2020

Is your feature request related to a problem? Please describe.
I'm in a corporate environment and my windows defender is very restricted. I do get to own the 172.18.0.0/16 address space. We use this for our docker desktop stuff so we can have things talk, and i want to do the same for my WSL2 but there doesn't seem to be a way to tell WSL to use that space. Every reboot it just randomly picks something from 172.16.0.0/10 or 192.168.0.0/24 it seems and i can't change it.

Describe the solution you'd like
I want to be able to do wsl --set-default-switch "JRS WSL"

this would be after i do something like:

New-VMSwitch -SwitchName "JRS WSL" -SwitchType Internal
New-NetIPAddress -IPAddress 172.18.5.1 -PrefixLength 24 -InterfaceAlias “vEthernet (JRS WSL)”
New-NetNAT -Name “JRS WSL NAT” -InternalIPInterfaceAddressPrefix 172.18.5.0/24

then any WSL instances after launch would use that network and get an ip from 172.18.5.0/24

Describe alternatives you've considered
There's a lot of issues related to this out there:

Additional context
Is there some guidance on how we can have our corporate GPO setup so that windows defender doesn't get in the way of internal network adapters? They have NO net connection profile...can GPO target them by that + internal? That'd be another way to solve this

@therealkenc
Copy link
Collaborator

therealkenc commented Aug 31, 2020

Every reboot it just randomly picks something from 172.16.0.0/10 or 192.168.0.0/24 it seems and i can't change it.

/dupe #4467

@ghost
Copy link

ghost commented Aug 31, 2020

Hi! We've identified this issue as a duplicate of another one that already exists in this repository. This specific instance is being closed in favor of tracking the concern over on the referenced thread.

Thanks for your report!

@ghost ghost closed this as completed Aug 31, 2020
@ghost ghost added the duplicate label Aug 31, 2020
@drdamour drdamour changed the title allow us to specify hyper-v virtual switch network adapter for wsl allow us to specify hyper-v virtual switch network adapter for wsl2 Aug 31, 2020
@drdamour
Copy link
Author

drdamour commented Sep 1, 2020

@therealkenc please reconsider, i called out #4467 as it is a related issue but this is asking for a very specific solution that has different implications

@m0nzderr
Copy link

+1 Please reopen!

@moonrockfamily
Copy link

This seems like a trivial feature for great benefit. It doesn't introduce a new concept but rather allows override of a default behavior and hence won't burden anyone relying on the current behavior; virtualSwitch="Default Switch".

Please reconsider this optional 'virtual switch' setting either via the command line (precedence) or /etc/wsl.conf:

  • command line
    wsl --set-virtual-switch "JRS WSL"
  • /etc/wsl.conf
[network]
virtualSwitch = "JRS WSL"

@berlincount
Copy link

I'm also affected by this bug, do not consider it a feature, and am prevented from using WSL "for real" by it :-/

The time at which Hyper-V decides which IP networks aren't conflicting is not the time I have all of them active.

Please allow selection of a static network for WSL2.

@awakecoding
Copy link

The WSL-managed switch simply doesn't work for me, and I'm having trouble figuring out how to modify it. I would appreciate having an option to create my own and just tell WSL to use it. Can we re-open this feature request?

@Biswa96
Copy link

Biswa96 commented Oct 7, 2021

You're welcome #7395

@toxyy
Copy link

toxyy commented Apr 17, 2022

Also affected by this. Apache logs show the virtual network address of the adapter instead of the actual visitor ip, and I can only get them if I have a cloudflare domain and mod_remoteip enabled (with RemoteIPTrustedProxy for 172.17.32.0/20 as well). The problem with this is if you connect to apache with my actual IP or any other domain pointing towards my IP, it shows the 172 addresses again.

The way to get them back would be to make a DNAT and have WSL use that switch, which this thread proves is pretty tedious. Please reopen.

@hubertsvk
Copy link

this doesn`t work

PS C:\Users\xxx> wsl --set-virtual-switch "NET"
Invalid command line option: --set-virtual-switch

@hubertsvk
Copy link

this working for me
#4150 (comment)

@luxzg
Copy link

luxzg commented Oct 23, 2022

I've written extensive tutorial in the other issue, so here's the link:

#4150 (comment)

Esit: to clarify, I'd like to point everyone to the fact that vSwitch can now be used to directly connect WSL2 distro, officially, no hacks, using "networkingMode=bridged". You do need W11 Pro, which shouldn't be an issue. I've compiled a nice big tutorial couple of days ago as a comment in main networking thread:
#4150 (comment)

Likewise added it to my GitHub:
https://github.com/luxzg/WSL2-fixes

I went through W10 to W11 upgrade (linked instructions for those with "unsupported" hardware), WSL2 Preview, creation of vSwitch, configuration of a bridge, and as a bonus systemd configuration on Ubuntu with complete systemd based networking setup. It should be doable for both newbies and experienced users. Btw, I can now tear up and setup new WSL2 instance with proper networking and full apt upgrades and all in less than 10 minutes, easy-peasy.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants