You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Reacted by Jonathan Bouchard, Zippaaa, A boo!, Fyodor Soikin, Jeff Shantz, Brad Mccormack, Joshua Carter, Radu Camerzan, Wayne Patterson, Constantine Molchanov and 299 more
I agree with the author of the question, please, Wsl2 must have option "static IP". Maybe cmd: wsl --ip <Distro> <IP address>?
Reacted by Leonid Gorshkov, Florian Sp., Andrés Javier Pavón Fernández, Favo Yang, Clément Février, S. Mohassel, Richard Lea, awp421, wenlongkang, Aleksey and 12 more
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.
It would be nice but instead of WSL 2 ports being bound to 127.0.0.1 they are bound to ::1 and that doesn't work in the browser or hosts file. So we got localhost support but not in a way we can map other domains to it.
Reacted by Constantine Molchanov, Ricardo Cordero, pixelpylon, Marcel Pokrandt, fengye, Andrea Stella, Shoaib Shakeel and bysir
It doesn't, unfortunately. To point a custom domain to WSL, I'm adding a line like 172.25.203.130 mysite.com, where 172.25.203.130 is the IP of eth0 interface of the WSL VM: ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1
Reacted by Diana Ungaro Arnos, 蔡正海, Viktor Zhurbin, e-castillo-ortiz, Steve, Sergey Nevmerzhitsky, Anthony Kuske, Jacob Page, mokanfar, RAJA PRASAD and 3 more
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 cmd.exe /c ver and ensure that your build number is 22621.2428 or higher (Including the minor build number which is after the . as this was a backport!)
Assigning Static IP Addresses in WSL2 does not work anymore. It seems the vm-switch has changed from vEthernet (WSL) to WSL (Hyper-V firewall)
and replacing that in the above script does not work either.
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
--------------------------------------------DefaultSwitch 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-NetFirewallRulePS C:\Windows\system32> New-NetFirewallRule -Name 'WSL (Hyper-V firewall)' -DisplayName 'WSL (Hyper-V firewall)' -InterfaceAlias 'WSL (Hyper-V firewall)' -Direction Inbound -Action AllowNew-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-NetFirewallRule], 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-25144.4 Mbps
...
The shear amount of pain and suffering I have experienced because of WSL is ridiculous.
I bought windows 10 pro for Hyper-V. didn't work.
I bought windows 11 pro for Hyper-V again. didn't work.
I configured WSL 1 and 2. It worked until 2.0.9.0 at which point it started to use Hyper-V networking (from what i understand)
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.
So then I tried mingw but that didnt work either for the compilation process.
and mysys-2 mingw is probably the same, I don't really know. And also did not work.
I am starting to think that windows is not going to be adequate for the simple programming tasks i need to log and complete.
Reacted by Akito, seabeam, rmie, Don Hayward and RAADE GmbH
Assigning Static IP Addresses in WSL2 does not work anymore. It seems the vm-switch has changed from vEthernet (WSL) to WSL (Hyper-V firewall) and replacing that in the above script does not work either.
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
--------------------------------------------DefaultSwitch 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-NetFirewallRulePS C:\Windows\system32> New-NetFirewallRule -Name 'WSL (Hyper-V firewall)' -DisplayName 'WSL (Hyper-V firewall)' -InterfaceAlias 'WSL (Hyper-V firewall)' -Direction Inbound -Action AllowNew-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-NetFirewallRule], 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-25144.4 Mbps
...
The shear amount of pain and suffering I have experienced because of WSL is ridiculous. I bought windows 10 pro for Hyper-V. didn't work. I bought windows 11 pro for Hyper-V again. didn't work. I configured WSL 1 and 2. It worked until 2.0.9.0 at which point it started to use Hyper-V networking (from what i understand)
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. So then I tried mingw but that didnt work either for the compilation process. and mysys-2 mingw is probably the same, I don't really know. And also did not work.
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)
WSL supports static IP already (if updated to the latest version), or you can try networkingMode=mirrored
There isn't a way to configure a specific fixed IP in .wslconfig today, but in NAT networking mode WSL already attempts to give your distro the same IP across reboots:
The NAT subnet/gateway are persisted to HKLM and the per-user assigned IP to HKCU on shutdown (WslCoreConfig.cpp L211-226).
On the next boot they're read back (L401-415) and WSL tries to re-create the NAT endpoint with the saved IP, deleting a conflicting endpoint first if one holds that address (NatNetworking.cpp L201-311).
The IP only changes if the saved subnet becomes unusable or another process claimed the address.
Activity
edwindijas commentedon Jun 22, 2019
There is a work around. You can port forward to host ip.
Check the below link.
#4150
zippaaa commentedon Jun 22, 2019
I agree with the author of the question, please, Wsl2 must have option "static IP". Maybe cmd:
wsl --ip <Distro> <IP address>?scrossan-crown commentedon Jun 24, 2019
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.
MiklerGM commentedon Jul 3, 2019
@alekseymvt
You could execute any command using
wsllike thisyanyan33333 commentedon Jul 13, 2019
Any solution?
also see MicrosoftDocs/WSL#418 (comment)
The Hyper-V Switch IP change everytime when the windows reboot, so the gateway in wsl 2 also need to change
GhostvOne commentedon Aug 1, 2019
Looking for a solution too :)
MiklerGM commentedon Aug 1, 2019
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
zippaaa commentedon Aug 1, 2019
Can anybody check?:
Will "http://mysite" work too, if I add "127.0.0.1 mysite" in "windows/hosts"? or localhost only?
MiklerGM commentedon Aug 1, 2019
Yes, it should work
scrossan-crown commentedon Aug 1, 2019
It would be nice but instead of WSL 2 ports being bound to
127.0.0.1they are bound to::1and that doesn't work in the browser or hosts file. So we got localhost support but not in a way we can map other domains to it.moigagoo commentedon Aug 1, 2019
Michael Orlov (@MiklerGM)
It doesn't, unfortunately. To point a custom domain to WSL, I'm adding a line like
172.25.203.130 mysite.com, where 172.25.203.130 is the IP of eth0 interface of the WSL VM:ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | cut -d/ -f1MiklerGM commentedon Aug 1, 2019
Constantine Molchanov (@moigagoo) check out this https://github.com/shayne/go-wsl2-host you can do it automatically with this service
moigagoo commentedon Aug 1, 2019
Michael Orlov (@MiklerGM) Thanks, I've seen it. I'm OK with my own self-written script.
MiklerGM commentedon Aug 1, 2019
btw, I have no problem accessing the custom domain, for example,
test.comfrom my browserMy hosts file on Windows host machine
196 remaining items
desarrollonenas2 commentedon Oct 12, 2023
uwu
FansinZhao commentedon Oct 12, 2023
keith-horton commentedon Oct 13, 2023
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
craigloewen-msft commentedon Oct 24, 2023
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
cmd.exe /c verand ensure that your build number is 22621.2428 or higher (Including the minor build number which is after the.as this was a backport!)luxzg commentedon Oct 25, 2023
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 Craig Loewen (@craigloewen-msft) and rest of the team for making this finally happen!
Lucyfurnice commentedon Dec 1, 2023
Assigning Static IP Addresses in WSL2 does not work anymore. It seems the vm-switch has changed from
vEthernet (WSL)toWSL (Hyper-V firewall)and replacing that in the above script does not work either.
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.
I will have to buy a new computer to do that because my laptop NIC does not support hyper-v correctly...
The shear amount of pain and suffering I have experienced because of WSL is ridiculous.
I bought windows 10 pro for Hyper-V. didn't work.
I bought windows 11 pro for Hyper-V again. didn't work.
I configured WSL 1 and 2. It worked until 2.0.9.0 at which point it started to use Hyper-V networking (from what i understand)
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.
So then I tried mingw but that didnt work either for the compilation process.
and mysys-2 mingw is probably the same, I don't really know. And also did not work.
I am starting to think that windows is not going to be adequate for the simple programming tasks i need to log and complete.
FansinZhao commentedon Dec 1, 2023
AzureZeng commentedon Dec 1, 2023
#4210 (comment)
WSL supports static IP already (if updated to the latest version), or you can try
networkingMode=mirroredmicheldiemer commentedon Apr 19, 2024
See also WSLAttachSwitch
Script : #4799 (comment)
Text : #4799 (comment)
FansinZhao commentedon Apr 19, 2024
d-jagoda commentedon May 11, 2025
route2wsl can workaround this limitation https://github.com/d-jagoda/route2wsl by altering windows routing rules.
FansinZhao commentedon May 11, 2025
benhillis commentedon May 18, 2026
There isn't a way to configure a specific fixed IP in
.wslconfigtoday, but in NAT networking mode WSL already attempts to give your distro the same IP across reboots:WslCoreConfig.cppL211-226).NatNetworking.cppL201-311).If you need WSL's IP to track the host's exactly,
networkingMode=mirroredin.wslconfigdoes that by design. Docs: https://learn.microsoft.com/windows/wsl/networking#mirrored-mode-networking.FansinZhao commentedon May 18, 2026