Skip to content

Instantly share code, notes, and snippets.

@friddle
Last active May 6, 2022 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save friddle/2833759d7ce6f187d1c57ef2dd08ba38 to your computer and use it in GitHub Desktop.
Save friddle/2833759d7ce6f187d1c57ef2dd08ba38 to your computer and use it in GitHub Desktop.
绑定WSLip和端口
echo "wsl port shell start"
wsl_ip=$(wsl.exe bash -c "ip addr show eth0 | grep \"inet\b\""|awk '{print $2}'|cut -d/ -f1)
echo "wsl ip:${wsl_ip}"
echo "port:9001"
netsh interface portproxy add v4tov4 listenport=9001 listenaddress=0.0.0.0 connectport=9001 connectaddress=${wsl_ip}
netsh advfirewall firewall add rule name="ALLOW TCP PORT 9001" dir=in action=allow protocol=TCP localport=9001
echo "port:9022"
netsh interface portproxy add v4tov4 listenport=9022 listenaddress=0.0.0.0 connectport=22 connectaddress=${wsl_ip}
netsh advfirewall firewall add rule name="ALLOW TCP PORT 9022" dir=in action=allow protocol=TCP localport=9022
echo "wsl port shell end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment