Skip to content

Instantly share code, notes, and snippets.

@danvy
Created September 5, 2020 21:04
Show Gist options
  • Save danvy/9486bf730371436131cb888ff4c2ceb6 to your computer and use it in GitHub Desktop.
Save danvy/9486bf730371436131cb888ff4c2ceb6 to your computer and use it in GitHub Desktop.
Reset your WSL network connection trying to fix WSL2 media disconnected error
# Check these threads before proceeding:
# https://github.com/microsoft/WSL/discussions/5857
# https://github.com/microsoft/WSL/issues/5821
if (-Not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')) {
$CmdLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments
Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CmdLine
Exit
}
# Restart the Host Network Service
Restart-Service -Force -Name hns
# Restart the Windows Subsystem for Linux Manager
Restart-Service LxssManager
# Restart the WSL Network adapter
Restart-NetAdapter -Name "vEthernet (WSL)"
@d-kja
Copy link

d-kja commented Oct 9, 2024

wsl ping google.com -c 4

thanks man, all that I needed to do was ping and it just setup a new IP and Adapter by itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment