Advertisement
tracins

automated port forward WSL - 1

Apr 7th, 2025
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.19 KB | None | 0 0
  1. # Get the IP address of your WSL2 instance
  2. $wslIP = bash.exe -c "hostname -I"
  3.  
  4. if ($wslIP) {
  5.     Write-Host "WSL2 IP Address: $wslIP"
  6.  
  7.    # List of ports to forward (host ports from your docker-compose.yml)
  8.    $ports = @(
  9.        80,    # Traefik HTTP
  10.        443,   # Traefik HTTPS
  11.        32400, # Plex
  12.        8989,  # Sonarr
  13.        7878,  # Radarr
  14.        9696,  # Prowlarr
  15.        8096,  # Jellyfin
  16.        8920,  # Jellyfin HTTPS (if configured)
  17.        8080,  # Heimdall (HTTP - internal to WSL2)
  18.        8443,  # Heimdall (HTTPS)
  19.        5055,  # Jellyseerr
  20.        8181,  # Tautulli
  21.        5056,  # Overseerr
  22.        19999, # Netdata
  23.        3000,  # MeshCentral HTTP
  24.        3001,  # MeshCentral HTTPS
  25.        8080,  # rdtclient
  26.        9117   # Jackett
  27.    )
  28.  
  29.    foreach ($port in $ports) {
  30.        $ruleNameHTTP = "WSL2_Forward_TCP_$port"
  31.        $ruleNameUDP = "WSL2_Forward_UDP_$port"
  32.  
  33.        # Forward TCP port
  34.        netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=$port connectaddress=$wslIP connectport=$port protocol=tcp
  35.        if ($LASTEXITCODE -eq 0) {
  36.            Write-Host "Successfully forwarded TCP port $port"
  37.        } else {
  38.            Write-Warning "Failed to forward TCP port $port. Rule '$ruleNameHTTP' might already exist. Try running 'netsh interface portproxy delete v4tov4 listenport=$port protocol=tcp'"
  39.        }
  40.  
  41.        # Forward UDP port (if applicable - check your container configurations)
  42.        if ($port -eq 8324 -or $port -eq 32410 -or $port -eq 32412 -or $port -eq 32413 -or $port -eq 32414 -or $port -eq 1900 -or $port -eq 7359) {
  43.            netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=$port connectaddress=$wslIP connectport=$port protocol=udp
  44.            if ($LASTEXITCODE -eq 0) {
  45.                Write-Host "Successfully forwarded UDP port $port"
  46.            } else {
  47.                Write-Warning "Failed to forward UDP port $port. Rule '$ruleNameUDP' might already exist. Try running 'netsh interface portproxy delete v4tov4 listenport=$port protocol=udp'"
  48.            }
  49.        }
  50.    }
  51. } else {
  52.    Write-Error "Could not retrieve WSL2 IP address. Make sure WSL2 is running."
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement