Created
March 15, 2021 22:09
-
-
Save evilbuck/df61b74040d5df0046bb6ac934accdf1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| @ECHO OFF | |
| SET LXDISTRO=WLinux & SET WSL2PORT=3000 & SET HOSTPORT=3000 | |
| NETSH INTERFACE PORTPROXY RESET & NETSH AdvFirewall Firewall delete rule name="%LXDISTRO% Port Forward" > NUL | |
| WSL -d %LXDISTRO% -- ip addr show eth0 ^| grep -oP '(?^<=inet\s)\d+(\.\d+){3}' > IP.TMP | |
| SET /p IP=<IP.TMP | |
| NETSH INTERFACE PORTPROXY ADD v4tov4 listenport=%HOSTPORT% listenaddress=0.0.0.0 connectport=%WSL2PORT% connectaddress=%IP% | |
| NETSH AdvFirewall Firewall add rule name="%LXDISTRO% Port Forward" dir=in action=allow protocol=TCP localport=%HOSTPORT% > NUL | |
| ECHO WSL2 Virtual Machine %IP%:%WSL2PORT%now accepting traffic on %COMPUTERNAME%:%HOSTPORT% |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is to allow accessing ports within the wsl2 container from outside the local machine, or from another docker container hosted on the same machine.