-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
How to enable Port Forwarding for TCP? | ||
|
||
[CzBiX/WSLHostPatcher](https://github.com/CzBiX/WSLHostPatcher) | ||
Run the wsl-port-forwarding.ps1 in Powershell Administrator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# From: https://stackoverflow.com/a/71546540 | ||
|
||
$ports=@(12345) # the ports you want to open | ||
$addr='0.0.0.0'; | ||
|
||
$wslIP = bash.exe -c "hostname -I" | ||
$found = $wslIP -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'; | ||
|
||
if(! $wslIP -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}') { | ||
echo "WSL's IP cannot be found. Aborting"; | ||
exit; | ||
} | ||
|
||
$portsStr = $ports -join ","; | ||
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' "; | ||
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $portsStr -Action Allow -Protocol TCP"; | ||
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $portsStr -Action Allow -Protocol TCP"; | ||
|
||
for ($i = 0; $i -lt $ports.length; $i++) { | ||
$port = $ports[$i]; | ||
iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr"; | ||
iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$wslIP"; | ||
} |