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
{{ message }}
Repository navigation
Windows Defender Firewall blocks access from WSL2 #4139
What you're doing and what's happening:
Trying to run X11 apps from my Ubuntu installation, which I just upgraded from WSL1 to WSL2. I've configured the X server (VcXsrv) to accept TCP connections, and I've put the IP address of the Windows host into the DISPLAY variable, but the connection times out. Digging into it, I've discovered that the vEthernet adapter is treated as an "Unidentified Network", and so it gets the Public firewall access rules (which, unsurprisingly, includes blocking port 6000). If I disable the firewall entirely, I can connect to the X server just fine. This worked under WSL1, of course.
What's wrong / what should be happening instead:
Connections from a WSL2 VM should be treated as privileged and not subject to firewall rules, probably?
Strace of the failing command, if applicable:
$ strace xev
execve("/usr/bin/xev", ["xev"], 0x7ffeee6e64a0 /* 21 vars */) = 0
brk(NULL) = 0x55feb7684000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
[cut for brevity]
close(3) = 0
socket(AF_INET, SOCK_STREAM|SOCK_CLOEXEC, IPPROTO_TCP) = 3
setsockopt(3, SOL_TCP, TCP_NODELAY, [1], 4) = 0
setsockopt(3, SOL_SOCKET, SO_KEEPALIVE, [1], 4) = 0
connect(3, {sa_family=AF_INET, sin_port=htons(6000), sin_addr=inet_addr("172.17.252.209")}, 16 [hangs here...]
Reacted by Tommy Yang, joaquimds, Ng Cheuk-fung, Jeff Shantz, Yuyi Wang, KalanyuZ, Jason, Ilya Kazakevich, joe-mills, Nico Gallinal and 79 more
I have the same issue. It would also be nice if it were possible to change the network profile of the vEthernet adapter that WSL2 creates to Private. This way, we could at least disable the firewall for private networks. I tried doing this in PowerShell, but PS claims the adapter doesn't exist (I'm using the correct alias):
PS C:\Users\Jeff> Set-NetConnectionProfile -InterfaceAlias "vEthernet (WSL)" -NetworkCategory Private
Set-NetConnectionProfile : No MSFT_NetConnectionProfile objects found with property 'InterfaceAlias' equal to
'vEthernet (WSL)'. Verify the value of the property and retry.
At line:1 char:1
+ Set-NetConnectionProfile -InterfaceAlias "vEthernet (WSL)" -NetworkCa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (vEthernet (WSL):String) [Set-NetConnectionProfile], CimJobException
+ FullyQualifiedErrorId : CmdletizationQuery_NotFound_InterfaceAlias,Set-NetConnectionProfile
Reacted by Jon Stelly, jovton, Brad Rust, juanuribe-j2, Changsheng Wu, Todd Aspeotis, Andrew, Dmitry Romanov, Sergei Silnov, Victor Wads and 23 more
I want to connect from WSL2 to X410. And this works currently:
Check Settings -> Firewall -> Advance Settings.
In the opened window, check in-site rules, you can find TCP & UDP rules of X410. You can double click each rule, switch to advance tab in the dialog, check on all three checkboxes: domain, private, universal. This changes the profile private to all.
Reacted by Björn Richter, Anner J. Bonilla, Sem, Christian Quispe H, Olivier Pons, TSlivede, Jonathan Giroux (Koltes), calad0i, Michaël Mondou, Aleksander Kowalski and 3 more
Reacted by KalanyuZ, jovton, kayodeDosunmu, ACHEER, UrielMiranda, Jeffery William Martin and Param Siddharth
Allowing traffic for Public networks via firewall rules works as described by Faymek Feng (@faymek), But it's kind-of working on my nerves security-wise.
So I tried to make the network private using the tricks mentioned here and here, but to no avail. Even after disabling and re-enabling the device (vEthernet (WSL) / Hyper-V Virtual Ethernet Adapter) the firewall still blocks it. And rebooting the host recreates the keys in the registry. I even tried protecting the keys with access permissions, but Windows can still overwrite them on reboot.
Reacted by Kevin Pullin, Sedat Kapanoğlu, kylhuk, Aleksander Kowalski, Chris Hills and Brian Cline
jovton also having the same problem. After disabling public profile vEthernet WSL rule - it works untill reboot. Tried with admin privileges also - button "apply" is simply disabled, all you can do is either "OK" or "Cancel" - which in term disabling defender rule for current session only.
Is there any solution to this? Or maybe script I can run at startup to make it automatic?
upon reboot, I disable the firewall on the WSL2 interface with an Administrator Powershell:
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\WINDOWS\system32> Set-NetFirewallProfile -DisabledInterfaceAliases "vEthernet (WSL)"
this only works after I've launched the X client that is trying to talk to my VcXsrv
I launch my X client (xterm) with a desktop shortcut whose "Target" is set to:
#!/bin/bash
exec 1> wslrun.log 2>&1
PATH=/usr/bin:/bin
# DISPLAY to default gateway
ip_r_l_default=( $(ip r l default) )
export DISPLAY=${ip_r_l_default[2]}:0.0
cd ~
nohup "$@" &
# don't understand why I need this sleep
sleep 1
Tedious parts of this:
the Powershell script, which has to run on every reboot
the fact that the WSL2 interface dies whenever I change WiFi networks (all X clients die, poo)
Reacted by William Denniss, Kristján Valur Jónsson, Chris Mc, Junior Machado, Antoine Wils, Param Siddharth, cxzmoe, Jennifer Linnenberg, Splatack, Philipp Holler and 6 more
Reacted by Miles Buckton
Reacted by Miles Buckton
Reacted by staedter, cxzmoe, Splatack, Ania Zavodian and Miles Buckton
Just chiming in that it was very unintuitive to figure out that the network being created was marked public and that's why I couldn't actually access host services due to the firewall. I'd expect it to be marked private.
Reacted by Li Yongqiang, Changsheng Wu, JaeHeung Han, Dan Sanduleac, Mike Lynch, André Gomes, Leander Seefeld, kerbe, Code Hugger (Matthew Jones), c01o and 45 more
I have the same issue. It would also be nice if it were possible to change the network profile of the vEthernet adapter that WSL2 creates to Private. This way, we could at least disable the firewall for private networks. I tried doing this in PowerShell, but PS claims the adapter doesn't exist (I'm using the correct alias):
PS C:\Users\Jeff> Set-NetConnectionProfile -InterfaceAlias "vEthernet (WSL)" -NetworkCategory Private
Set-NetConnectionProfile : No MSFT_NetConnectionProfile objects found with property 'InterfaceAlias' equal to
'vEthernet (WSL)'. Verify the value of the property and retry.
At line:1 char:1
+ Set-NetConnectionProfile -InterfaceAlias "vEthernet (WSL)" -NetworkCa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (vEthernet (WSL):String) [Set-NetConnectionProfile], CimJobException
+ FullyQualifiedErrorId : CmdletizationQuery_NotFound_InterfaceAlias,Set-NetConnectionProfile
This would just be a workaround and is not good.
All you need to do is add an inbound firewall rule using the program name
Just a note, the settings from the above comment work for me, but I had trouble finding them: control panel > system and security > windows defender firewall > advanced settings > inbound rules > edit the vcxvsrv rule for public networks.
Also, since the hostname is in the DNS forwarder, you can do
export DISPLAY=$(host $HOST| head -n1 | cut -d'' -f4):0
Confirmed adding the firewall rule and limiting the source IP scope range works. Functional and secure!
I tried this method but it didn't work. After some searching I find that there are two block rule of "VcXsrv windows xserver" in my firewall rule list and these rules take precedence. Windows OS will add rules to your firewall when you first start VcXsrv windows xserver, and you should disable these rules manually(not remove it, or Windows OS will try to add it again when you open VcXsrv next time).
Since I just got bumped on email about this issue, I'd like to point everyone to the fact that vSwitch can now be used to directly connect WSL2 distro, officially, no hacks, using "networkingMode=bridged". You do need W11 Pro, which shouldn't be an issue. I've compiled a nice big tutorial couple of days ago as a comment in main networking thread: #4150 (comment)
I went through W10 to W11 upgrade (linked instructions for those with "unsupported" hardware), WSL2 Preview, creation of vSwitch, configuration of a bridge, and as a bonus systemd configuration on Ubuntu with complete systemd based networking setup. It should be doable for both newbies and experienced users. Btw, I can now tear up and setup new WSL2 instance with proper networking and full apt upgrades and all in less than 10 minutes, easy-peasy.
Reacted by Ryan Spletzer, Ignacio J. Perez Portal, Rémi Debette, Andrew Nosenko, kongkong and Etienne Boucher
For those of you that cannot for whatever reason install Windows 11, its now possible to run WSLg (https://github.com/microsoft/wslg) in WSL2 on Windows 10 builds that have a UBR>= 2311. So, if you are reading this issue because you are trying to run Linux GUIs in Windows using an X-11 server like VcxSrv installed in Windows, then one alternative is to use WSLg instead.
This is solved all the problems I was personally having as I now do not have to disable the Defender firewall for the WSL2 connection in order to get the GUI processes in WSL2 to be able to connect to the X-11 port running in Windows. That in turn allows me to connect to my corporate VPN (which otherwise blocked dues to security policies related to firewall settings).
After that - I rebooted and ensured my DISPLAY env variable setting was set to :0, and WAYLAND_DISPLAY was set to wayland-0 (the required values for WSLg) and WSLg started serving my Linux GUIs!!
My understanding is that this will allow only traffic from the local subnet. I'm not sure if it's strictly needed though. Can anyone confirm one way or the other?
therealkenc This has had the status "investigation required" for 2.5 years. How is... the investigation going? Any chance this is fixable? Is WSL2 fundamentally incompatible with Windows networking? There are dozens of cross-referencing issues, this is a real problem for so many people.
I believe that indicating the network as Private could resolve the issue, at least partially, if that's a possibility at all. The VM switch adapter connection profile is not exposed through WMI, so changing its profile the "normal" way, with Set-NetConnectionProfile, is impossible. Other Internal VM switches are visible, only not the WSL's one.
> Get-NetConnectionProfile -InterfaceAlias 'vEthernet (WSL)'
Get-NetConnectionProfile: No MSFT_NetConnectionProfile objects found with property 'InterfaceAlias' equal to 'vEthernet (WSL)'. Verify the value of the property and retry.
> Get-NetConnectionProfile | ft InterfaceAlias,NetworkCategory,IPv4Connectivity
InterfaceAlias NetworkCategory IPv4Connectivity
---------------- --------------- ----------------
Wi-Fi Private Internet
vEthernet (buba) Private LocalNetwork
The second row is a Hyper-V internal switch, visible in Control Panel/Networking, but the WSL one isn't. It's interesting that both are visible in the long output of Get-VMSwitch | fl *, also returned through WMI(!); I compared them, no differences. The network interface is not visible in Device Manager either, although the Hyper-V switch is, as "Hyper-V Virtual Ethernet Adapter #2". I don't understand what is really going on.
Reacted by Kazurin Nanako, mihkelmuur, le-petit-prince, Etienne Boucher, kaizenlpi and Marek Babinčák
So the script from #4139 (comment) does not work on my Windows 10 Laptop. The IP address it finds in the first few lines also doesn't seem to be the IP address from WSL in an "ipconfig /all".
The commands from #4139 (comment) do work, but they cause a warning in "Windows Security" (the "Restore settings" button) which the security people don't seem to like very much.
Are there any other solutions to make xdebug work from WSL2 to a Windows PhpStorm without causing Windows Security warnings.
Because Windows randomly turns on the firewall without your acknowledge, enforce a cron job to disable it might be the only compromised solution.
# run as admin in "windows powershell"$option=New-ScheduledJobOption-RunElevated -RequireNetwork
$atLogin=New-JobTrigger-AtLogOn -User *$atInterval=New-JobTrigger-Once -RepeatIndefinitely -RepetitionInterval "00:10:00"-At "0am"Register-ScheduledJob-Name "F wsl firewall"-ScheduledJobOption $option-Trigger $atLogin,$atInterval-ScriptBlock {
Set-NetFirewallProfile-Profile Public -DisabledInterfaceAliases "vEthernet (WSL)";
}
(I know basically nothing about windows powershell, so please let me know if I'm wrong.)
Also don't forget to enable inbound rules on the "Windows" host side.
Activity
jeffshantz commentedon Jun 21, 2019
I have the same issue. It would also be nice if it were possible to change the network profile of the vEthernet adapter that WSL2 creates to Private. This way, we could at least disable the firewall for private networks. I tried doing this in PowerShell, but PS claims the adapter doesn't exist (I'm using the correct alias):
faymek commentedon Jul 15, 2019
I want to connect from WSL2 to X410. And this works currently:
Check
Settings->Firewall->Advance Settings.In the opened window, check in-site rules, you can find TCP & UDP rules of X410. You can double click each rule, switch to advance tab in the dialog, check on all three checkboxes: domain, private, universal. This changes the profile
privatetoall.For xeyes demo:
jovton commentedon Oct 27, 2019
Allowing traffic for Public networks via firewall rules works as described by Faymek Feng (@faymek), But it's kind-of working on my nerves security-wise.
So I tried to make the network private using the tricks mentioned here and here, but to no avail. Even after disabling and re-enabling the device (vEthernet (WSL) / Hyper-V Virtual Ethernet Adapter) the firewall still blocks it. And rebooting the host recreates the keys in the registry. I even tried protecting the keys with access permissions, but Windows can still overwrite them on reboot.
sandric commentedon Nov 19, 2019
jovton also having the same problem. After disabling public profile vEthernet WSL rule - it works untill reboot. Tried with admin privileges also - button "apply" is simply disabled, all you can do is either "OK" or "Cancel" - which in term disabling defender rule for current session only.
Is there any solution to this? Or maybe script I can run at startup to make it automatic?
paul-reilly commentedon Dec 7, 2019
sandric (@sandric): I wrote this PS script to deal with the WSL2 IP address changing on reboot:
https://github.com/paul-reilly/WSL2-Xming-Init
It works with firewall active on my machine at least.
rob-solana commentedon Dec 17, 2019
upon reboot, I disable the firewall on the WSL2 interface with an Administrator Powershell:
this only works after I've launched the X client that is trying to talk to my VcXsrv
I launch my X client (xterm) with a desktop shortcut whose "Target" is set to:
Where wslrun.sh is:
Tedious parts of this:
jefferai commentedon Dec 25, 2019
Just chiming in that it was very unintuitive to figure out that the network being created was marked public and that's why I couldn't actually access host services due to the firewall. I'd expect it to be marked private.
a-schaefers commentedon Feb 23, 2020
This would just be a workaround and is not good.
All you need to do is add an inbound firewall rule using the program name
C:\Program Files\VcXsrv\vcxsrv.exe
fquinner commentedon Apr 1, 2020
For the record, I added some more surgical options and documented here:
https://github.com/cascadium/wsl-windows-toolbar-launcher#firewall-rules
For me though the ideal solution would be for this to work:
#4619
drewhemm commentedon Apr 22, 2020
Confirmed adding the firewall rule and limiting the source IP scope range works. Functional and secure!
wmertens commentedon Apr 23, 2020
Just a note, the settings from the above comment work for me, but I had trouble finding them: control panel > system and security > windows defender firewall > advanced settings > inbound rules > edit the vcxvsrv rule for public networks.
Also, since the hostname is in the DNS forwarder, you can do
to set the display
QingGo commentedon May 1, 2020
I tried this method but it didn't work. After some searching I find that there are two block rule of "VcXsrv windows xserver" in my firewall rule list and these rules take precedence. Windows OS will add rules to your firewall when you first start VcXsrv windows xserver, and you should disable these rules manually(not remove it, or Windows OS will try to add it again when you open VcXsrv next time).
47 remaining items
luxzg commentedon Oct 26, 2022
Since I just got bumped on email about this issue, I'd like to point everyone to the fact that vSwitch can now be used to directly connect WSL2 distro, officially, no hacks, using "networkingMode=bridged". You do need W11 Pro, which shouldn't be an issue. I've compiled a nice big tutorial couple of days ago as a comment in main networking thread:
#4150 (comment)
Likewise added it to my GitHub:
https://github.com/luxzg/WSL2-fixes
I went through W10 to W11 upgrade (linked instructions for those with "unsupported" hardware), WSL2 Preview, creation of vSwitch, configuration of a bridge, and as a bonus systemd configuration on Ubuntu with complete systemd based networking setup. It should be doable for both newbies and experienced users. Btw, I can now tear up and setup new WSL2 instance with proper networking and full apt upgrades and all in less than 10 minutes, easy-peasy.
boardbloke commentedon Dec 2, 2022
For those of you that cannot for whatever reason install Windows 11, its now possible to run WSLg (https://github.com/microsoft/wslg) in WSL2 on Windows 10 builds that have a UBR>= 2311. So, if you are reading this issue because you are trying to run Linux GUIs in Windows using an X-11 server like VcxSrv installed in Windows, then one alternative is to use WSLg instead.
This is solved all the problems I was personally having as I now do not have to disable the Defender firewall for the WSL2 connection in order to get the GUI processes in WSL2 to be able to connect to the X-11 port running in Windows. That in turn allows me to connect to my corporate VPN (which otherwise blocked dues to security policies related to firewall settings).
If you don't have the .2311 build of Windows 10, then install all the latest updates from Windows Update. You need to be updated to Version 22H2. I took the advice from here - https://superuser.com/questions/1754138/running-wsl-that-was-installed-from-the-microsoft-store-results-in-windows-vers. Note if that doesn't get you to UBR 2311, then you may need the preview update https://support.microsoft.com/en-gb/topic/november-15-2022-kb5020030-os-builds-19042-2311-19043-2311-19044-2311-and-19045-2311-preview-237a9048-f853-4e29-a3a2-62efdbea95e2.
I actually couldn't get that via Windows Update - probably because it's a preview release, but I found I could install it manually by downloading from https://www.catalog.update.microsoft.com/Search.aspx?q=KB5020030. Do this at your own risk though - it's a preview release. People seem to think it will be out of preview in a few months, so you might want to wait and use Windows Update.
After that - I rebooted and ensured my DISPLAY env variable setting was set to :0, and WAYLAND_DISPLAY was set to wayland-0 (the required values for WSLg) and WSLg started serving my Linux GUIs!!
Hope you find this helpful!
ScottShingler commentedon Apr 28, 2023
I wasn't sure if the
New-NetFirewallRulecommand mentioned above might allow external traffic in, so I added-RemoteAddress LocalSubnet:My understanding is that this will allow only traffic from the local subnet. I'm not sure if it's strictly needed though. Can anyone confirm one way or the other?
kkm000 commentedon Jun 24, 2023
therealkenc This has had the status "investigation required" for 2.5 years. How is... the investigation going? Any chance this is fixable? Is WSL2 fundamentally incompatible with Windows networking? There are dozens of cross-referencing issues, this is a real problem for so many people.
I believe that indicating the network as Private could resolve the issue, at least partially, if that's a possibility at all. The VM switch adapter connection profile is not exposed through WMI, so changing its profile the "normal" way, with
Set-NetConnectionProfile, is impossible. Other Internal VM switches are visible, only not the WSL's one.The second row is a Hyper-V internal switch, visible in Control Panel/Networking, but the WSL one isn't. It's interesting that both are visible in the long output of
Get-VMSwitch | fl *, also returned through WMI(!); I compared them, no differences. The network interface is not visible in Device Manager either, although the Hyper-V switch is, as "Hyper-V Virtual Ethernet Adapter #2". I don't understand what is really going on.kgonia commentedon Aug 8, 2023
This one help me to to debug with PyCharm using enviroment in WSL 2
#4585 (comment)
z11k commentedon Oct 15, 2023
finally something what works also for me. yes it was need of rules for firewall... i will borrow it.. thx
KeisukeeLee commentedon Dec 24, 2023
My solution:
run_in_background.vbs:disable-wsl-public-profile.bat:ryumada commentedon Dec 24, 2023
My solution is to completely reinstall my WSL by: 1
Windows Subsystem for Linux UpdateWindows Subsystem for LinuxVirtual Machine PlatformBy doing this, I assume that the WSL network interface has reconfigured.
Footnotes
NotTheDr01ds, “Answer to ‘Completely reinstall WSL,’” Super User. Accessed: Dec. 24, 2023. [Online]. Available: https://superuser.com/a/1619435 ↩
sboden commentedon Feb 4, 2024
So the script from #4139 (comment) does not work on my Windows 10 Laptop. The IP address it finds in the first few lines also doesn't seem to be the IP address from WSL in an "ipconfig /all".
The commands from #4139 (comment) do work, but they cause a warning in "Windows Security" (the "Restore settings" button) which the security people don't seem to like very much.
Are there any other solutions to make xdebug work from WSL2 to a Windows PhpStorm without causing Windows Security warnings.
danon commentedon Apr 20, 2024
What worked for me:
OneBlue commentedon May 14, 2024
Hi ! Please try the latest networking features that we've added in WSL. Those should greatly improve connectivity.
If the issue still remains, please reopen this issue.
LifeJustDLC commentedon May 18, 2024
Because Windows randomly turns on the firewall without your acknowledge, enforce a cron job to disable it might be the only compromised solution.
(I know basically nothing about windows powershell, so please let me know if I'm wrong.)
Also don't forget to enable inbound rules on the "Windows" host side.
Add comprehensive WSL2 X11/VcXsrv firewall fix scripts
Major WSL2 X11 diagnostic and firewall overhaul v2.0