WSL2 Networking

Understanding WSL2's Unique Networking Model

WSL2, or Windows Subsystem for Linux version 2, introduces a distinct approach to networking compared to its predecessor, WSL1. This difference stems primarily from WSL2's use of a virtualized environment, which impacts how it connects and interacts with other devices on a network.

Key Points of WSL2 Networking

  • Virtual Network Interface: WSL2 operates on a lightweight virtual machine (VM) and uses a separate network interface managed by Hyper-V. This setup provides isolation and enhances security but also adds complexity.

  • NAT and Network Isolation: The WSL2 instance is behind a Network Address Translation (NAT) provided by the Hyper-V Virtual Switch. As a result, it has a different IP address range from the Windows host and isn't directly visible on the home network.

Challenges in Accessing WSL2

  • Invisibility on Home Network: Other devices on your home network can't directly discover or communicate with WSL2 due to its distinct network setup.

  • Need for Port Forwarding: To access services within WSL2 from external devices, users often need to configure port forwarding on the Windows host.

Workarounds and Solutions

  • Setting Up Port Forwarding: Users can manually set up port forwarding rules on the host machine to enable communication with services running inside WSL2.

  • Accessing via Host IP Address: Services in WSL2 can be accessed through the host machine’s IP, with the host acting as a relay.

Conclusion

While WSL2's networking model offers improved performance and better Linux kernel compatibility, it complicates certain network interactions. Users might need to consider workarounds like port forwarding or even using WSL1 for simpler networking needs.

Install GUI software for WSL2:

sudo apt update && sudo apt -y upgrade
sudo apt -y install wget
sudo wget -qO https://bonguides.com/wsl/xrdp | bash

Reboot and then you should be able to access GUI on localhost:3390 using RDP

Reference: Video

Setting Port Forwarding:

netsh interface portproxy add v4tov4 listenport=3390 listenaddress=0.0.0.0 connectport=3390 connectaddress=<WSL machine ip>

Reference: Video