PeterSmith.Org

Accessing a server running under WSL2

    I wanted to tidy away a server and mover to using docker containers under WSL. That's a story for another day.

    But when I have a server running in my docker container, that I can happily access via https://localhost:9443, how do I access it from the local LAN. I.e., use https://example.com:9443

    There is a lot written on this and the [[https://github.com/microsoft/WSL/issues/10494][problems associated with it].

    What to do.

    There are scripts that never quite worked for me.

    One of the problems is that WSL2 gets a new IP address with each reboot. Arrgh!.

    My simple solution was to proxy traffic that comes to the target port to the localhost (and thence automagically to WSL2), like this.

    Using powershell in Administration mode I did this proxy:

      netsh interface portproxy add v4tov4 listenport=9443 listenaddress=0.0.0.0 connectport=9443 connectaddress=127.0.0.1

    Great. On my machine running WSL (example.com), I can now access the server as https://example.com:9443.

    All I need to do is to expose that port now, so that systems on local LAN can get through Windows Firewall. Back in powershell I run wf and set a rule to allow access to port 9443 on this machine (example.com).

    Yay! It all works.


    Webmentions
    If you webmention this page, please let me know the URL of your page.

    BTW: Your webmention won't show up until I next "build" my site.

    Word count: 200 (about 1 minutes)

    Published:

    Updated: 20 Nov '23 19:56

    Author: Peter Smith

    Permalink: https://petersmith.org/blog/2023/11/20/accessing-server-on-wsl2/

    Section: blog

    Kind: page

    Bundle type: leaf

    Source: blog/2023/11/20/accessing-server-on-wsl2/index.org