-
Notifications
You must be signed in to change notification settings - Fork 579
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
Static IP on WSL 2 #418
Comments
You'll need to create an init script for ssh to auto start when you launch WSL (doesn't matter WSL1 or WSL2). Pengwin will automatically do this for you if you ask it from pengwin-setup. As far as IP address goes, you can make the IP address static just like on Linux. Here's a quick look from a recent article: https://danielmiessler.com/study/manually-set-ip-linux/ |
@mscraigloewen It may be a good idea to create a new doc going over common configurations such as creating the init script for ssh and others that are common. Anyone could go to the Pengwin repo to get the ssh script, I linked to a few others in the FedoraRemix repo (such as memcached and nginx) but I'm sure it would ease a lot of developers time and effort to just have an authoritative doc that goes over standard practices and procedures. Init scripts are just a part of it. Linking to the dev-box-setup repo would also be a good idea for that doc. |
@WSLUser yes that's a good idea! I'll look into making some of those docs. |
It`s not working, the Hyper-V Switch IP change everytime when the windows reboot, so the gateway in wsl 2 also need to change |
@mscraigloewen Is it no way to make the IP in Hyper-V Switch on windows and linux on WSL 2 not to change every reboot right now ? |
There's a technical issue with WSL2 in that regard. I saw there was an issue about it on https://github.com/Microsoft/WSL/issues/ but I don't recall the issue number unfortunately. From what I remember, you'll need something like a script right now that automatically runs when you launch a WSL2 instance. |
As of right now I'm not aware of a way to make the IP of the Hyper-V switch static. We are working on improving our networking story so you can connect to Linux apps using 'localhost' instead of a remote IP address which should address your issue! |
There's a workaround posted, but I haven't tried it. |
@mscraigloewen it doesn't work when you need to access Windows resources from Linux, say, you want to run a Linux app to access the SQL Server running on Windows host. |
I think the 9P server would probably be able to work for it. Granted perf will likely not be great but assuming 9P works as intended in WSL2, it should provide you an workaround option. Also keep in mind AF_Unix. Though I think the interop story was broken, so that use-case may not be entirely workable even with 9P. |
@WSLUser Not sure what you mean by 9P server. If you're refering to the MSSQL Server for Linux, yes it works but I also hope to be able to use the Management Studio to easily explore my data... |
No, 9P is a network share feature for allowing Windows to access Linux files that’s built into |
@peidaqi what do you mean by it doesn't work? If you follow the instructions here (make sure to read the 'Other networking considerations section as well as that might be where the error comes from!) does it still not work? If it still doesn't work please consider opening an issue on our WSL Github repo: https://github.com/microsoft/wsl |
@mscraigloewen thx |
@mscraigloewen Is there any solution to start wsl when windows booting? |
@yanyan33333 there's a program called 'Task Scheduler' on Windows that can start programs on log on. You can set this up to run |
I give you a new idea: Instead of changing the IP, add a designated IP. In Windows 10, run CMD or Powershell with administrator privilege, and then execute the following two commands: :: Add an IP address in Ubuntu, 192.168.50.16, named eth0:1 :: Add an IP address in Win10, 192.168.50.88 In the future, you will use 192.168.50.16 when you access Ubuntu, and 192.168.50.88 when you access Win10. |
protang -- Ths works "temporarily". Sometimes, it persists after a reboot. Sometimes after 3-4 days the IP vanishes. |
Hyper-V bridged mode
|
Still impossible to set a static IP? |
Hey @craigloewen-msft do you have any news on that? I recently tried to assign a static IP to my wsl instance and I noticed the IP get randomized at each wsl reboot, this is mainly because the wsl vSwitch is deleted when wsl is not running. It would be really, really great if the wsl vSwitch could be permanently configured, along with the NAT settings associated with the Windows host and the hyper-v wsl instance. Thanks in advance. |
We don't yet have any concrete news here. I can tell you that we are working on improving WSL's networking story and are taking in static IP as a consideration, but we don't yet have anything to share in this area. Thanks for being patient! |
|
Hello Is there any update regarding this? It's awful have to look for the IP every time you need to access the WSL. |
@craigloewen-msft Its been years since users are asking for this feature. Why does it take so long to implement? I'm like many others out there want to have static IP (and also static MAC address) in WSL2... Why can't we just have an access to those virtual Hyper-V network adapters used by WSL2 guests (i've tried to find them without success) and be able to configure them the way we want it (assign ip, assign mac etc)? |
@Falseclock If I copy a Ubuntu 18.04, modify one of the static IP will lead to another Ubuntu18.04 IP will also change, I want to make these two have static IP, what is a good way |
hello, I use WSL 2 in windows 10 insider
and I found that the ip address on WSL 2 change everytime when I restart windows
can I use the static ip on WSL 2?
also how can I start ssh service on boot?
thx~
The text was updated successfully, but these errors were encountered: