WSL 2 is a wonderful technology, but it is not suited for the every possible workflow right from the start. Sometimes you need to use some tweaks to fit it in your toolchain.

In case you need to access some service running inside of WSL 2 container, web server for example, from your local network, you'll need to things:

1. Create a rule in a firewall allowing you TCP or UDP packets to reach some port on your host machine.

2. Map this port to another one listening within the WSL environment. Check IP address assigned to your VM in WSL. On Ubuntu, for example:

username ~ $ ip a … 4: eth0: mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:15:5d:d0:b5:f1 brd ff:ff:ff:ff:ff:ff inet brd scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::215:5dff:fed0:b5f1/64 scope link valid_lft forever preferred_lft forever …

Now you only need to create the mapping. Start the elevated PowerShell console, and run the following command:

netsh interface portproxy add v4tov4 listenport=1337 listenaddress= ` connectport=1337 connectaddress=

And you're all set! Any risks from running open ports on your Windows host are your own 😝

WSL 2 differs from WSL 1, you don't need such manipulations when using the first version.

I actually wrote this not to keep another link in my Pocket.