-
Notifications
You must be signed in to change notification settings - Fork 815
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
WSL2 Set static ip? #4210
Comments
There is a work around. You can port forward to host ip. |
I agree with the author of the question, please, Wsl2 must have option "static IP". Maybe cmd: |
My issue isn't just with port forwarding and docker. The biggest issue was that I am using VSCode remote development extension and remote developing in WSL and if I need to restart WSL2 to release some resources then I can't just reconnect in the usual way and any unsaved changes get lost which accidentally happened last week. |
@alekseymvt
|
Any solution? The Hyper-V Switch IP change everytime when the windows reboot, so the gateway in wsl 2 also need to change |
Looking for a solution too :) |
With the latest update, you can access remote ports(WSL2) as local on Windows Host You can have a look at this Windows Service - assign a static hostname for WSL machine |
Can anybody check?: |
Yes, it should work |
It would be nice but instead of WSL 2 ports being bound to |
It doesn't, unfortunately. To point a custom domain to WSL, I'm adding a line like |
@moigagoo check out this https://github.com/shayne/go-wsl2-host you can do it automatically with this service |
@MiklerGM Thanks, I've seen it. I'm OK with my own self-written script. |
@MiklerGM Huh, that's interesting. Tried that several times, it never worked, adn still doesn't 🤔 It works even if you remove the last line, doesn't it? Maybe, you did something else apart from editing hosts file, like installed something like dnsmasq? Also, maybe this Go service does more than just writes to hosts? |
@yanyan33333 I'm already on build 18945 but still no joy |
I confirm it doesn't work. |
One work around I've found is if you are using docker and you install the latest edge version. It has support for WSL2 and it uses some magic (not sure what it's doing) but now |
@scrossan-crown it works ,I start nginx on wsl and I can visit the website in windows brower by using |
@yanyan33333 I can do the same but can't use 127.0.0.1 in my hosts file with a domain name and access my docker container running on port 80 but I can now that I'm using docker desktop edge version |
Check custom domain:
Windows |
Thank you, I saw your answer. I answered to @yanyan33333, because he wrote about localhost. |
We also had a bug where you needed to bind your Linux applications to 0.0.0.0 instead of 127.0.0.1 to access it, which we've fixed. This is being tracked in issue #4353 |
On build 18963 I can access http://localhost fine but in my Windows host file I have defined domains: |
Set 127.0.0.1 domain in Windows hosts file does not work all the time,even only do nothing. |
Still no official feature. All workaround makes thing more complicated by adding extra stuff to already buggy Wsl's DNS, and host Windows's VPN. |
我已收到您的邮件!谢谢
|
@travelr Powershell has get-vmswitch/set-vmswitch/new-vmswitch but they are not installed probably until you enable the Hyper-V Windows feature, which is not available for Windows Home.
|
I have found something interesting in the latest version of WSL2. The WSL instance IP and host IP relative to WSL instance will not change even you restart your computer, if you leave these registry keys unmodified. If you want to change WSL IP, just edit these registry keys, then restart your computer, and new WSL IP setting will be applied when you open WSL. My OS is Windows 11 Enterprise (Build 22621.1702), and WSL version is 1.2.5.0. |
我已收到您的邮件!谢谢
|
Thanks. It works on my Win10 too. Build 10.0.19045. |
About 200 comments on a much-wanted feature and no comments from Microsoft? The WSL release page doesn't even have any comment on this https://github.com/microsoft/WSL/releases Edit: I can also confirm that this works with WSL 1.2.5 (Windows 11 Pro) |
Very good question! So, for what you paying to the Microsoft? For ignorating from billion company? |
@timesnewmen: not working on my PC 10.0.19045 Build 19045. |
Here is what I do to set the IP address. Save the below script as [boot]
|
Are you on WSL 1.2.5 (wsl -v) ? AzureZeng said it's working with the latest WSL release, which is 1.2.5 currently. |
@aki-k
|
Hi folks, we have put out a new update that aims to address networking issues in WSL. In your More info on this release and the changes can be found here in the blog post. Please note: You need to be on a Windows Insiders version to use the new networking settings (Any channel of Windows Insiders will do, including release preview). If you see the "These are not supported" messages it means that your current Windows version doesn't have support, and you will need to upgrade. These features will eventually be coming to Windows 11 22H2. |
This comment was marked as off-topic.
This comment was marked as off-topic.
@craigloewen-msft, thanks for the update, waiting for 22H2 |
Mirrored mode does seem quite interesting. However I couldn't find any hints, if Windows firewall policies are applied and how they are applied when using mirrored mode. In many enterprise organizations firewall must be applied at host level. Copying rules to linux packet filter wouldn't be sufficient in such environment. Filtering at host level is required to provide observability to network traffic. That said, some documentation would be appreciated. |
uwu |
我已收到您的邮件!谢谢
|
Hi there. Please see https://devblogs.microsoft.com/commandline/windows-subsystem-for-linux-september-2023-update/#:~:text=Hyper-V%20Firewall%20allows%20you%20to%20specify%20firewall%20settings,will%20be%20automatically%20applied%20to%20your%20WSL%20distros. for more information about the new features coming like Mirrored Networking, DNS Tunneling, and Hyper-V Firewall |
These new networking features are now available on the latest version of Win11 22H2! Please make sure you're on the latest build to get these features, you can do that by clicking "Check for Updates" in Windows settings. You can check you have the right build by either ensuring you have KB5031354 installed, or run |
Don't get me wrong, I applaud this with all my remaining strength! (But 4.5 years in the making, I guess 99% of users moved on) I still look forward to testing the new functionality, gives me a reason to install WSL2 again, even if just for a quick spin. Thank you @craigloewen-msft and rest of the team for making this finally happen! |
Assigning Static IP Addresses in WSL2 does not work anymore. It seems the vm-switch has changed from I can't believe all the trouble i have to go through just to get caddy server and gitea in a docker container so i can program finally. This is going on for long enough for me to derail my study and go get a network certification for hyper-v. PS C:\Windows\system32> Get-VMSwitch
Name SwitchType NetAdapterInterfaceDescription
---- ---------- ------------------------------
Default Switch Internal
WSL (Hyper-V firewall) Internal
PS C:\Windows\system32> New-NetFirewallRule -Name 'WSL' -DisplayName 'WSL' -InterfaceAlias 'WSL (Hyper-V firewall)' -Direction Inbound -Action Allow
New-NetFirewallRule : The specified interface was not found on the system.
At line:1 char:1
+ New-NetFirewallRule -Name 'WSL' -DisplayName 'WSL' -InterfaceAlias 'W ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (MSFT_NetFirewallRule:root/standardcimv2/MSFT_NetFirewallRule) [New-Net
FirewallRule], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070057,New-NetFirewallRule
PS C:\Windows\system32> New-NetFirewallRule -Name 'WSL (Hyper-V firewall)' -DisplayName 'WSL (Hyper-V firewall)' -InterfaceAlias 'WSL (Hyper-V firewall)' -Direction Inbound -Action Allow
New-NetFirewallRule : The specified interface was not found on the system.
At line:1 char:1
+ New-NetFirewallRule -Name 'WSL (Hyper-V firewall)' -DisplayName 'WSL ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (MSFT_NetFirewallRule:root/standardcimv2/MSFT_NetFirewallRule) [New-Net
FirewallRule], CimException
+ FullyQualifiedErrorId : HRESULT 0x80070057,New-NetFirewallRule I will have to buy a new computer to do that because my laptop NIC does not support hyper-v correctly... PS C:\Windows\system32> Get-NetAdapter
Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
---- -------------------- ------- ------ ---------- ---------
...
Wi-Fi Killer(R) Wi-Fi 6 AX1650i 160MHz Wir... 12 Up XX-14-XX-B5-C0-25 144.4 Mbps
... The shear amount of pain and suffering I have experienced because of WSL is ridiculous. I have not even moved forwards one step because of all the technical problems. I tried cygwin. but i had issues with the software i was using after i compiled all of it and did what i thought would be the best configuration for the stuff i needed. I am starting to think that windows is not going to be adequate for the simple programming tasks i need to log and complete. |
我已收到您的邮件!谢谢
|
#4210 (comment) |
See also WSLAttachSwitch Script : #4799 (comment) Text : #4799 (comment) |
我已收到您的邮件!谢谢
|
This maybe the wrong place to post this but not sure where else to post. Is it currently possible to set a static ip for the WSL2 machine?
I'm loving WSL2 so far with docker and vscode and my only issue is dynamic ip at the moment.
The text was updated successfully, but these errors were encountered: