Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WSL 2] NIC Bridge mode 馃枾 (Has TCP Workaround馃敤) #4150

Open
jkasten2 opened this issue Jun 16, 2019 · 591 comments
Open

[WSL 2] NIC Bridge mode 馃枾 (Has TCP Workaround馃敤) #4150

jkasten2 opened this issue Jun 16, 2019 · 591 comments
Labels

Comments

@jkasten2
Copy link

@jkasten2 jkasten2 commented Jun 16, 2019

Issue

WSL 2 seems to NAT it's virtual network, instead of making it bridged to the host NIC. My goal is for a service running in Ubuntu in WSL 2 to be accessible from anywhere on my local network.

Issue Details

  • Your Windows build number: Microsoft Windows [Version 10.0.18917.1000]

  • What you're doing and what's happening:
    Running ipconfig on my Windows 10 host machine

   IPv4 Address. . . . . . . . . . . : 192.168.1.41
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 192.168.1.1

Running ifconfig in Ubuntu WSL 2

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.18.72.60  netmask 255.255.0.0  broadcast 172.18.255.255

Accessing 172.18.72.60 from my Window host does work, however this IP is not accessible from another system on my network.

  • What's wrong / what should be happening instead:
    I would expect to ifconfig in Ubuntu WSL 2 to have an IP address in the same network as my host machine.

  • Searching the docs:
    The only detail I have found about WSL 2 networking is the following that notes that it will have it's own IP and that localhost is something that will be used for WSL 2 in the future.
    https://docs.microsoft.com/en-us/windows/wsl/wsl2-ux-changes
    This is fine, however I would like the IP WSL 2 is getting to be on my local LAN which means I need to configure the virtual NIC to be bridged.

Workaround

See @edwindijas #4150 (comment)

@briandesousa
Copy link

@briandesousa briandesousa commented Jun 18, 2019

Same issue here.

IP address of Windows machine is 192.168.1.95 and the eth0 interface in Ubuntu on WSL2 is getting 172.18.47.17.

I originally had Ubuntu on WSL1 running and then upgraded the installation to WSL2 but same problem. Then I uninstalled Ubuntu altogether and reinstalled fresh but same issue after reinstall.

Prior to using WSL2 I had an instance of Ubuntu setup as a Hyper-V VM on the same machine (Hyper-V NIC bridge already existed).

@zzz1990771
Copy link

@zzz1990771 zzz1990771 commented Jun 18, 2019

Same issue. I have a rstudio server running in docker container in WSL2 and wanted to access it from other machine but failed. Really need some fix/idea on it.

@nicolazj
Copy link

@nicolazj nicolazj commented Jun 18, 2019

I can confirm this issue.
I can no longer access the service running in subsystem from my mobile device, which is within the same wifi network with my windows laptop.

@edwindijas
Copy link

@edwindijas edwindijas commented Jun 20, 2019

It's not a bug with WSL 2, WSL 2 is running as a hyper-v virtual machine. The hyper-v adapter can be found in network adapters. You can use port forwarding to forward the port with netsh as below.
Example command below will forward tcp from port 3000 of the WSL 2 client to port 3000 of the host OS.
netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=172.18.28.x
Next allow incoming and outgoing ports on port 3000 in firewall.

@zzz1990771
Copy link

@zzz1990771 zzz1990771 commented Jun 20, 2019

It's not a bug with WSL 2, WSL 2 is running as a hyper-v virtual machine. The hyper-v adapter can be found in network adapters. You can use port forwarding to forward the port with netsh as below.
Example command below will forward tcp from port 3000 of the WSL 2 client to port 3000 of the host OS.
netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=172.18.28.x
Next allow incoming and outgoing ports on port 3000 in firewall.

Hi! Did you try it on your end? It didn't work for me when I was trying to access it from another machine in the same network. Although I did work when I use the windows host.

@edwindijas
Copy link

@edwindijas edwindijas commented Jun 20, 2019

I tried it. It worked but the craziest thing is happening, the ip address is changing on reboot. Don't forget to add inbound and outbound rules. Microsoft will fix this issue in the future

@edwindijas
Copy link

@edwindijas edwindijas commented Jun 20, 2019

WSL 2 TPC NETWORK FORWARDING

Introduction

With the introduction of WSL 2 Beta, Microsoft has made changes to the system architecture.
The changes include changing from the default bridged network adapter to a hyper-v virtual network adapter.
The implementation was not completed during the launch of the beta program. This makes accessing of network resources under WSL 2 complex.
The work around is to forward the TCP ports of WSL 2 services to the host OS.
The virtual adapter on WSL 2 machine changes it's ip address during reboot which makes it tough to implement a run once solution.
Also a side note, windows firewall will block the redirected port.

The work around is to use a script that does :

  1. Get Ip Address of WSL 2 machine
  2. Remove previous port forwarding rules
  3. Add port Forwarding rules
  4. Remove previously added firewall rules
  5. Add new Firewall Rules

Configuration

The script must be run at login ,under highest privileges to work, and Powershell must be allowed to run external sources.

PowerShell Configuration

Enable power shell to run external scripts, run the command below in power shell with administrative privileges.

How To:
Go to search, search for task scheduler. In the actions menu on the right, click on create task.
Enter Name, go to triggers tab. Create a new trigger, with a begin task as you login, set delay to 10s.
Go to the actions and add the script. If you are using Laptop, go to settings and enable run on power.

Finally:
I am no expert at security nor scripting and technically new to the windows OS.

Update
The update adds the feature to remove unwanted firewall rules.
Here is the script.


$remoteport = bash.exe -c "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,10000,3000,5000);


#[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";
}


@jkasten2
Copy link
Author

@jkasten2 jkasten2 commented Jun 21, 2019

@edwindijas Awesome, that worked for me! 馃憤 馃帀 I can access my running Linux service from any system on my network via my Windows host IP!
Thanks for all the detail and Task Scheduler suggestion too.

In addition, this workaround means localhost works too.

I was trying to go down another route by forcing bridge mode of WSL virtual adapter, that didn't work. Just including it here for completeness.

PS C:\WINDOWS\system32> Set-VMSwitch WSL -NetAdapterName 'Name_of_your_phsyical_windows_NIC'
Set-VMSwitch : Failed while adding virtual Ethernet switch connections.
External Ethernet adapter 'Name_of_your_phsyical_windows_NIC' is already bound to the Microsoft Virtual Switch
protocol.
At line:1 char:1
+ Set-VMSwitch WSL -NetAdapterName 'Name_of_your_phsyical_windows_NIC'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Set-VMSwitch], VirtualizationException
    + FullyQualifiedErrorId : InvalidParameter,Microsoft.HyperV.PowerShell.Commands.SetVMSwitch

@edwindijas Linked your comment as a workaround for this issue in my original post #4150 (comment).

@jkasten2 jkasten2 changed the title [WSL 2] NIC Bridge mode [WSL 2] NIC Bridge mode 馃枾 (Has Workaround馃敤) Jun 21, 2019
@edwindijas
Copy link

@edwindijas edwindijas commented Jun 22, 2019

The script only opens ports you desired. And the ports are redirected to WSL machine.
That said, I am no security expert, if you have a better suggestion, I am open to suggestions.

@frkhit
Copy link

@frkhit frkhit commented Jun 23, 2019

my method to solve this problem: refresh ip in win10:hosts file

@gstorelli
Copy link

@gstorelli gstorelli commented Jun 24, 2019

WSL 2 TPC NETWORK FORWARDING

Introduction
....
Configuration

The script must be run at login ,under highest privileges to work, and Powershell must be allowed to run external sources.

PowerShell Configuration

Enable power shell to run external scripts, run the command below in power shell with administrative privileges.

I saved your script in a file called "wslbridge.ps1" and then in Windows Scheduler just set Powershell.exe as Action and as argument I wrote this (instead of setting the Unrestricted ExecutionPolicy):
-ExecutionPolicy Bypass c:\scripts\wslbridge.ps1

Thanks

@shayne
Copy link

@shayne shayne commented Jun 30, 2019

I wrote a Windows Service that automatically writes the WSL2 VM's IP address to the Windows hosts file. You can then just always reference "wsl.local" from your host machine and it will resolve to the WSL2 VM.

I've been using this for a week now and just open-sourced it.

https://github.com/shayne/go-wsl2-host

@shayne
Copy link

@shayne shayne commented Jul 1, 2019

I've collected a few WSL2 hacks into a repo:
https://github.com/shayne/wsl2-hacks

