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
Add "allow" rule to Windows firewall for WSL2 network #4585
Workaround works. But it would be great to have this rule enabled by default.
Reacted by QQ, Daniel Reis, Frederic Seiler, Kinmarui, Christopher Peisert, Sébastien Pujadas, Galen Warren, Summer YOU, Warot, Tomek Porozynski and 43 more
Reacted by haomingz, Bevan Christians, Martin Wong, teodoryantcheff, Luo Chen, Warot, Frank Pei, XIONG Ziwei, Changsheng Wu, Asaduzzaman Pavel and 236 more
Reacted by Catherine, Jokeoo, Mustapha AJEGHRIR, yuri, meseaw, Sherry Lyu and IvanGluschenko
Reacted by Rene Sauve, Matt Hughes, nmoreaud, Max Kobozev, Victor Wibisono, Kishan Reddy, Jonas Kello, Sayon Bhattacharjee, Limc, Clay Reinhardt and 15 more
Reacted by Leo, eZio Pan, Simon Stender Boisen, beautifulnature, Tim Leach, Rene Sauve, Nipuna Weerasekara, Chris Mc, nmoreaud, Elvir Moraes and 44 more
Reacted by Nipuna Weerasekara, Matt Hughes, nmoreaud, Max Kobozev, Kishan Reddy, Stefano Frazzetto, Mihai Iorga, Sayon Bhattacharjee, Clay Reinhardt, Catherine and 14 more
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))
Reacted by Vincent Wang, Raj Vengalil, Serkan, Jerry Tian, Jonas Kello, Greg Zeng, Zhang Mingquan, bzkdjc, Danilo Arcidiacono, Roberto Prevato and 4 more
Reacted by Christian Nau, kyleflan, tortal42, Xu Siyuan, Karlkim Suwanmongkol, Vincent Wang, Hammad Javed and Greg Zeng
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.
Reacted by Rod Rivera, lakensei, Jitesh Dhakshinamoorthy, Natsuki-Ikeda, Markus Schaber and Robert Navado
Mongo installs rules MongoDB Database Server on windows that disallow public connections to mongodb. To be able to access from WSL these need to be disabled.
That is 6 hours I won't get back! I hope you are saved that time.
this is still extremely unreliable,
sometimes works, sometimes it does not, other times only works until you shut down the computer 😢
I've
restored all Firewall rules
added the WSL rule as WSL by interface as New-NetFirewallRule -DisplayName "WSL by interface" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow
tested without restarting
tested after restarting
also tried having all Firewalls disabled (Domain, Private and Public) - and restart after change
I can't reach the localhost:8989 from the Windows side and as Ubuntu-20.04 under WSL2 does not have any browser, it's hard to develop in these conditions 😔
machine info:
Edition Windows 10 Pro
Version 20H2
Installed on 25-06-2020
OS build 19042.928
Experience Windows Feature Experience Pack 120.2212.551.0
image below has Ubuntu on the left side and PowerShell on the right side of Windows Terminal 1.7.1033.0, both showing the output of curl http://localhost:8989
Does anyone know some reliable trick that I can use to develop web interfaces under WSL2?
Reacted by Dmitrij Rebrov, Christian Elowsky, cppimprov, Ken Schnall, ICHx, chengxuzheng, Timor Gruber, ManuelSuarezMolina, cdsw, Conor Lawton and 2 more
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 run this command on a small Hello World code: gcc pkg-config --cflags gtk+-3.0 -o gui hello.c pkg-config --libs gtk+-3.0
and it gives a 'gui' object. I run: ./gui
and it says:
Unable to init server: Could not connect: Connection refused
(gui:32): Gtk-WARNING **: 10:51:06.383: cannot open display:
I installed xfce4 but that doesnt work too. Upon running this: xfce4-session
I get this:
Unable to init server: Could not connect: Connection refused
xfce4-session: Cannot open display: .
Type 'xfce4-session --help' for usage.
For my instances, New-NetFirewallRule doesn't work and I don't know why. I use Set-NetFirewallProfile to directly disable firewall on WSL2 interface instead to add a rule and allow it.
#Requires -RunAsAdministratorSet-NetFirewallProfile-Profile Private -DisabledInterfaceAliases "vEthernet (WSL)"Set-NetFirewallProfile-Profile Public -DisabledInterfaceAliases "vEthernet (WSL)"
Reacted by NaOHCC, Timor Gruber, jajansen, woodong, 莫居尘, Steffen, Phani Anne, Adam Pritchard, Anton Belonovich, Mathias Kallmert and 25 more
Reacted by < Marcelo Caetano /> and ayoub anbara
Reacted by jospenn
Reacted by Anton Belonovich, Gary, FloraKarniavoura-TomTom and jospenn
Reacted by Anton Belonovich, Martin, maxwaddoups, FloraKarniavoura-TomTom and jospenn
Reacted by Anton Belonovich, FloraKarniavoura-TomTom and jospenn
so after I do New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL (Hyper-V firewall))" -Action Allow, I still cannot access the service on windows from wsl2.
Reacted by Thomas Bonnet, Enduriel, Scott Salisbury, Samuel Poirier, Artyom Matveev, Andrea Turso, LiAuTraver, 染青42, Taha I, Karuhut Komol and 3 more
Now, when I have a containerized pgadmin and a containerized postgres listening on :5432...
nerdctl ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5d0c3acb38ea docker.io/dpage/pgadmin4:latest "/entrypoint.sh" 14 minutes ago Up 0.0.0.0:6543->80/tcp pgadmin4-5d0c3
92147e941b71 docker.io/library/postgres:latest "docker-entrypoint.s…" 17 minutes ago Up 0.0.0.0:5432->5432/tcp localDB
... I'm (pgadmin is) able to connect to host.docker.internal:5432 👌
Reacted by Scott Salisbury, smarkandu, Tobias Schoofs, johnrayg, LiAuTraver and Daniel Sczepansky
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.
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: https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps
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!.
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.
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:
net stop hns
net start hns
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 wsl --shutdown and then opening Ubuntu in Windows Terminal.)
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).
systeminfo | findstr /B /C:"OS 名称" /C:"OS 版本"
OS 名称: Microsoft Windows 10 专业版
OS 版本: 10.0.19045 暂缺 Build 19045
I use this command New-NetFirewallRule -DisplayName "WSL by interface" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allow after run wsl and it works,but after windows reboot it not work again.
So I try add a new Inbound Rules in Windows Defender FGirewall with Advanced Security,and didnot change any options but display name is WSL my,so I got this:
It works,after I rebooted windows ,it works still.
Maybe I know why WSL by interface didnot work,maybe cause windows didnot start wsl interface when windows boot so this rules is not use for wsl interface ,But I donot know why WSL my working,they are same rules. 😕 Anyway ,seems it a why to fix this problem.
Activity
throwable-one commentedon Oct 10, 2019
How to repro.
On Windows, listen to some port
On WSL2, try to connect to it:
$ telnet $(cat /etc/resolv.conf | grep nameserver | cut -d' ' -f2) 80You would not be able to connect until you create appropriate firewall rule
therealkenc commentedon Oct 10, 2019
#4139
dansanduleac commentedon Apr 6, 2020
Nice!
Since the IP might change every time you restart your computer, why not use the inteface?
eromoe commentedon May 21, 2020
Dan Sanduleac (@dansanduleac) This allow ping, but how can I access some port on windows , without shutdown the firewall ?
Dicridon commentedon May 23, 2020
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!
CyberQin commentedon Jun 6, 2020
try add new inbound rule for these ports?
dansanduleac commentedon Jun 13, 2020
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))
chaoky commentedon Oct 21, 2020
this should be in the docs
yakaboskic commentedon Nov 5, 2020
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.
brucejo75 commentedon Feb 12, 2021
If you are trying to connect to a
mongodbfollow Dan Sanduleac (@dansanduleac) advice.Mongo installs rules
MongoDB Database Serveron windows thatdisallowpublic connections to mongodb. To be able to access from WSL these need to be disabled.That is 6 hours I won't get back! I hope you are saved that time.
balexandre commentedon Apr 22, 2021
this is still extremely unreliable,
sometimes works, sometimes it does not, other times only works until you shut down the computer 😢
I've
WSLrule asWSL by interfaceasNew-NetFirewallRule -DisplayName "WSL by interface" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action AllowI can't reach the
localhost:8989from the Windows side and as Ubuntu-20.04 under WSL2 does not have any browser, it's hard to develop in these conditions 😔curl http://localhost:8989Does anyone know some reliable trick that I can use to develop web interfaces under WSL2?
7 remaining items
MrPointer commentedon Jun 17, 2022
Miguel Arriaga (@marriagav) Very naively, I tried this:
New-NetFirewallRule -DisplayName "WSL" -Direction Outbound -InterfaceAlias "vEthernet (WSL)" -Action AllowAnd it worked for me! This is the only thing that has worked in fact, among tons of others that I've tried 😄
merajhasan88 commentedon Sep 1, 2022
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 run this command on a small Hello World code:
gcc pkg-config --cflags gtk+-3.0 -o gui hello.c pkg-config --libs gtk+-3.0and it gives a 'gui' object. I run:
./guiand it says:
I installed xfce4 but that doesnt work too. Upon running this:
xfce4-sessionI get this:
Restarted everything several times.
kenvix commentedon Jan 1, 2023
For my instances,
New-NetFirewallRuledoesn't work and I don't know why. I useSet-NetFirewallProfileto directly disable firewall on WSL2 interface instead to add a rule and allow it.rabbitLove520 commentedon Dec 20, 2023
win 11 failed:
netsh interface ipv4 show interfaces got
so after I do
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL (Hyper-V firewall))" -Action Allow, I still cannot access the service on windows from wsl2.KeisukeeLee commentedon Dec 23, 2023
I tested this. This is work for not only WSL NIC but all Interfaces.
schmik commentedon Apr 5, 2024
Thanks, everyone. WIN11 here, Rancher Desktop with containerd.
PowerShell'ing
Get-NetAdapter -IncludeHidden | Format-Table -AutoSizehelped find the right "-InterfaceAlias"...
I ended up using
New-NetFirewallRule -DisplayName "WSL" -Direction Outbound -InterfaceAlias "vEthernet (WSL (Hyper-V firewall))" -Action AllowNow, 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 👌
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.
pikouser commentedon Jun 7, 2024
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:
https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps
dante198712 commentedon Jul 21, 2024
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!.
Petros626 commentedon Sep 19, 2024
I did the following, which worked for me (Windows 10 & WSL2):
sudo nano /etc/ssh/ssh_configsudo nano /etc/ssh/sshd_configservice ssh restartssh [email protected]dwymark-celestron commentedon Sep 20, 2024
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.
Then I restarted WSL by opening a new session in Windows Terminal.
I used the command below to find the two InterfaceAliases (thanks schmik):
dwymark-celestron commentedon Sep 27, 2024
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
wsl --shutdownand then opening Ubuntu in Windows Terminal.)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).
Zon1234 commentedon Jan 19, 2025
for me, this fixed the issue
https://learn.microsoft.com/de-de/windows/security/operating-system-security/network-security/windows-firewall/hyper-v-firewall
cloudqq commentedon Jan 23, 2025
2025 Windows 11 24H2
New-NetFirewallRule -DisplayName "WSL" -Direction Inbound -InterfaceAlias "vEthernet (WSL (Hyper-V firewall))" -Action Allowwillser commentedon Jul 3, 2025
env:
I use this command
New-NetFirewallRule -DisplayName "WSL by interface" -Direction Inbound -InterfaceAlias "vEthernet (WSL)" -Action Allowafter run wsl and it works,but after windows reboot it not work again.So I try add a new Inbound Rules in
Windows Defender FGirewall with Advanced Security,and didnot change any options but display name isWSL my,so I got this:It works,after I rebooted windows ,it works still.
Maybe I know why
WSL by interfacedidnot work,maybe cause windows didnot start wsl interface when windows boot so this rules is not use for wsl interface ,But I donot know whyWSL myworking,they are same rules. 😕 Anyway ,seems it a why to fix this problem.