-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Network down after reboot #3
Comments
Unfortunately you stumbled on the same issue I discovered too late. |
It looks as though it will be possible to script it. My adapter name, from Get-NetAdapter, is "Ethernet" This unticks the binding of Ethernet to HyperV Extensible switch
Set the switchtype to Private, twice
Once is enough if it works. But it doesn't always work first go, and doing it a second time doesn't do any harm if it did work first time Then configure the Switch
Then do Get-NetAdapter again, to get the name of the new virtual ethernet adapter, in my case it is "vEthernet (WSL)" The interfaceindex (30 in the case below) could be used instead in the next steps, but that appears to change on each boot whereas the name stays constant. Name InterfaceDescription ifIndex Status MacAddress LinkSpeed VMware Network Adapte...8 VMware Virtual Ethernet Adapter for ... 20 Up 00-50-56-C0-00-08 100 Mbps Then reset the desired parameters for the virtual Ethernet adapter The 'New' seems necessary if the desired IP address has not been allocated, but will error (doing no harm) if it is already correct
Similarly, "Set"ting it may error if it is already set but it may be required to set it and will do no harm if it is already set
Then set desired DNS addresses in case they are not set
And now Windows networking is working as well as WSL networking :) |
If you manage to make an usable script, I would gladly include it in this repository! |
It is working for me now :) I'll test it and tweak it a bit before considering it successful. But essentially it is what I have already shown you. I used Windows+R then shell:startup to create a vbs script in startup group containing just
If wanting to specify distribution could edit that to
See microsoft/WSL#8854 (comment) This starts a background WSL process on windows startup. This is my Powershell script
Obviously for wider use that will need some explanation about using the correct adapter names, or some extra coding to detect them automatically. I had to allow Powershell scripts:
I have put it in a file fix-network.ps1 in C:\posh. I configured Task Scheduler to run it on startup, with highest privileges, and with a delay of 60seconds (to ensure that WSL has already started up). Maybe that delay can be reduced - needs some experimentation. But once that script has run it all seems OK. |
|
I'm pretty new to WSL (and this is my first time using Powershell). When googling for a way to start up WSL on boot it seemed that it isn't always straightforward e.g. it can shut itself down after 30s. The vbs was a way which way said to work, easy to try out, and does work, so I haven't tried others. There may well be other better approaches (I hope), especially as vbs is deprecated now. As I have observed it, Windows usually binds to the physical ethernet adapter, but after that is bound to HyperV Extensible Switch Windows seems to find the vEthernet (WSL) virtual adapter and bind to that though often with incorrect or missing values. Those three lines are configuring Windows to use the vEthernet (WSL) adapter with my preferred static ip address 192.168.1.61. As per your recipe WSL itself is already configured to use 192.168.1.8 as its static IP address and that seems to survive a reboot without any need to do anything other than start up WSL - what needs repair is the configuration of the physical adapter to act as a virtual switch. |
Thank you for this "recipe". It works for me to enable networking to my WSL instance from a different computer on my local network - excellent!
My issue (perhaps expected? perhaps not) is that on a reboot of my windows 10 host for WSL2 windows networking is broken. It is fixable and I've worked out what seem to be the minimum steps to get it working again. But I wonder whether the problem can be avoided, or recovered from in fewer steps (or recovered automatically perhaps via a startup script)?
After a reboot of windows I can get working again if I do the following:
Is there an easier way?
Is there a way to script this so that it can all get fixed automatically e.g. when Windows does a reboot in the middle of the night after installing updates? Probably the Powershell commands can be scripted, perhaps WSL can be set to run on startup(?), but how to script the unticking in adapter properties?
NB, in case relevant, I have a static IP on my Windows PC, and I have set a static IP for WSL (as per your instructions).
I have added a line to /etc/hosts on WSL, and also on my linux server and also to windows hosts file C:\windows\system32\drivers\etc\hosts
192.168.1.8 wsl
Thanks for the very useful and working recipe!
The text was updated successfully, but these errors were encountered: