-
Notifications
You must be signed in to change notification settings - Fork 823
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
Add "allow" rule to Windows firewall for WSL2 network #4585
Comments
How to repro. On Windows, listen to some port
On WSL2, try to connect to it: You would not be able to connect until you create appropriate firewall rule |
Nice! New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow |
@dansanduleac This allow ping, but how can I access some port on windows , without shutdown the firewall ? |
Thank you so much, I searched for about two hours to make WSL2 launch a graphic Emacs, and this command enabled the use of Emacs GUI, many thanks! |
try add new inbound rule for these ports? |
@eromoe @HQDragon The command I posted should allow you to access anything exposed by Windows from WSL, no matter what port, however bear in mind that any apps you've launched get an automated rule created for them when you first launch them, blocking access from public networks (this is when you get a prompt from Windows Firewall, asking whether the app should be allowed to accept connections from public networks). If you don't explicitly allow, they will be blocked by default, which also blocks connections from WSL. So you might need to find that inbound rule, and change it from block to allow (or just delete it). More info here (linked from this comment on the original issue #4139 (comment)) |
this should be in the docs |
In case this helps anyone: I was trying to setup a new laptop that I just bought and nothing here worked. That's when I realized the Windows machine I just bought had a McAfee Firewall on it (free one year subscription). So all the windows firewall stuff wasn't actually working cause it wasn't the active Firewall (McAfee was) and they have known compatibility issues with WSL/WSL2. Once I uninstalled the McAfee firewall (you could also just disable it), everything here worked except the telnet stuff. For some reason that still didn't work, but I was able to connect to my X servers no problem, which is probably why most of us were here. |
If you are trying to connect to a Mongo installs rules That is 6 hours I won't get back! I hope you are saved that time. |
this is still extremely unreliable, I've
I can't reach the
Does anyone know some reliable trick that I can use to develop web interfaces under WSL2? |
You can hit the IP address that Ubuntu is using if you're using the same machine (ifconfig from WSL2 terminal will give you this address) - is that what you mean? What I'm running into is trying to hit that IP from a wifi connected device like a phone or something. I'm definitely in over my head here, but was hoping changing the -InterfaceAlias to 'vWan' or something would do the trick, but a) I don't know where to find the correct term for that alias, and b) I don't know if that's even how it works - maybe WSL interprets incoming wifi requests through the vEthernet adapter? |
I'm still having this issue as well when trying to debug my application from within the WSL using Intellij's Pycharm |
Thank you so much for that hint! I was about to give up. Setting up the specific IP Range for the "Remote IP Adresses" has done the trick for me. -> #4139 (comment) |
Sometimes I have problems with the WSL network, but this always do the trick: |
I resolved it as this thread: #4139 (comment) |
Thank You! This solved an issue I've been facing for over a month. For some reason after updating to Windows 11, fetching repositories by VSCode (which was started from WSL) was unbearably slow. This solved it! |
Does anyone know how to do this for an outbound rule? I´ve tried just changing the direction to no success |
@marriagav Very naively, I tried this: And it worked for me! This is the only thing that has worked in fact, among tons of others that I've tried 😄 |
I tried all of the above as well as this thread: [https://github.com//issues/4139] to no avail. Windows 21H2 Just trying to use GTK-3 on VSCode with a WSL2 Ubuntu terminal. Using VcXsrv running in background.
I installed xfce4 but that doesnt work too. Upon running this:
Restarted everything several times. |
For my instances, #Requires -RunAsAdministrator
Set-NetFirewallProfile -Profile Private -DisabledInterfaceAliases "vEthernet (WSL)"
Set-NetFirewallProfile -Profile Public -DisabledInterfaceAliases "vEthernet (WSL)" |
win 11 failed:
so after I do |
I tested this. This is work for not only WSL NIC but all Interfaces. |
Thanks, everyone. WIN11 here, Rancher Desktop with containerd. PowerShell'ing
helped find the right "-InterfaceAlias"... I ended up using
Now, when I have a containerized pgadmin and a containerized postgres listening on :5432...
... I'm (pgadmin is) able to connect to host.docker.internal:5432 👌 |
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.) |
For me command "New-NetFirewallRule -DisplayName "WSL" -Direction Outbound -InterfaceAlias "vEthernet (WSL (Hyper-V firewall))" -Action Allow" fails with HRESULT 0x80070057. Adding this rule manually also does not change ports blockage, seems block is inside WSL. Anyway I found other solution. Just storing it here so perhaps that solves someone's time. It is already possible to run GUI apps with WSL: |
I just install WSL Ubuntu in W11 and nothing works to do anywhere, it also happened to me the same thing testing on other virtualization platforms such as Virtualbox, Docker and Hyper-V. The easiest thing was to completely destabilize the Windows Firewall, but it did not work, additionally I have already tried a lot of tutorials related to adding Firewal Gui/Powershell rules and still totally blocked. Very bad that it is so complicated to enable such basic functionality, formerly even in Virtualbox it was very easy to use the internet from the guest system!. |
I did the following, which worked for me (Windows 10 & WSL2):
|
These are the commands I needed to get the internet working again. Not sure which of these were necessary; posting this here for my own future reference. I'll update it if I learn more later. New-NetFirewallRule -DisplayName "WSL" -Direction Outbound -InterfaceAlias "vEthernet (WSL (Hyper-V firewall))" -Action Allow
New-NetFirewallRule -DisplayName "WSL" -Direction Outbound -InterfaceAlias "vSwitch (Default Switch)" -Action Allow
wsl --shutdown Then I restarted WSL by opening a new session in Windows Terminal. I used the command below to find the two InterfaceAliases (thanks @schmik): Get-NetAdapter -IncludeHidden | Format-Table -AutoSize |
UPDATE: I realized that there is another factor that was important in my case. For an unrelated reason, I needed to run the following commands in PowerShell:
Doing this while WSL2 is running causes it to lose internet access even though DNS continues to function. I am able to get the internet access to work again by restarting WSL. (Specifically, I mean running I am not sure if the firewall commands I mentioned in my last comment were important or not, because I also restarted WSL. It's possible that they were just a red herring (in my case). |
I was trying to connect to Windows machine from Linux and found that it is blocked by default.
WSL virtual NIC connection belongs to "Public" profile and almost all connections are forbidden.
As workaround, I added following rule explicitly:
Workaround works. But it would be great to have this rule enabled by default.
The text was updated successfully, but these errors were encountered: