This script can be used to handle the forwarding of ports between your Windows host and your WSL2 machine.
This is usefully because WSL2 distros cannot have a fixed IP address so binding port after each reboot of them is necessary.
- Python3 installed on Windows host.
- net-tools installed on WSL (
sudo apt install net-tools
).
- Launch a terminal (bash or cmd) as Administrator.
- Clone the script on your Windows machine.
- Get the name of the WSL distribution (
wsl.exe -l
). - In python script, fill the
PORTS_TO_FORWARD
variable with all ports you want to forward. - Run the script:
python3 wsl-auto-forwarding.py "Name of you WSL machine"
.