0

I have a Windows 2022 Server, build 23H2 / 22631, and it runs an Ubuntu 22.04 distribution in WSL2.

If I'm on the server itself, I can access the files in this distribution using the \\wsl$\Ubuntu path in Explorer.

Is there a way to access these same files from Explorer on a different machine that has network connectivity to the server?

I can access e.g. \\server\c$ just fine from this network machine. I wish I could go to e.g. \\server\wsl$\Ubuntu and get to the server's WSL files, but nothing like this seems to exist.

I thought about installing Samba on the Ubuntu distribution. But the distribution has the same hostname as the host 2022 server, so I don't know how I'd redirect SMB traffic to WSL without somehow killing the host's SMB traffic.

If possible, I'd like to avoid hacks like copying files / synching / scp. I'm aware of these, though they are less convenient. Direct access to the files via Explorer would be ideal.

2 Answers 2

2

I haven't tried it, but here is some information that might make it possible.

WSL2 now has Mirrored mode networking which makes it work just as in WSL1, without NAT, by using the host's network adapter(s) and assuming the host's IP.

Mirrored mode is enabled by :

  • Create the file %UserProfile%\.wslconfig (if it doesn't exist)

  • Add to the file these lines:

    [wsl2]
    networkingMode=mirrored
    
  • Shutdown WSL with wsl --shutdown

  • Start the WSL distribution.

You still need to enable the inbound SAMBA ports in the Windows firewall. From the documentation, the elevated PowerShell commands for enabling all incoming ports or just one:

Run the following command in PowerShell window with admin privileges to Configure Hyper-V firewall settings to allow inbound connections: Set-NetFirewallHyperVVMSetting -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -DefaultInboundAction Allow or New-NetFirewallHyperVRule -Name MyWebServer -DisplayName "My Web Server" -Direction Inbound -VMCreatorId "{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}" -Protocol TCP -LocalPorts 80.

Some experimentation may be required, but this might be enough to make the samba server in WSL2 be accessible over the LAN.

2
  • Oh wow, this looks promising thank you.
    – neilalex
    Commented Mar 29 at 21:17
  • Haven't been able to try it yet though I'm concerned Windows won't cooperate here either -- because Samba SMB ports 137-139 and 445 are already in use for the host's SMB? It feels like what I'd need is WSL to take on its own IP address and hostname. Let me try it and report back.
    – neilalex
    Commented Apr 4 at 22:05
0

The c$ share location is enabled by default. If you have another directory you want to share, you'll have to share that location separately. There's a few ways to do that, but the easiest - using the GUI is as simple as finding the folder directory that has the Ubuntu files and: right-click, properties, sharing tab.

The difficulty you're describing may be that the "location" of those files is not intuitively located where you think they are. The containerization may be visualizing those directories.

4
  • Thank you! The c$ example was to try to clarify that network connectivity is not an issue. I'm not aware of a mirror in the host file system that I could create an SMB share from, does that exist somewhere?
    – neilalex
    Commented Mar 29 at 19:18
  • @neilalex - You would need to enable the appropriate software to support SMB from within WSL and configure it to allow external clients to connect
    – Ramhound
    Commented Mar 29 at 19:39
  • @Ramhound thank you. Would be grateful for any specific leads as to the appropriate software?
    – neilalex
    Commented Mar 29 at 19:42
  • The most likely candidate is Samba
    – Ramhound
    Commented Mar 29 at 22:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .