TroubleChute Logo
WSL

How to Port Forward Ubuntu/WSL


Published: Jun 4, 2023
Last Edit: Jun 4, 2023
Ubuntu WSL
302 Words, 1 Minute.

Watch the video:


The issue

Hosting programs under wsl only allows access on your local computer. In order to allow access from outside your local network or computer, you need to port forward WSL from within your computer.

How to pull forward Ubuntu WSL?

The step should be the same for most Debian based operating systems under wsl. All you need to do is run this command under Windows and change out the ports when necessary.

Open Powershell or command prompt as administrator and run the following swapping out 2000 for whenever port you’d like to use.

1
netsh interface portproxy add v4tov4 listenport=2000 listenaddress=0.0.0.0 connectport=2000 connectaddress=$($(wsl hostname -I).Trim());

In order to remove this port-forward forward later on, you can use the following command to delete it once again swapped to 2000 for whatever port.

1
netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=2000

If you’d like to note ports that you currently have for ones you can run the following command in Windows Edge should tell you what is currently forwarded.

1
netsh interface portproxy show v4tov4

What is 0.0.0.0?

4x 0’s allows any network interface to access this service on your computer. Using 127.0.0.1 means that only other services running on your computer should be able to access whatever you’re trying to port forward.

This is a super simplified way of explaining it, but having it set is 4 zeros is probably what you’re looking for.

Forwarding different ports

If for some reason you’re already using port 2000 you can change the listen port in the first command, and it’ll change what your computer listens for. The connect port is the one towards WSL.

Why?

This is the great option if you’d like to run this stable diffusion or other language models, etc, under WSL. This is the great way to get around it.

TroubleChute © Wesley Pyburn (TroubleChute)
Support Me Privacy Policy Cookies Policy Terms of Service Change privacy settings Contact