WSL: [WSL2] Network connections are not restored after returning from Windows sleep mode

Your Windows build number:

10.0.19582.1001

What you’re doing and what’s happening:

Originally found this problem while using X410 (X Server for Windows 10) with WSL2. I was able to confirm the same problem with much simpler program, netcat (https://en.wikipedia.org/wiki/Netcat).

The following problem only happens when TCP connections are made from WSL2 to Windows. When connections are made from Windows to WSL2, they are restored after sleep mode as expected.

  1. Start netcat in Windows 10
.\ncat.exe -l -p 9999 -v

netcat for Windows is available as an executable in Nmap package (https://nmap.org/download.html) You don’t need to install it. You just need to download its command-line ZIP file, unzip, go to that unzipped folder in PowerShell or Windows Command Prompt and execute the ncat.exe as shown above.

The above command puts ncat.exe into a server mode (-l) waiting for data at the port 9999 (-p).

If you have a WSL1, you can also use its ‘nc’ command. For example, if you have Debian in WSL1 and Ubuntu in WSL2, you can run “nc -l -p 9999 -v” in Debian and get the same result.

  1. Open WSL2 console

I used the “Ubuntu 18.04” installed from Microsoft Store.

2.1 Get the IP address for Windows host

echo $(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}')

2.2 Connect to the IP address found in Step 2.1

Assuming the IP address is 172.18.16.1:

nc -v 172.18.16.1 9999

2.3 You should get connection succeeded messages for both ncat.exe in Windows and nc in WSL2.

  1. Type some text and press [ENTER] in Windows (ncat.exe) and WSL2 (nc). You should be able to confirm that the connection is active and working in both directions as expected.

  2. Put your computer to Sleep (Windows Start -> Power -> Sleep)

  3. After confirming that your computer is fully in sleep mode, wake it up.

ncat.exe in Windows shows that the connection is lost, but nc in WSL2 thinks the connection is still active.

What’s wrong / what should be happening instead:

The network connection between WSL2 and Windows is completely restored after waking up from Windows sleep mode.

The same problem can be observed with Hyper-V virtual machines (TCP connections made from VM to Windows). However, I can work around it by using its VSOCK feature. But, as far as I can tell, there seems to be no plan for VSOCK or AF_UNIX in WSL2.

All in all, such problem can be fatal for developers who create server programs for Windows that can be used by Linux apps running in WSL2.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 68
  • Comments: 53

Most upvoted comments

I’m getting this as well, but I use hibernate. I’m on Version 10.0.20197.1000

It’s annoying, things I did to no avail:

  1. add nameservers
  2. disable swap

restarting via WSL --shutdown does nothing (same as restarting Lxssmanager).

I have to reboot just to get connectivity back. Is there a way to initialize WSL’s network stack since IP is

This problem has gone away after I updated my Ubuntu by doing the following: sudo apt update && sudo apt upgrade.

I wrote a short article on how I solve this problem: WSL2 slowing down over time issue: Medium

This has been resolved since few windows versions ago.

This problem still exists on Windows 11 build 22621.1265 on a fairly fresh install.

I recently discovered https://github.com/nbdd0121/wsld which provides a workaround based on vsocks. So far it works really well for my X forwarding use case.

Same on insider 20180.1000 (wsl kernel: 4.19.121), must reboot windows to get network back

To prevent rebooting the whole system, you can try: wsl-restart.bat

Perhaps Microsoft can just fix their shit. This has been open since (early) 2020 ffs

Same problem. After sleeping mode, I lost the internet connection for wsl2. Only reboot can solve the problem, wsl --shutdown cannot solve. Still looking for / waiting better solution!

OS: Win10 pro insider preview: build 20201.re_prerelease.200822-1922

wsl cat /proc/version: Linux version 4.19.128-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Tue Jun 23 12:58:10 UTC 2020

I suppose this is also the reason why my WSL 2 Emacs over Xming X11 windows server have aborted with a traceback every time the computer returns from sleep.

I have the same issue.

  • MS Windows 10 Education build 19042.685
  • WSL2 with Ubuntu 20.04
  • Docker Desktop with WSL2 backend
  • Hyper-V not installed.

I can’t connect to my WSL2 ubuntu after returning from sleep mode. VS Code connection is lost after waking up and can’t reconnect unless I reboot my pc. Also, I can’t connect with Windows Terminal application.

Not sure why, but after 6 months of constantly looking for a solution. This command fixed the issue (see: link):

sudo rm -rf /etc/acpi/events

Hmm, today my computer with Windows 19042.928 came back from sleep with my X11 Emacs still running. Good! What changed?

Or maybe I should wait a bit and see if it wasn’t just a one-time thing…

wsl --shutdown makes my system back, but this is not really a solution. All unsaved work are lost and very inconvenient. I really wish Microsoft can solve this issue.

Check in your /etc folder for resolv.conf and wsl.conf. If resolv.conf is missing you will get DNS resolution issues.

So check what is in your wsl.conf, assuming that you have one …

If it contains:

[network]
generateResolvConf = false

Then WSL is not going to regenerate the resolv.conf for you and you have to create/edit your own (e.g. sudo nano /etc/resolv.conf and make sure it is pointing at some nameservers.

The default for generateResolvConf is supposed to be true (from what I understand), but sometimes that doesn’t seem to be correct …

So you can explicitly set generateResolvConf = true in the /etc/wsl.conf, and then reboot (yep), to get it to generate resolv.conf for you.

https://github.com/nbdd0121/wsld does seem to work! I had to download pre-built binary for windows because custom built executable would just insta-crash. I am running x410/Void/i3 so I had to put the snippet from wsld into .profile and set up windows daemon in task scheduler.

@robmwalsh Ssh has an X option. It ’s similar to that.

For me is gone after updating to Windows Insider 20236

Similar issue here. It seems heavily linked with Hyper-V and stops obeying to any sort of logic once the issue starts to happen, reboot solves it. The problem occurs since the update to Windows 10 2004. Latest KB doesn’t seem to resolve the issue.

@thisguychris :

I have to reboot just to get connectivity back.

and @david50407 :

must reboot windows to get network back

This seems to be a different issue than the one reported by @klesniewski :

IntelliJ IDEA run from WSL 2, connecting to X Server on Windows. After coming back from sleep, IntelliJ window is gone and I have to start it again.

which is what I am experiencing as well: I’m running an X server on Windows (VcXsrv) to use graphical Linux applications. This works perfectly, except that when Windows goes into standby and wakes up again, all X windows are gone. The Linux applications don’t report any error (in the console) and appear to be running fine; it’s only the X output that is gone (thus rendering the apps unuseable). I can simply kill the apps and restart them, and the X windows reappear fine. No reboot required, which is why I think there are separate issues here.