Skip to content

Cant access web app hosted on WSL 2 #5368

Closed

Description

@ItsCubeTime

Environment

Windows build number: 10.0.19041.264
Your Distribution version: Release:        20.04 (From Microsoft store)
Whether the issue is on WSL 2 and/or WSL 1: WSL 2, Linux version 4.19.104-microsoft-standard (oe-user@oe-host) (gcc version 8.2.0 (GCC)) #1 SMP Wed Feb 19 06:37:35 UTC 2020

Steps to reproduce

Once you're set and running with Ubuntu 20.04 with WSL 2 :

(Following https://sandstorm.io/install )

curl https://install.sandstorm.io | bash

It will give you 2 install options, 1 for a regular install and 2 if you're setting up a development server for developing sandstorm itself or apps for sandstorm, here I choose option 1

1

Then it will ask you if you are sure if you want to install

y

"What *.sandcats.io subdomain would you like?" Pick one (One thats available) ;)

awesomesubdomain

Now it will ask you for an email to assign the sancats.io to, this is for if you loose access to your current device, you can still reclaim your domain with this email, it does not require confirming it, so if you dont wanna use an actual mail adress, just type in something random.

[email protected]

After this there are no more steps for the installation (I believe), it will now give you a admin-token link that you are supposed to be able to put in your webbrowser to continue the setup process from there, this is where I've ran into the issue of not getting a response from host when attempting to access it from a Microsoft Edge or Chrome browser running on Windows. I get no response when attempting to go to awesomesubdomain.sandcats.io neither, which is supposed to give some sort of response at all times once you have sandstorm running.

So my first thought was then that this was probably a firewall issue, made some quick google search and found this (Which I then followed) : https://www.williamjbowman.com/blog/2020/04/25/running-a-public-server-from-wsl-2/ replacing his $PORT with 80, 443, 30025 and 6080 (Which are mentioned in the sandstorm.io faq page: https://docs.sandstorm.io/en/latest/administering/faq/#what-ports-does-sandstorm-need-open )

Here are the precise powershell cmds I used (running PowerShell with admin previllegues:

PS C:\WINDOWS\system32> netsh interface portproxy add v4tov4 listenport=6080 listenaddress=0.0.0.0 connectport=6080 connectaddress=127.0.0.1 protocol=tcp

PS C:\WINDOWS\system32> netsh interface portproxy add v4tov4 listenport=30025 listenaddress=0.0.0.0 connectport=30025 connectaddress=127.0.0.1 protocol=tcp

PS C:\WINDOWS\system32> netsh interface portproxy add v4tov4 listenport=443 listenaddress=0.0.0.0 connectport=443 connectaddress=127.0.0.1 protocol=tcp

PS C:\WINDOWS\system32> netsh interface portproxy add v4tov4 listenport=80 listenaddress=0.0.0.0 connectport=80 connectaddress=127.0.0.1 protocol=tcp

For my router portforwarding I enabled all the 4 ports individually going to my PCs main IP (XXX.XXX.X.65 as you can find in my pastebin below) as it told me the Hyper-V Virtual Ethernet Adapters IP "is invalid", maybe this is where my errors lays, are there any other approaches around this? This is the guide I followed (Seems to only be available in Swedish) : https://www.telia.se/privat/support/info/oppna-portar-tradlos-router-sagemcom Here I left External host empty, and set the internal and external port to the ports above (creating a rule for each port individually (making 4 rules total)), leaving the protocol to TCP, service to other and like I said earlier, the internal IP was set to my PCs "main" or regular adress "XXX.XXX.X.65" as it didnt allow me to set it to the Hyper-V adress.

For the firewall I added the following Inbound rule: https://imgur.com/a/0awS3ae (Those separators I used are a , with a regular space after (Which is correct, right?) ). I also noticed that it had already created 2 rules for sandstorm since earlier which opens up all ports for TCP and UDP for a program in the following directory "C:\users\oliver\appdata\local\packages\canonicalgrouplimited.ubuntuonwindows_79rhkp1fndgsc\localstate\rootfs\opt\sandstorm\sandstorm-267\sandstorm". If I try going here in fire explorer however I can only get as far as to "LocalState" where there is a disk image (Which Im guessing is the Ubuntu image?) C:\Users\Oliver\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState https://imgur.com/a/m9HGGoa .

Lastly, Im not using Ubunntu ufw (Firewall for Ubuntu) as this implies:

olliver@Ollivers-Hackintosh:/mnt/c/WINDOWS/system32$ sudo ufw status
[sudo] password for olliver:
Status: inactive

Expected behavior

When you enter the admin-token url in your webbrowser, you should be greeted with this page: https://imgur.com/a/AWJA2JT

Actual behavior

https://imgur.com/a/rx6n1cX

Additional information

System info taken from within Ubuntu:
https://pastebin.com/smCCiuLf

System info taken from Windows:
https://pastebin.com/766wiJUH

I've made a post for this on sandstorms own Google group as well, its appending approval so Im just going to provide a link to the group itself in case it have appeared by the time someone reads this: https://groups.google.com/forum/#!forum/sandstorm-dev . There you can find some more info (Its posted on my account "Olliver Aira").

If you need any additional information please ask :) I've never setup and portforwarded a home server before so I might just not of grasped some of the basics fully and forgotten something obvious.

