Intro
https://learn.microsoft.com/en-us/windows/wsl/networking
Mirrored mode networking
https://learn.microsoft.com/en-us/windows/wsl/networking#mirrored-mode-networking
- Set networkingMode=mirrored under [wsl2] in the .wslconfig file to enable mirrored mode networking
Configure Windows Firewall for WSL
-
Configure Hyper-V firewall to disable firewall
- Get WSL VM id
Get-NetFirewallHyperVVMCreatorVMCreatorId : {40E0AC32-46A5-438A-A0B2-2B479E8F2E90} FriendlyName : WSL- Disable firewall
Set-NetFirewallHyperVVMSetting -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -Enabled False -
List existing firewall rules
Get-NetFirewallRule -DisplayName *WSL*- Allow all traffic
New-NetFirewallRule -DisplayName "Allow All WSL Traffic" -Direction Inbound -Action Allow -Protocol AnyName : {5a95604b-9e6b-456b-b649-70d64afb4793}
DisplayName : Allow All WSL Traffic
Description :
DisplayGroup :
Group :
Enabled : True
Profile : Any
Platform : {}
Direction : Inbound
Action : Allow
EdgeTraversalPolicy : Block
LooseSourceMapping : False
LocalOnlyMapping : False
Owner :
PrimaryStatus : OK
Status : The rule was parsed successfully from the store. (65536)
EnforcementStatus : NotApplicable
PolicyStoreSource : PersistentStore
PolicyStoreSourceType : Local
RemoteDynamicKeywordAddresses : {}
PolicyAppId :
- To remove the rule
Remove-NetFirewallRule -DisplayName "Allow All WSL Traffic"- A safer alternative is to Only allow connection to wsl in a Trusted (Private) network
- Remove with
Remove-NetFirewallHyperVRule -Name 'WSL Rule
- Remove with
New-NetFirewallHyperVRule `
-DisplayName 'Allow All Inbound Traffic to WSL in Private Network' `
-Name 'WSL Rule' `
-Profiles Private `
-Direction Inbound `
-Action Allow `
-VMCreatorId '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' `
-Enabled True


