Repository navigation
Configuring WSL
Windows Subsystem for Linux (WSL) allows you to run a Linux distribution alongside your Windows operating system.
If your company uses a proxy server to access the Internet, WSL will have the same issues as some applications in Windows when trying to access the Internet.
To access the Internet from WSL, we typically configure WSL to use the same local proxy server that is already running in your Windows host.
WSL exists in two versions: WSL1 and WSL2. WSL1 is not much in use anymore, as WSL2 offers better performance and compatibility.
WSL2 uses a lightweight virtual machine to run a full Linux kernel, which means that WSL2 has its own networking stack and does not talk directly to the WinPX proxy server running on Windows.
This used to be a bit of a hassle. To use the WinPX proxy server from WSL2 (using the default network mode NAT), we had to figure out the IP addresses of the virtual network adapters of both WSL and the Windows host, add a Windows Firewall rule to allow the traffic, and then route all proxy traffic to the virtual network interface in order to reach WinPX.
If your company happened to use some broken VPN software, this got even more complicated.
Starting with Windows 11 22H2, WSL networking has been significantly improved, and things got much easier using the new networking mode Mirrored:
Thanks to some cool magic, a WSL VM can now reach both its own loopback interface and the Windows host's loopback interface simply by using the single IP adress 127.0.0.1.
TL;DR: Use the WSL networking mode Mirrored and get access to WinPX using the proxy URL http://127.0.0.1:3128.
To use Mirrored networking mode in WSL, follow these steps:
- Ensure that you have an up-to-date version of WSL installed by running the command
wsl.exe --updatein an elevated Windows Command Prompt. - Open the WSL Settings dialog from the Windows Start menu and set the networking mode to Mirrored.
To verify that the WinPX proxy server is reachable from within WSL, run the command
curl --head http://127.0.0.1:3128from a Linux shell. If WinPX is running and the command succeeds, you should see a response similar to the following:
HTTP/1.1 200 OK
Server: WinPX/1.0.34 (Windows)
Content-Type: text/html
Content-Length: 564
To configure the WSL environment to use the WinPX proxy server, you should set the http_proxy and https_proxy environment variables
by adding the following lines to your shell configuration file (e.g. .bashrc):
export http_proxy=http://127.0.0.1:3128
export https_proxy=$http_proxyIf, for some reason, you cannot use the WSL networking mode Mirrored, you can still use the NAT networking mode and configure WSL to use the WinPX proxy server:
- Open the WinPX Options dialog
- On the General Tab, configure WinPX to use the networking mode Loopback + WSL.
- Click the button Add Firewall Rule (requires administrative privileges).
- On the Status Tab, check the field WSL2 Proxy URL. It should show the WSL virtual switch address, such as
http://172.20.48.1:3128. - In WSL, set the
http_proxyandhttps_proxyenvironment variables to the WSL2 Proxy URL.