Skip to content

Instantly share code, notes, and snippets.

@L1ghtmann
Last active November 28, 2025 23:10
Show Gist options
  • Select an option

  • Save L1ghtmann/d38d63eea511a5cac3c924ad72752525 to your computer and use it in GitHub Desktop.

Select an option

Save L1ghtmann/d38d63eea511a5cac3c924ad72752525 to your computer and use it in GitHub Desktop.
Access WSL2 externally
netsh interface portproxy add v4tov4 listenport=4000 listenaddress=0.0.0.0 connectport=4000 connectaddress=$(wsl.exe hostname -I)

Purpose: forwards all incoming network traffic (0.0.0.0) on port 4000 to $(wsl.exe hostname -I) at the same port

  • view
netsh interface portproxy show all
  • delete
netsh interface portproxy reset

netsh advfirewall firewall add rule name=wsl-jekyll dir=in action=allow protocol=TCP localport=4000 

Purpose: adds firewall rule ('wsl-jekyll') to allow incoming traffic to TCP port 4000

  • view (specific)
netsh advfirewall firewall show rule name="wsl-jekyll"
  • view (all)
netsh advfirewall firewall show rule name=all | findstr "Rule Name:" | findstr /V "Microsoft"
  • toggle
netsh advfirewall firewall set rule name="wsl-jekyll" new enable=<yes/no>
  • delete
netsh advfirewall firewall delete rule name='wsl-jekyll'

Note: access system via <your Windows PC's IP>:<4000>, which can be obtained with:

(netsh interface ip show address "Wi-Fi" | Select-String -Pattern "IP Address") -replace ".+:\s+",""

ref: microsoft/WSL#4150 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment