Skip to content

Instantly share code, notes, and snippets.

@pidb
Created August 28, 2022 03:33
Show Gist options
  • Save pidb/86802e2c65a1f43762d37310b753239c to your computer and use it in GitHub Desktop.
Save pidb/86802e2c65a1f43762d37310b753239c to your computer and use it in GitHub Desktop.
The script can help you proxy wsl2 ssh service.
# define proxy address
$addr='0.0.0.0';
$port=22222
# Get wsl2 ip addres
$wsl_ip_all = wsl.exe hostname -I
$wsl_ip = $wsl_ip_all.Split(" ")[0]
$wsl_ssh_port = 22222
# Ensure ssh service started
echo "========================= Start wsl sshd... ========================="
wsl.exe -e sudo service ssh --full-restart
echo "========================= Start portproxy... ========================="
netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$wsl_ssh_port connectaddress=$wsl_ip
echo " * port is $wsl_ssh_port"
echo " * addr is $wsl_ip"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment