If you're someone who needs to use both Linux and Windows on a fairly frequent basis, the Windows Subsystem for Linux, or WSL, has probably been a lifesaver for you. It's a great feature that makes it much easier to bring these two things together, and when you pair it with something like X410, it really enhances the Linux experience on your Windows PC.
But it's not all perfect, and for all the usefulness of WSL, more advanced users have noticed some big issues, with networking being a major one. With Linux running inside Windows, managing the network connection for the host and guest can be a challenge, at least out of the box.
Networking in WSL can be a mess
Local services and VPNs cause problems
WSL is great, but when it comes to networking, things can get a bit confusing, especially because WSL has changed its behavior a bit since it first made its debut. Initially, WSL used a setup that allowed other devices on your network to access WSL applications on your computer provided they had access to the host computer itself. This made things a bit more seamless since you'd just use the IP address of the host machine to connect to your WSL apps.
With WSL2, though, the Linux instance uses a virtual network adapter that has its own IP assigned, so there are some extra steps you may need to go through with the default configuration. The networking setup also makes it harder to access network-based services in Windows through your Linux machine, so not only is the setup more complicated, it's more prone to errors. And once VPNs get involved, it can be a huge mess for Linux apps to be able to use networking at all when the VPN is controlled by Windows.
Starting with Windows 11 version 22H2, Microsoft did take some steps to address some of these issues. A new feature called DNS tunneling was added, which allowed DNS requests to be processed by a virtualization layer rather than through a network packet, which greatly improved support for connectivity when using VPNs.
It may be easy to fix
Mirroring mode to the rescue
In the default behavior, WSL uses a NAT-based architecture which can contribute to many of the issues you experience when using networking features in WSL. If you want to improve your networking experience, your best bet is to use the mirrored networking mode. This option was also added in Windows 11 version 22H2, but it's not enabled by default, and it tries to mirror the network interfaces of your Windows host, enabling support for more features and improving compatibility with other tools.
This includes the ability to use IPv6, connect to services running on the Windows host using the localhost address (127.0.0.1), better compatibility for VPNs, and the ability to connect to your WSL services directly from other machines in your local network, similar to how it worked with WSL1. That's a pretty big list of benefits, and even Microsoft recommends trying this out in your WSL setup. So how do you do it?
Well, it's fairly easy. If you're running WSL2, you can find an app called WSL Settings in your Start menu, and this changes global settings for all your WSL distros. Launch it and then head into the Networking tab on the left side of the app.
Networking mode is the first option on the page, so simply change it to Mirrored and close the app.
In order for your settings to take effect, you may need to restart WSL. You can do this by opening a terminal and entering the command wsl --shutdown to turn off the WSL2 virtual machine. Launch your distro again to boot it back up. Alternatively, rebooting your PC should also work.
If you don't want to use the GUI, you can manually create and modify the WSL configuration file. You'll need to create a file called .wslconfig in your user folder (C:\Users\
[wsl2]
networkingMode=mirrored
In addition to this, you may want to run the following PowerShell command to configure the Hyper-V firewall so that it allows inbound connections on your WSL machine:
Set-NetFirewallHyperVVMSetting -Name '{40E0AC32-46A5-438A-A0B2-2B479E8F2E90}' -DefaultInboundAction Allow
Once that's done, your network tools should work a lot better through WSL.
This should be the default
Why even use the less functional method?
What's interesting about the mirrored networking mode in WSL is that even though it's been available for around three years, Microsoft still doesn't use this method as the default for new WSL configurations. The company's documents don't point to any obvious limitations with this setup, and there are numerous advantages. The company does ask users to send feedback on any issues they encounter, but considering it's been three years and no specific issues are mentioned in the documentation, you would think it's reliable enough to be the default behavior. Especially when the company explicitly states that it's recommended to try the mirrored networking mode.
Either way, using Linux inside of Windows is something most will only do for very specific purposes, and networking is likely going to be a major part of why you want to do this in the first place. Some self-hosted services may need to run on Linux or work better on the platform, and having these networking problems makes the experience far more frustrating than it needs to be. The steps above should help with that, but ideally, Microsoft will just change the default behavior in the near future to make things better for everyone.