Any suggestions on fixes/solutions on my end are very welcome and is why I came here :)

If you happen to know any other places I could post this in (Like any forums? ), I would love to know about them!

Activity

  1. rescenic commented on Jun 10, 2020

    @rescenic

    I got OAuth login error when trying to do what it says after:
    sudo sandstorm admin-token in Ubuntu WSL.
    Error: conection is refused.
    But I can access my localhost.
    I used this workaround too, but not successful: #4150

    $remoteport = wsl -d Ubuntu ifconfig eth0 `| grep "inet "
    $found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
    
    if( $found ){
      $remoteport = $matches[0];
    } else{
      echo "The Script Exited, the ip address of WSL 2 cannot be found";
      exit;
    }
    
    #[Ports]
    
    #All the ports you want to forward separated by coma
    $ports=@(80,443,6080,6081,30025);
    
    
    #[Static ip]
    #You can change the addr to your ip config to listen to a specific address
    $addr='0.0.0.0';
    $ports_a = $ports -join ",";
    
    
    #Remove Firewall Exception Rules
    iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";
    
    #adding Exception Rules for inbound and outbound Rules
    iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
    iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";
    
    for( $i = 0; $i -lt $ports.length; $i++ ){
      $port = $ports[$i];
      iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
      iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";
    }
    

    I believe, maybe this is Sandstorm issue:
    I can access my localhost in HTTP, HTTPS and MongoDB Port.
    error

  2. lizeidsness commented on Jun 12, 2020

    @lizeidsness

    I'm having a similar problem but with Minecraft port. I haven't been sure where the best place to report issue. This sounds similar. When I test in WSL2 using nc -l 8080 I can see traffic from host web browser. If I do the same with port 25565, something shows up with nc in WSL2 when minecraft pings. However minecraft on host doesn't get a connection. Firewall?

    This was working before I upgraded recently to build 19041 and updated to WSL2.

  3. ItsCubeTime commented on Jun 13, 2020

    @ItsCubeTime
    Author

    I'm having a similar problem but with Minecraft port. I haven't been sure where the best place to report issue. This sounds similar. When I test in WSL2 using nc -l 8080 I can see traffic from host web browser. If I do the same with port 25565, something shows up with nc in WSL2 when minecraft pings. However minecraft on host doesn't get a connection. Firewall?

    This was working before I upgraded recently to build 19041 and updated to WSL2.

    If it was working on WSL1, why would you upgrade in the first place? WSL2 was introduced to bring better compatibility/allow pretty much all Linux softwares to run properly.

    Are you hosting a Minecraft server on the WSL2? When you try connecting to it through the Minecraft client, is that on the same device (but on Windows, outside of WSL)?

    I went through trying several fixes to get my Sandstorm.io issue resolved before I realised that it was something wrong with Sandstorm.io itself and not my network configuration, so Im not sure if any of these fixes actually fixed anything for me in the first place but, WSL 2 has unlike WSL 1 its own separate IP adress and a virtual network card (which you can find if you type in systeminfo in Windows command prompt) and supposedly your Linux OS running in WSL 2 only listens on anything directed to the IP of that virtual network card "Hyper-V Virtual Ethernet Adapter".

    #4150 (comment)
    https://www.williamjbowman.com/blog/2020/04/25/running-a-public-server-from-wsl-2/
    (Essentially these 2 guides are supposed to solve the same thing)

    Now the github link suggests that your Hyper-V Virtual Ethernet Adapter IP is dynamic and changes every time it restarts (everytime WSL 2 gets terminated/you restart WSL or your pc) (Which for me doesnt seem to be the case, so Im not so sure his system of creating and removing ports dynamically like he is is really necessary).

    sandstorm-io/sandstorm#3365 Also this is another issue I created in Sandstorm.io's Github where I also got some help with this where someone suggested another solution (which once again, I have no idea whether it solved anything or not).

    Now I were planning to use Sandstorm.io mainly to host a WordPress site, but after going through all these fixes/solutions I tried installing another web app server environment using the same ports, which then ran perfectly and was reachable from outside the WSL2. But now I cant really say if that was thanks to any of these solutions I had tried, or if it would of run out of the box without the need of opening up any firewall ports explicitly for WSL 2's Hyper-V adapter IP or bridging Windows IP to WSL2's IP.

    Something else that I found out while working on this is that if you run ifconfig in the Linux environment, it will give you a different inet IP than what your Hyper-V adapter has. Tho as far as I remember I never really did any bridging to this IP. Just so you are aware

  4. lizeidsness commented on Jun 13, 2020

    @lizeidsness

    I upgraded to WSL2 because I wanted to use it with Docker, for a different purpose. I'm not hosting anything from my windows machine, it's all just for development. I have proper linux environments for everything deployed. WSL has been great for quick and dirty linux so I've been loyal.

    Something else that I found out while working on this is that if you run ifconfig in the Linux environment, it will give you a different inet IP than what your Hyper-V adapter has. Tho as far as I remember I never really did any bridging to this IP. Just so you are aware

    I noticed this too. I chose to use a direct IP when the localhost stopped working, but that is constantly changing too. The one in the Hyper-V adapter is what WSL would use to find windows. And the one in ifconfig for Windows to find WSL. I just wish either they stopped changing, or localhost worked as it should. In my case - I just need it for development.

  5. MrTomasz commented on Jun 17, 2020

    @MrTomasz

    Use this PS if you want to bind your WSL2 easily to your LAN interface in order to get real IP address for it and expose services normally. If services will still not work, then probably it would be useful to enable systemd & co. and configure firewall properly on WSL side.

    It is a bit tricky and I need to run it manually every Windows bootup, but as I understand WSL vSwitch is created on Windows bootup, so it is not persistent like other vSwitches defined by user.

    "LAN" interface (physical NIC) will have vms_pp enabled, even previous WSL switch does not exist anymore, so it needs to be disabled first and reconfigured back to pure TCP/IP stack in order to use it again for creating this new WSL vSwitch.

    wsl --shutdown
    netsh winsock reset
    Disable-NetAdapterBinding -name "LAN" -ComponentID vms_pp
    Enable-NetAdapterBinding -name "LAN" -ComponentID ms_tcpip
    Set-VMSwitch vSwitch_LAN -SwitchType Internal
    Set-VMSwitch WSL -NetAdapterName "LAN"
    Enable-NetAdapterBinding -name "vEthernet (WSL)" -ComponentID ms_tcpip
    Set-NetIPInterface -InterfaceAlias "vEthernet (WSL)" -InterfaceMetric 10
    Set-NetIPInterface -InterfaceAlias "vEthernet (WSL) 2" -InterfaceMetric 11
    

    then under WSL one more trick:

    DEV=eth0
    OLD_IP=`ip address show dev ${DEV} | grep inet | grep ${DEV} | awk '{print $2}'`
    sudo ip address del ${OLD_IP} dev ${DEV}
    sudo dhclient ${DEV}
    

    With this -- I can run well the NFS+TFTP+SSH servers on WSL2, can connect with Cisco VPN client, etc. Depending on your settings -- you may need also to update resolv.conf with your real DNS servers.

    And yes -- it does create secondary WSL vSwitch, unfortunately.

    I hope MS will let us configure persistent vSwitch(es) for WSL (sometimes more than 1 vNIC would be useful).

  6. therealkenc commented on Jun 17, 2020

    @therealkenc

    Sandstorm runs out of the box on WSL2.

    image

    It requires no port forwarding tricks in #4150. It requires no configuration file changes in to sandstorm, beyond what the install script walks you through. It does require listening on WSL's IP address and it does require a domain (you can't just pick awesomedomain and expect that to work).

    One way to get a domain up is with avahi-daemon(8).

    You'll usually get better eyeballs on a product in that product's discussion forums.

  7. rescenic commented on Jun 17, 2020

    @rescenic

    Tomasz S (@MrTomasz) Thank you very much. I'll try your scripts.
    therealkenc Thank you very much. I'll try avahi-daemon.

  8. therealkenc commented on Jun 17, 2020

    @therealkenc

    I did realize after the fact ya'll might be trying to host things on a public IP (a minecraft server is actually a good example), and that's a different kettle of fish. #4150 is the hangout for that scenario, although setting up a tunnel is probably a better solution than what is being suggested over there. For now WSL2 is not a particularly good tool for hosting public web services. The avahi-daemon will get you a domain, and the pretty screencap above. But it is only useful for local scenarios. Sandstorm doesn't look particularly local by its nature (noting that an hour ago I had never heard of the thing).

  9. ItsCubeTime commented on Jun 17, 2020

    @ItsCubeTime
    Author

    Well yeah at least I were trying to set it up to be available outside of my network as well, tho I never really got it working.

    Just out of curiosity, how would you setup a tunnel?

  10. therealkenc commented on Jun 17, 2020

    @therealkenc

    Just out of curiosity, how would you setup a tunnel?

    You'd set up a tunnel with nontrivial effort. If I ever take the time to figure out how do a static ARP reply in Windows so the local router (typically your DHCP box in a home environment) knows where the ethernet packets are supposed to go I'll post something over in #4150. I haven't made it a personal priority because I'd never host something public facing on my own box. But it's good question. And FWIW I hope a just-works network bridge solution is forthcoming as much as everyone else.

  11. ItsCubeTime commented on Jun 17, 2020

    @ItsCubeTime
    Author

    Alrighty, thanks for the info

    I believe I know what I need to get this working when I do my next attempt, so I will just close this for now.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions