Last active
April 16, 2023 11:23
-
-
Save k-tahiro/7485d311d2d694c6ba0ad1d7bede336d to your computer and use it in GitHub Desktop.
WSL + systemd
This file contains 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
Param( | |
[String]$distro = "Ubuntu" | |
) | |
Write-Host "Start WSL $distro ..." | |
wsl -d $distro -u root -e bash -c 'apt list daemonize || (apt update && apt install daemonize -y) && daemonize $(which bash) -c \"while true; do sleep 1d; done\"' | |
Write-Host "WSL $distro has been started." | |
Write-Host "Set portproxy ..." | |
$wsl_ipv4 = wsl -d $distro -e bash -c "hostname -I | cut -d' ' -f1" | |
netsh interface portproxy delete v4tov4 listenport=22 | |
netsh interface portproxy delete v6tov4 listenport=22 | |
netsh interface portproxy add v4tov4 listenport=22 connectaddress=$wsl_ipv4 | |
netsh interface portproxy add v6tov4 listenport=22 connectaddress=$wsl_ipv4 | |
Write-Host "ssh portproxy has been set to $wsl_ipv4" | |
$wsl_ipv6 = wsl -d $distro -e bash -c "ip -6 a show eth0 | grep inet6 | sed -E 's/\s+/ /g' | xargs | cut -d' ' -f2 | cut -d/ -f1" | |
netsh interface portproxy delete v4tov6 listenport=22 | |
netsh interface portproxy delete v6tov6 listenport=22 | |
netsh interface portproxy add v4tov6 listenport=22 connectaddress=$wsl_ipv6 | |
netsh interface portproxy add v6tov6 listenport=22 connectaddress=$wsl_ipv6 | |
Write-Host "ssh portproxy has been set to $wsl_ipv6" | |
Start-Sleep 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment