microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.26k stars 812 forks source link

Unable to get internet when connected to 192.168.81.0/24 network #10016

Open sorryusernameisalreadytaken opened 1 year ago

sorryusernameisalreadytaken commented 1 year ago

Windows Version

Microsoft Windows [Version 10.0.19045.2846]

WSL Version

1.2.0.0

Are you using WSL 1 or WSL 2?

Kernel Version

Linux version 5.15.90.1-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Fri Jan 27 02:56:13 UTC 2023

Distro Version

Ubuntu 22.04

Other Software

No response

Repro Steps

Unfortunately, I can't say what triggered it. Suddenly it was no longer possible to access the internet with my WSL2 Ubuntu 22.04 instance at my workplace.

Other colleagues have the same wsl2 setup as me and can connect to the internet with their WSL2 without any problems.

The office network has two possible DHCP ranges: 192.168.81.0/24 (WLAN/LAN) 192.168.82.0/24 (guest WLAN)

At home in the home office I have no problems in the network 10.0.0.1/16. If I change the network to 192.168.81.0/24 at home, the WSL has no internet again.

The other colleagues have got other IPs to their WSL-Virtual Adapter. But even after uninstalling and reinstalling the WSL feature, I still get the same IP on the virtual MS adapter.

Maybe an important information. We use in the team wsl as a non-administrator under windows. This means that the wsl2 is installed by it-support and then the remaining software can be installed by non-admin (ubuntu etc.).

Expected Behavior

No matter what network I am on, my WSL2 instance should always have internet if the network allows it.

Actual Behavior

I can't get internet on the following networks: 192.168.81.0/24 (WLAN/LAN) 192.168.82.0/24 (guest WLAN)

I get internet in the following: 10.0.0.1/16

Diagnostic Logs

wsl.zip packets.zip

OneBlue commented 1 year ago

Thanks for reporting this @sorryusernameisalreadytaken.

Does running wsl --shutdown and then restarting WSL help when networking connectivity is lost ?

If not, can you follow the ['Networking issues']'https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#networking-issues) section and share the output ?

sorryusernameisalreadytaken commented 1 year ago

Does running wsl --shutdown and then restarting WSL help when networking connectivity is lost ?

No it does not help. I have immediately no internet when I change to a 192.168.81.0/24 / 192.168.82.0/24 network with the wsl2. If I then switch back to e.g. my cell phone's internet (mobile hotspot) it works immediately. Also in my private network at home (10.0.0.1/16).

If not, can you follow the ['Networking issues']'https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#networking-issues) section and share the output ?

I did that already. In the initial issues there is a wsl.zip containing the wsl.etl and the packets.zip containing the packets.etl I had to pack the logs in a ZIP each because otherwise I was not allowed to upload the files here. Definitely I have the networking.bat run by our it-service with admin rights. Did I forget to upload some logs?

zcobol commented 1 year ago

@sorryusernameisalreadytaken Other colleagues ...can connect so it's not a WSL issue!

sorryusernameisalreadytaken commented 1 year ago

Why can you say that with such confidence? I can recreate the network at home with a completely different network hardware and get the same behavior.

My Windows 10 was installed normally with no special extra setups. This is how it happens with all employees.

I still see more of a WSL2 bug here. We have the WSL2 probably now 4 times completely uninstalled and again installed. The "vEthernet (WSL)" always gets the same static IP. No matter if I install wsl in my home network (10.0.0.1/16 ip range) or at work. On the other 4 PCs the "vEthernet (WSL)" did not get an IP in the 192.168.80.1 range. Another one has e.g. a static IP at his "vEthernet (WSL)" adapter 192.168.192.1 and his Ubuntu gets 192.168.199.60 as IP.

Biswa96 commented 1 year ago

The "vEthernet (WSL)" always gets the same static IP.

Newer version of WSL creates some registry key to store static IP addresses. Could you please check if deleting or modifying those registry values fix the issue? I have explained those here https://github.com/microsoft/WSL/discussions/9580

sorryusernameisalreadytaken commented 1 year ago

Awesome! That worked. Sorry for the late reply but the person responsible in out IT-Service was on vacation and so was I.

Deleting the NatNetwork and NatGatewayIpAddress value in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss fixed the issue. Steps:

  1. wsl.exe --list
  2. wsl.exe --unregister "Ubuntu aka ALL your WSL's"
  3. uninstall wsl from your windows machine
  4. delete with regedit the mentioned values NatNetwork and NatGatewayIpAddress in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss
  5. reinstall wsl
  6. reinstall your wsl systems, e.g. Ubuntu

I am a bit unsure about this issue here. My problem is fixed, but I think the wsl-installer should choose static IPs more carefully or should always recreate by random a new static ip when reinstalling the wsl.

Biswa96 commented 1 year ago

It is not required to uninstall Linux distribution in WSL2. The network IP related registries can be changed without that.

abdullah-bin-hasan commented 10 months ago

Doing these solved my problem: Open Hyper-V Manager as administrator

Select your pc, open Virtual Switch Manager

Select WSL

Set to external network

Select the network card the traffic runs through

Then login to wsl2 terminal and configure an IP address. E.g.

sudo ip addr flush dev eth0 sudo dhclient eth0

This is where i found it: https://stackoverflow.com/a/62438375/10853017