Skip to content

Instantly share code, notes, and snippets.

@jarkkojs
Created December 13, 2022 15:29
Show Gist options
  • Save jarkkojs/b188f3c19d9cfe4ad1340b5bddd0102a to your computer and use it in GitHub Desktop.
Save jarkkojs/b188f3c19d9cfe4ad1340b5bddd0102a to your computer and use it in GitHub Desktop.
$wsl_netif_index = (Get-NetAdapter | Where-Object -Property Name -Match "WSL").InterfaceIndex
$wsl_ip = (Get-NetIPAddress -InterfaceIndex $wsl_netif_index -AddressFamily IPv4).IPAddress
Write-Output 'WSL IP address: ' $wsl_ip
if ((Get-NetFirewallRule | Where-Object -Property DisplayName -eq wsl_ssh).count -eq 0)
{
Write-Output 'Creating''wsl_ssh'' firewall rule'
New-NetFirewallRule -DisplayName wsl_ssh `
-Direction Inbound `
-Protocol TCP `
-LocalPort 10022 `
-Action Allow `
| Out-Null
}
Remove-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\PortProxy\v4tov4\tcp' '*/10022'
netsh interface portproxy add v4tov4 listenport=10022 connectport=22 connectaddress=$wsl_ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment