No Internet when winnat stop/started
Version
Microsoft Windows [Version 10.0.19044.2364]
WSL Version
- [X] WSL 2
- [ ] WSL 1
Kernel Version
5.10.16
Distro Version
Ubuntu 22.04
Other Software
Docker Desktop (Engine) v20.10.17
Repro Steps
I was on the stackoverflaw for solving this problem:
bind: An attempt was made to access a socket in a way forbidden by its access permissions
I ran:
net stop winnat
net start winnat
The issue will go away but the WSL's internet interrupted and i have to reboot the pc
First, Can you tell me why the first error happens? It occur when the windows restarted, The second one cause by the 1st solution :(
Expected Behavior
Having Internet on WSL after stop/start winnat
Actual Behavior
No Internet After:
net stop winnat
net start winnat
$ curl google.com
curl: (6) Could not resolve host: google.com
Diagnostic Logs
No response
Thanks for reporting this @foremtehan.
WSL uses HNS for NAT networking, which relies on winnat. I'm guessing that restarting winnat will drop all the port reservations which will effectively break any running WSL2 distribution.
Ok how do i solve bind: An attempt was made to access a socket in a way forbidden by its access permissions issue then? Is it possible to fix it without restarting the pc ?
Every solution on internet require restarting pc or restarting winnat
I am having the same problem which is also talked about in this thread. https://github.com/docker/desktop-feedback/issues/783
Any solution to this? This seems to permanently break the WSL because rebooting and restarting wsl.exe doesn't work.
FYI, this solution in docker/for-win#3438 worked for me. For whatever reason, you have to make sure to actually restart instead of shutting down and powering back on
What @Ai-Yukino wrote above leads to instructions to reset your entire network configuration. This doesn't work, and especially is no solution to WSL network connectivity issues (typically of the type, DNS works, but ICMP, TCP and UDP don't) after restarting the WinNAT service, which is a common solution for freeing a listen port that it is hogging for some reason, so that a Windows application may use it.
Since I find it beyond annoying to have to go hunt for solutions and a non-solution (generic nuclear option of "just reinstall" or "just reset to default settings") being offered in all the popular internet search results, here's the correct solution. Requires no reboot or reconfiguring all of your network settings, either:
After restarting WinNAT with net stop winnat && net start winnat, it will also be necessary to restart the Host Network Service with net stop hns && net start hns. However, be aware that the Application Guard Container Service depends on it. If Windows Defender Application Guard is installed, you will need to stop it before stopping the Host Network Service with net stop hvsics and then restart it after, as well with net start hvsics.
It is also necessary to stop WSL with wsl --shutdown and reopen your WSL terminal after doing the above or networking will still not work properly.
You're welcome.
Thanks for providing correct solution @dori4n ! I appreciate it
Its working great @dori4n - God bless you!
net stop hns was enough for me. When I attempted to start it back up, it said that it was already started, so I guess it got restarted automatically. And I didn't even need to restart WSL. Or touch hvsics. Kudos, @dori4n!