-
-
Save danvy/9486bf730371436131cb888ff4c2ceb6 to your computer and use it in GitHub Desktop.
# 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)" |
This script is working for me, many thanks, I have seen the case where "vEthernet (WSL)" disappears not sure why, if I run "wsl --shutdown" and the adaptor still shows up,
Restart-NetAdapter -Name "vEthernet (WSL)"
cannot be run becausevEthernet (WSL)
is gone whenRestart-Service LxssManager
.But, when I start my windows terminal, then open Ubuntu WSL, I can restart the
vEthernet (WSL)
. Is it common behavior? Because it's like everytime I shutdown the WSL, then the hyper-v adapter is also gone.
@Rizary Does it help if you restart the adapter before Lxss ?
I added
wsl --shutdown
wsl ping google.com -c 4
At the end just to check that the wsl internet connection works at the end
Thanks
It's working for me. Is there any permanent solution?
This is very dangerous and annoying.
It worked for me. Thx
It worked for me. Thx
What exactly did you get to work I'm having mixed luck using this script, what version of windows are you currently running
It didn't work for me.
I had to add a firewall rule to whitelist the Network Interface.
This is a godsend!
This did the trick for me!
This works :) I initially copy pasted your code directly into PowerShell terminal and it didn't work. Then I created a separate .ps1 file and ran it and then it worked. Thanks!
This is works.
Thanks
I added
wsl --shutdown wsl ping google.com -c 4
At the end just to check that the wsl internet connection works at the end
This fixed things for me, Thank you!
After 1h30 of trying everything on stackoverflow, this worked ! I am surprised this is still needed and still works after 2 years.
@dtraparic Happy that it help you. I'm also surprised that it's still relevant.
Restart-NetAdapter -Name "vEthernet (WSL)"
cannot be run becausevEthernet (WSL)
is gone whenRestart-Service LxssManager
.But, when I start my windows terminal, then open Ubuntu WSL, I can restart the
vEthernet (WSL)
. Is it common behavior? Because it's like everytime I shutdown the WSL, then the hyper-v adapter is also gone.