One thing I wanted to point out, relevant to this thread, was "Access localhost ports from Windows", a way to access ports bound to 127.0.0.1 / localhost from the Windows host.

@joaopluigi
Copy link

@joaopluigi joaopluigi commented Jul 18, 2019

Thanks @edwindijas, it is a great workaround.

For people using Debian, which does not come with ifconfig out of the box, you can try:

$remoteport = bash.exe -c "ip addr | grep -Ee 'inet.*eth0'"

Also, the hint from @gstorelli of using -ExecutionPolicy Bypass inside the arguments of your Task Scheduler script action is awesome!

Thanks, guys!

@QingGo
Copy link

@QingGo QingGo commented Jul 20, 2019

If there are multi wsl2 in your system, remember use this command on cmd to change the wsl2 which you want to bind these port as the default one, because bash.exe will run command in the default wsl2 environment:

# list the wsl on you system
wslconfig /l
# set Debian as default for example
wslconfig /setdefault Debian

@abnerfreitas
Copy link

@abnerfreitas abnerfreitas commented Jul 21, 2019

@edwindijas I was hoping to make my Google Chrome (inside my Kali Distro) recognize my Chromecast, but i couldn't find anywhere the actual ports chromecast uses to connect, however now i can access my Kali from anywhere trought SSH.

@sangemaru
Copy link

@sangemaru sangemaru commented Aug 20, 2019

You can now use localhost to connect in recent WSL2 versions

@ericblade
Copy link

@ericblade ericblade commented Aug 28, 2019

You can now use localhost to connect in recent WSL2 versions

That's really sort of a different problem -- you can use "localhost" from the host itself, but there's no obvious way to get there from a different machine on the network:

WSL2 is running on Windows host A
WSL2 on Windows host A is running server application B
You can connect to the application from host A by just doing "localhost:port"
You can't connect to the application from Windows Host C in any obvious way.

@xorinzor
Copy link

@xorinzor xorinzor commented Aug 28, 2019

You can connect to the application from host A by just doing "localhost:port"
You can't connect to the application from Windows Host C in any obvious way.

If you open the port, why would you not be able to connect to host A from host C by just doing "host-A-ip:port"?

This behaviour shouldn't be any different then it is for linux.

@ericblade
Copy link

@ericblade ericblade commented Aug 28, 2019

I don't know the technical reason for it, but it doesn't work by default, and is what brought me here.

@timesnewmen
Copy link

@timesnewmen timesnewmen commented Sep 8, 2019

You can connect to the application from host A by just doing "localhost:port"
You can't connect to the application from Windows Host C in any obvious way.

If you open the port, why would you not be able to connect to host A from host C by just doing "host-A-ip:port"?

This behaviour shouldn't be any different then it is for linux.

Although you can open Win app by localhost:port from WSL2, but they are definitely not sharing the same network like WSL1.

This is working in WSL1, but in WSL2 it's not. Still waiting form a solution.

@mindplay-dk
Copy link

@mindplay-dk mindplay-dk commented Apr 30, 2022

As far as I can tell, there have been three "fully" working workarounds posted.

[...]

I am a bit confused since people still seem to not be able to get things to work. Are there people who are having issues with the options above?

I literally don't know what any of those options mean, what they do, or why.

I'm a developer. I use WSL2 so I can run the Linux versions of things like Node.JS, PHP, etc. - so I can develop and test locally with an environment that's more similar to a production Linux environment.

My knowledge of networking is at the level of HTTP and DNS and such - below that level, networking to me is the network icon in the system tray. I don't know or understand (or frankly want to know) anything below that, because it's not useful to the kind of work I do. Except apparently to work around breaking changes between WSL1 and WSL2, which isn't really a great motivator.

I can follow instructions blindly, sure - but I won't understand what I've done or why, I won't have any recollection of how to do it the next time I need it, and so on. I don't really want to read a book or take a course to learn the gory details of networking just to be able to run WSL2.

Wanting to test on real devices is not an exotic requirement for a web developer - and I don't think I stand out in a crowd of web developers as the village idiot for not knowing all the intricacies of network. For most of us, this stuff is "plug and play".

WSL1 "just worked" in this regard, and WSL2 broke that expectation.

It would be really lovely if we could get back to a place where "mere mortals" can make better use of this.

@mindplay-dk
Copy link

@mindplay-dk mindplay-dk commented Apr 30, 2022

Maybe it's time to think about adding a simple GUI for this and other common configuration tasks?

Yes, Linux is all consoles all the time - but I'm a Windows user and thankfully don't generally have to drill into configuration files, or copy and paste endless terminal commands from StackOverflow, in order to make use of the software on my computer.

If I wanted all that mess, I would just run Linux instead, wouldn't I? 馃槃

@sarim
Copy link

@sarim sarim commented Apr 30, 2022

If I wanted all that mess, I would just run Linux instead, wouldn't I? 馃槃

You do understand L in WSL means linux right?

@tylerkahn
Copy link

@tylerkahn tylerkahn commented May 3, 2022

Note to those finding this via Google or new to WSL, you must be using the Preview version of WSL for the bridge functionality. You can get that from the Windows App store here: https://www.microsoft.com/store/productId/9P9TQF7MRM4R

@jimdinunzio
Copy link

@jimdinunzio jimdinunzio commented May 3, 2022

I got Pawel's Solution working on my surface pro with wifi (changed script to use Wi-Fi instead of Ethernet), but wifi traffic from inside WSL2 Ubuntu is extremely slow as a result like git clone or apt install, and after a reboot or windows then my wifi is connected, but has no internet at all until I remove the bridge from adapter list. FYI, I had to set the nameserver to my router in the resolv.conf file or else I cannot connect to internet WAN.
Guess I'm giving up and going to docker and native linux solution for ROS2.

@Wee-Free-Scot
Copy link

@Wee-Free-Scot Wee-Free-Scot commented May 3, 2022

I have tried most/all things in this thread and a bunch of other things from other places I found in my several-day attempt to get WSL to see the outside world. Summary: nothing works -- WSL is deeply borked.

My config is made more complex by the existence of a corporate VPN (Cisco AnyConnect Secure Mobility Client) and a WfH setup via a broadband connection. All non-LAN connections must go through that VPN.

I have Windows 10 Enterprise. I have enabled the relevant Windows features (WSL and Virtual Machine Platform). I have previously installed the Ubuntu-20.04 distro but I have unregistered all distros so that I can start over. I have set the default WSL version to 2.

PS C:\windows\system32> wsl --install -d Ubuntu-20.04
Ubuntu 20.04 LTS is already installed.
Launching Ubuntu 20.04 LTS...

I now set my username and password inside the WSL Ubuntu-20.04 instance.

Inside the WSL instance, I cannot get DNS resolution and cannot ping anything (even the host Windows machine).
The WSL instance reports that adapter eth0 has "inet 172.30.134.139/20 brd 172.30.143.255 scope global eth0"
(I used ip addr because ifconfig isn't installed and apt cannot get to the internet to install it.)
That IP and mask isn't going to do anyone any good because everything will be unreachable from there.

In a Windows powershell, I see no changes to my network adapters/settings (powershell: ipconfig /all).
Broadband IP is 192.168.1.59 mask 255.255.255.0 gateway 192.168.1.1
Cisco VPN IP starts 10.xxx.yyy.zzz mask 255.255.240.0 gateway 10.xxx.bbb.ccc
There is no adapter with "WSL" in its name (I have previously seen such an adapter in one of my other failed attempts, but I cannot seem to reproduce that any more).

I don't know enough about Linux/Hyper-V/Windows networking settings to make this work. Moreover, I don't want to know enough about manually fiddling with network settings to make this work. Even if I did have the knowledge, I'm pretty certain my corporate IT security colleagues would be very "interested" in what I had done.

So, now I have a useless WSL instance and a headache.

@mindplay-dk
Copy link

@mindplay-dk mindplay-dk commented May 5, 2022

If I wanted all that mess, I would just run Linux instead, wouldn't I? 馃槃

You do understand L in WSL means linux right?

Hilarious. Very helpful.

I'm fairly certain you know what I meant:

If I was running Linux natively, this would just work - I wouldn't have these network issues.

WSL1 was closer to a native Linux experience in that way.

WSL2 adds a whole layer of complexity - and doesn't add anything to help manage this complexity.

@bassemsab
Copy link

@bassemsab bassemsab commented May 10, 2022

As far as I can tell, there have been three "fully" working workarounds posted. I have tried all three and they do all work.

  1. Port forwarding in a PowerShell script with netsh: This solution works for TCP forwarding but not UDP.
    Netsh Solution
  2. Using the script by @pawelgnatowski to create a virtual switch and manually bridge the network connections. This solution works extremely well and your WSL2 will be seen as a separate IP on your local LAN. I had very rare issues with this method.
    Pawel's Solution
  3. Creating a virtual switch using Hyper-V and setting WSL2 to use network bridge mode in wsl.conf:
    "Native" Bridge Solution

I've been using the third option for the last month or so without much issue. I had to recreate the switch once after a Windows update.
I am a bit confused since people still seem to not be able to get things to work. Are there people who are having issues with the options above?

This is a very good recap of the useful workarounds in this thread -- thanks! Prerequisites should also be added though, and as I recall the @pawelgnatowski script specifies Windows 11, and the virtual switch solution requires both Windows 11 and the Pro version -- correct?

Also, perhaps a fourth option should be added, which requires no modifications to WSL2 -- and that is to install Docker container versions of your desired applications via Docker Desktop:

Docker Desktop uses WSL2 as a backend and Windows as the frontend. The best of both worlds in some ways, since you can use all of your favorite Linux containers, and have access to needed ports via the host's IP or hostname. Portainer and VS Code both work great, with VS Code running under Windows and connected to WSL2 via its "Remote WSL" support.

I'd also highly recommend this approach for anyone wanting to build multi-arch containers, where the applications are actually compiled natively on a docker buildx cluster -- so much faster than using buildx CPU architecture emulation.

I spent some time on this approach, seems like dev docker containers are slow, even pressing enter on my terminal takes long to break into a new line.

@zucci-z
Copy link

@zucci-z zucci-z commented May 16, 2022

If the reason why WSL can't be accessed from outside the host PC is because of no known route, why can't the networkers just add entries to both routing tables or something

@tohsaka888
Copy link

@tohsaka888 tohsaka888 commented May 17, 2022

in latest wsl store preview 0.51.2 microsoft seems to have implemented bridging but this feature is not documented for some reason to enable bridging :

  1. create an External hyper-v virtual switch which is bridged to your network
  2. run wsl --shutdown
  3. add this to your .wslconfig file

[wsl2] networkingMode=bridged vmSwitch=my-switch

just replace my-switch with the switch you have created

then start wsl it will be bridged

I just discovered it using process explorer

it works,thanks!!!

@haimat
Copy link

@haimat haimat commented May 17, 2022

So I also followed the approach using the .wslconfig file, via the hyper-v virtual switch, which seem to work well. Both the Windows host machine and the WSL guest get their IP addresses from the network DHCP server. However, I cannot ping from one of these machines to the other.

How can I access one machine from the other, do I need to specify that somehow in the virtual hyper-v adapter?

@cerebrate
Copy link

@cerebrate cerebrate commented May 17, 2022

@haimat That should just work; there aren't any settings that I know of in the VM switch that could cause that particular behavior.

Can you not ping in either direction? Is there a firewall blocking ping on one or both machines?

@haimat
Copy link

@haimat haimat commented May 17, 2022

@cerebrate I disabled both Windows and Linux firewalls, so they were not the problem. As it turned out the issue was caused by the virtual switch itself - after removing and adding it again on the Windows host I can now ping in both directions again 馃憤

@carylewis
Copy link

@carylewis carylewis commented May 17, 2022

@cerebrate
Copy link

@cerebrate cerebrate commented May 17, 2022

@haimat That's very strange, but I'm glad you got it working.

@carylewis Yep. It's an L2 bridge, so it should support just about anything a physical adapter can, protocol-wise.

@carylewis
Copy link

@carylewis carylewis commented May 17, 2022

@tbarbette
Copy link

@tbarbette tbarbette commented May 19, 2022

As far as I can tell, there have been three "fully" working workarounds posted. I have tried all three and they do all work.

  1. Port forwarding in a PowerShell script with netsh: This solution works for TCP forwarding but not UDP.
    Netsh Solution
  2. Using the script by @pawelgnatowski to create a virtual switch and manually bridge the network connections. This solution works extremely well and your WSL2 will be seen as a separate IP on your local LAN. I had very rare issues with this method.
    Pawel's Solution
  3. Creating a virtual switch using Hyper-V and setting WSL2 to use network bridge mode in wsl.conf:
    "Native" Bridge Solution

I've been using the third option for the last month or so without much issue. I had to recreate the switch once after a Windows update.

I am a bit confused since people still seem to not be able to get things to work. Are there people who are having issues with the options above?

Because none of the solutions are actually fully working.

If you use both Wired and WiFi, all solutions become a nightmare. Let's not speak about multi-pathing which is now coming to all distros as MPTCP has been merged in the upstream Kernel, or IPv6 :)

I guess the best options would be to allow one bridge per interface, so WSL sees two interfaces too and that would allow a "native" experience and enable both of those "novel" use cases, but it's not yet possible.

@ylluminate
Copy link

@ylluminate ylluminate commented May 22, 2022

@mindplay-dk your remarks are spot on. I'm coming from a near 30 year career of working with Windows/MS, Apple/macOS, and Linux/*nix (27 years alone), a degree in CS + a ton of experience in network admin. I came here because I wanted to "do it right" vs hacking around with everything so that updates don't b0rk things and I don't get caught with my pants down since I need to use WSL2+Ubuntu 22.04 for a small monitoring application at a satellite location for a scenario. This indeed should work more like WSL1 with a simple mechanism to "just work." I realize that it's NOT a simple backend solution for Microsoft given many scenarios and multiple instances of Linux distros running behind the scene, but that's what MS gets paid the big bucks for. So yeah, at this point they have a MAJOR fail for the networking scene for WSL2 and it's a very, very ugly leaky black eye...

@bnhf I thought your remark was interesting and I tested it out, but it doesn't actually do (set up) the routing for me. Everything works fine on localhost, but nope, not from any other devices on the LAN.

@bnhf
Copy link

@bnhf bnhf commented May 22, 2022

@ylluminate Which comment are you talking about? I've made several in this thread. If it's regarding using Docker Desktop with the WSL2 backend, and being able to access Docker containers -- that does work, at least for me. I just tested it again to confirm. From another computer on my network, I was able to pullup the Portainer webpage running on a Windows host using the WSL2 backend. The only thing I've ever noticed is that you need to be sure you don't have a port conflict with the Windows host, or that will take precedence over the same port in a docker container. I use the hostname of the host typically rather than IP, but it shouldn't make any difference.

If it's another comment you're referring to, I'll try to clarify that.

@ylluminate
Copy link

@ylluminate ylluminate commented May 22, 2022

@bnhf I am indeed referring to that (your most recent prior to this to which I'm replying) remark. Can you tell me the versions you have of Windows, WSL, Docker Desktop, Linux (Ubuntu?), and any other component you think may be in the pipeline?

In my case I'm running:

  • WSL2
    $ wsl --version
    WSL version: 0.58.3.0
    Kernel version: 5.10.102.1
    WSLg version: 1.0.33
    MSRDC version: 1.2.2924
    Direct3D version: 1.601.0
    Windows version: 10.0.22000.675

@bnhf
Copy link

@bnhf bnhf commented May 23, 2022

@ylluminate So there are definitely some differences between what we're running:

"wsl --version" only appears to work using the WSL Preview from the Microsoft Store on Windows 11. I have a setup like that I'm experimenting with, but the "daily driver" I'm currently using is Windows 10.

My particulars are:

Windows 10 Pro 21H2
Docker Desktop 4.8.2
WSL Kernel 5.10.16

None of the WSL graphics related stuff is implemented before the WSL Preview you're running. My Docker Desktop settings are the same.

Here are some examples where I'm connecting to my Windows host @ NUC8-PC, from another computer, and pulling up setup pages from various docker containers:

Screenshot 2022-05-22 182953

Screenshot 2022-05-22 183731

Docker Desktop includes its own distro of some sort, so it's not necessary to have Ubuntu or Debian installed at all, however I typically install Debian, and set Docker Desktop to "integrate" with that.

@bnhf
Copy link

@bnhf bnhf commented May 23, 2022

@ylluminate Also, I do have a Windows 11 system running WSL2, and again I can access Portainer from another computer on my network using the Windows system hostname and the Portainer port number.

As an experiment, I just installed Portainer on my test rig. That system is running Windows 11 Pro, with the WSL Preview -- and is setup to use a VMware Virtual Switch and Network Bridge described some posts back. The WSL2 instance is assigned its own IP on my LAN, and so I need to use that IP and the port number to pull up the setup page. The unique hostname I've assigned to that instance does not seem to be advertised, which I haven't had time to work on yet.

@ylluminate
Copy link

@ylluminate ylluminate commented May 23, 2022

@bnhf thanks so much for sharing your details. Well at this point I don't have time to futz around any further while MS figure's out its schizophrenic troubles, so I'm going to load up Proxmox in Hyper-V and just roll with a properly bridged VM handling LXCs so that I minimize virtualization back to basically what I should be getting with WSL2 + Ubuntu + Docker. Proxmox at least will be clean and I'll have clean control over the bridge and Linux container network configs.

In theory I should get roughly the same performance I'd be getting otherwise and it's not like I need the additional GPU integration for this scenario that may or may not be missing by this route.

@luxzg
Copy link

@luxzg luxzg commented May 23, 2022

@bnhf thanks so much for sharing your details. Well at this point I don't have time to futz around any further while MS figure's out its schizophrenic troubles, so I'm going to load up Proxmox in Hyper-V and just roll with a properly bridged VM handling LXCs so that I minimize virtualization back to basically what I should be getting with WSL2 + Ubuntu + Docker. Proxmox at least will be clean and I'll have clean control over the bridge and Linux container network configs.

In theory I should get roughly the same performance I'd be getting otherwise and it's not like I need the additional GPU integration for this scenario that may or may not be missing by this route.

You don't need to use Proxmox. To everyone that has Win Pro (any version since 7-11) just simply run a VM with your choice of Linux distro in it. Performance is good, no issues with updates, networking just works, and if you have tons of physical adapters - all the better. You get to choose what you use for what and when.

The "new" option of WSL 2 Preview on W11 gives SOME hope for future, but that still requires W11 and as such eliminates 80% hardware out there. Everything else is just a limited scope or hack upon hack.

Sure, dozens of people in this thread claim it works "for me" but no solution so far works for everyone. Be it because of UDP, VPN, corporate networking, port/ip collisions, Windows versions, or whatever.

@ylluminate
Copy link

@ylluminate ylluminate commented May 23, 2022

@luxzg I'm sorry, perhaps I didn't clearly state the point: the convenience of WSL2 + Docker and being able to access services conveniently off-machine (on the LAN, for example) is pretty much eliminated by the current challenge that MS is having with this situation. Proxmox manages LXCs similar to virtual machines themselves, so it gives you a light layer + linked clones and so it's very similar to Docker, doesn't chew up the drive space (beyond Proxmox and the first LXC setup), and by using Hyper-V to offer up a sane switch for ethernet + wifi, it facilitates the flexibility it seems we all would like to see from WSL2+Linux distros. I just don't see any way to accomplish this otherwise at this point...

So yeah, Hyper-V virtual switches will do the trick and shouldn't have any problems needing to be recreated on reboot or after updates, etc. and Proxmox adds the "Docker Desktop" layer of convenience + lightness, etc.

@luxzg
Copy link

@luxzg luxzg commented May 23, 2022

@ylluminate oh yeah if you need something for lots of containers then yes, sure. Otherwise for a few VMs just do them directly on Hyper-V.

I have made whole environments on my desktop when proofing systems before production, and I'd never do that with WSL (1 or 2), and I've completely gave up on WSL in current form.

Setting up new Ubuntu VM in Hyper-V takes a few minutes these days, and most of that time is downloading and writing to disk. With ISO already downloaded and SSDs it's a breeze. When you get comfortable with it you can tear down environment and be up and running in fresh one way quicker than battling WSL issues

Edit: and Pro license is like 5$ on so many sites

Edit # 2: for those that never did it themselves and think it's complicated, scroll through this:
https://www.how2shout.com/linux/how-to-install-ubuntu-22-04-linux-on-windows-with-hyper-v/

Also, once you have clean VM with Ubuntu installed, it's easy to export and then reimport as many times needed to save time & clicks needed through Ubuntu guided install:
https://docs.microsoft.com/en-us/windows-server/virtualization/hyper-v/deploy/export-and-import-virtual-machines

I simply can't recommend WSL for anything else than tinkering and sado-mazo IT studies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests