luxzg / WSL2-fixes

Fix-up scripts for WSL2, mainly networking related
198 stars 23 forks source link

Static IP for 2 different wsl2 distros on same pc #3

Open Camrule opened 1 year ago

Camrule commented 1 year ago

Hey there,

Thanks so much for your guide! Has helped me immensely. I'm wondering if there would be an easy solution to set static IP for 2x wsl2 Linux on the same pc?

Cheers!

luxzg commented 1 year ago

I haven't tested with them running at the same time, it should work, just set one IP in one OS, other IP in other OS. You should NOT use static MAC in that case (I think) as it would likely confuse networking stacks. So let the WSL handle mac, and you handle the IPs.

Camrule commented 1 year ago

Hey thanks for that. But that is my issue. I do not know how to set it. Do you have any idea how to do that?

luxzg commented 1 year ago

Sure, here's the general idea. Follow my guide, just make sure NOT TO set wslconfig option macAddress=.... Go through the procedure for VM distro no 1, and let's say you give it static IP 192.168.0.101. Then go through same procedure with VM No 2 and when setting static IP just give it next in line for example 192.168.0.102 Start both VMs and try pinging one from the other and if that works everything should work.

Note that "global" settings (eg. Hyper-V vSwitch, and options inside wslconfig) apply to all VMs / distros / instances. So when setting 2nd one, you don't actually need to set anything, because you've already done it when setting 1st one. Both will use same vSwitch and same wslconfig settings.

Hope that helped!

P.S. IP s above are just an example, make sure to adjust them to your real network

micheldiemer commented 6 months ago

Here a detailed working procedure on how to use WSLAttachSwitch

Script : https://github.com/microsoft/WSL/issues/4799#issuecomment-2065450904

Text : https://github.com/microsoft/WSL/issues/4799#issuecomment-2065456777