Skip to content

About

a powershell script to set port forwarding to wsl2 and automatically add firewall rules

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

WSL-PortForwarding

a powershell script to set port forwarding to wsl2 and automatically add firewall rules

Usage:

In an elevated powershell window

Enable script execution

set-executionpolicy remotesigned

Adding or removing port forwarding and firewall rules requires an elevated PowerShell window. Listing distros, distro addresses, and existing rules can be used without elevation.

Interactive menu

Run the script without parameters to open the interactive menu. The menu can list installed WSL distros, show distro IPv4 addresses, add or remove forwarding rules, and show existing portproxy/firewall rules.

.\WSL-PortForwarding.ps1

Add port forwarding rule

The script discovers IPv4 addresses dynamically from the selected WSL distro. It does not require a specific interface name such as eth0.

.\WSL-PortForwarding.ps1 -DistroName "YourWslDistro" -LocalPort 8080 -WslPort 80

You can also provide the target WSL IP address explicitly.

.\WSL-PortForwarding.ps1 -DistroName "YourWslDistro" -WslIp 172.24.32.10 -LocalPort 8080 -WslPort 80

Remove port forwarding rule

.\WSL-PortForwarding.ps1 -DistroName "YourWslDistro" -LocalPort 8080 -WslPort 80 -Purge

Show existing rules

.\WSL-PortForwarding.ps1 -ShowRules

About

a powershell script to set port forwarding to wsl2 and automatically add firewall rules

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages