Skip to content

Commit

Permalink
feat: Implement automated script for setting up WSL2 port-forwarding …
Browse files Browse the repository at this point in the history
…ports dynamically (#19)

* feat: Scripted setup of WSL port forwarding

* fix: Add logs and license

---------

Signed-off-by: Sean O'Hair <sean.ohair@intel.com>
  • Loading branch information
seanohair22 authored Aug 21, 2023
1 parent a7659ad commit 6feb3c1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions WSL_Port_Script.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
########################################################################
# Copyright (c) Intel Corporation 2023
# SPDX-License-Identifier: BSD-3-Clause
########################################################################

## NOTE: Run with Admin Powershell Terminal!
$wsl_ip = (wsl hostname -I).split(" ")[0]
echo "Ubuntu IP: $wsl_ip"

# WSL Port Forwarding Port 22 AND 2223
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=22 connectport=22 connectaddress=$wsl_ip
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=2223 connectport=2223 connectaddress=$wsl_ip
netsh interface portproxy show all
# WSL Add firewall rules

netsh advfirewall firewall add rule name="Open SSH Tunnel port 2223 for WSL2" dir=in action=allow protocol=TCP localport=2223
netsh advfirewall firewall add rule name="Open SSH port 22 for WSL2" dir=in action=allow protocol=TCP localport=22

0 comments on commit 6feb3c1

Please sign in to comment.